Ble-Security Essentials
Ble-Security Essentials
slawomir.jasek@smartlockpicking.com
@slawekja
Bluetooth Smart?
Our hardware – flashing, embedded development
BLE advertisements, connections, services, characteristics
Sniffing BLE
BLE „Man in the Middle”, relay, replay
BtleJacking
General idea
myvessyl.com
www.vitalherd.com
Startups
1. Come out with a bright idea where to
put a chip in.
4. Crowdfunding!
5. Profit! http://southpark.cc.com/full-episodes/s18e01-go-fund-yourself
http://www.bluetooth.com/Pages/Medical.aspx
https://www.youtube.com/watch?v=1xrdwhisW-M
https://www.youtube.com/watch?v=RxM55DNS9CE
Fuze card: emulates magnetic stripe credit cards
https://fuzecard.com/
BLE DEVKIT
Why I want you to become embedded developer?
BLE400 + nRF51822
USB BLE adapters
ST-Link V2
USB UART
Connector wires
Why nRF51822?
http://www.waveshare.com/wiki/NRF51822_Eval_Kit
• BLE400 motherboard
https://os.mbed.com/platforms/Nordic-nRF51822/
Add board
Now back in the compiler
New->New Program, choose template
Hello world = blinky
Blinky source
Blinky main.cpp – blink LED1 few times a second
Compile
nrf/smartlockpicking/smartlockpicking_uvision5_nrf51822.zip
You can import this zip into mbed.com (it will compile without
error). You can also use offline mbed CLI or other IDE (e.g. Keil).
Flashing nRF51822 module
Non-original starting at $5
Works with open-source software
openocd (www.openocd.org)
Connect ST-Link to BLE400
SWDIO – SWIO
SWCLK – SWD
GND – GND
3.3V unconnected, we’ll
power board using USB
Connect BLE400
Openocd (already installed)
root@kali:~# openocd -f
/usr/share/openocd/scripts/interface/stlink-v2.cfg
-f /usr/share/openocd/scripts/target/nrf51.cfg
root@kali:~# ./openocd.sh
Ready to use script openocd.sh in your VM
Successfully connected
Troubleshooting: bad connection
> reset
> halt
advertisement
Android: iOS:
nRF Connect for nRF Connect for
Mobile Mobile
https://play.google.com/store/ap https://itunes.apple.com/us/app/l
ps/details?id=no.nordicsemi.andr ocate-beacon/id738709014
oid.mcp
LightBlue
https://itunes.apple.com/us/app/l
ightblue-bluetooth-low-
energy/id557428110
Your device advertisement in nRF Connect
0x08 –
shortened
local name
Advertisement data
Devices broadcast data formatted according to „Generic Access Profile” specification, for
example („header” values):
https://www.bluetooth.org/en-us/specification/assigned-numbers/generic-access-profile
Linux – interacting with BLE
Power:
• Class II – 2.5 mW, 10m range – most common
• Class I – 100 mW, 100 m range – more expensive, actually not necessary
Update: Kali 2018.3 VM problem
https://www.kali.org/releases/kali-linux-2018-3-release/
Solution:
- use Kali 2018.2 with previous kernel 4.15
- downgrade kernel to 4.15 manually
Downgrade kernel to 4.15 manually
Turn off
Connect „Cambridge Silicon Radio” to VM
root@kali:~# hciconfig
hci0: Type: BR/EDR Bus: USB
BD Address: 54:4A:16:5D:6F:41 ACL MTU: 310:10 SCO MTU: 64:8
UP RUNNING
RX bytes:568 acl:0 sco:0 events:29 errors:0
TX bytes:357 acl:0 sco:0 commands:30 errors:1
https://github.com/evilsocket/bleah/
https://www.evilsocket.net/2017/09/23/This-is-not-a-post-about-BLE-introducing-BLEAH/
# bleah
Your device advertisement in bleah
root@kali:~# bleah
Introducing GATTacker – gattack.io
Open source
Node.js
Websockets
Modular design
Json
.io website
advertisement
Advertisement
JSON scan.js
ws-slave.js
Running the ws-slave (client)
root@kali:~# cd node_modules/gattacker
GATTacker ws-slave
Step 2 – scan (connecting to ws-slave)
advertisement
Advertisement
JSON scan.js
ws-slave.js
Scan for advertisements
on open
poweredOn
Start scanning.
Troubleshooting
root@kali:~/node_modules/gattacker# node
scan
Ws-slave address: 127.0.0.1
on open Your BLE adapter is off
# hciconfig hci0 up
poweredOff
scan.js
# node scan.js
connects to ws-slave
listens to all advertisements,
saves them automatically to JSON files (devices/ subdir).
GATTacker: scan for devices
Device MAC
The advertisement file
Node_modules/gattacker/devices/<MAC>_<name>.adv.json
"id": "d0c92e6350b3",
"eir": "0201041308736d6172746c6f636b7069636b696e673031", Raw hex data (according to
"scanResponse": null, BLE spec), used later
"decodedNonEditable": {
"localName": "smartlockpicking01",
"manufacturerDataHex": null,
"manufacturerDataAscii": null, Decoded just for display
"serviceUuids": []
}
Sex toys...
https://www.pentestpartners.com/security-blog/screwdriving-
locating-and-exploiting-smart-adult-toys/ https://internetofdon.gs/
„Screwdriving”
BLE
central peripheral
Services, characteristics, ... SERVICE, eg. 0x180F - battery
Characteristic
Descriptor: string
(e.g. “Battery level”)
Service – groups several characteristics
Descriptor:
subscription status
Properties – read/write/notify...
Characteristic
(...)
services
SERVICE
(...)
Device characteristics (in service) SERVICE, eg. 0x180F - battery
Characteristic
Characteristic
(...)
SERVICE
(...)
Reading, writing, notifications
Read value
write
Linux: device advertisement
MAC address
gatttool – blueZ command-line interface
The device advertises
random MAC address type
[B8:27:EB:08:88:0E][LE]>
[B8:27:EB:08:88:0E][LE]> connect
Connection successful
[B8:27:EB:08:88:0E][LE]>
Blue = connected
Troubleshooting
ascii hex
Decode HEX: e.g. in CyberChef
https://gchq.github.io/CyberChef/
Toggle the LED status
value
[D0:C9:2E:63:50:B3][LE]> char-write-req 0x25 01
[D0:C9:2E:63:50:B3][LE]> char-write-req 0x25 00
Your MAC
Bleah vs sex toy (enumerate services)
Bleah vs sex toy: vibrate
advertisement
Advertisement
JSON, services
JSON
scan.js
services?
ws-slave.js
GATTacker: running the ws-slave (client)
$ cd node_modules/gattacker
GATTacker ws-slave
GATTacker: scan for devices
Device MAC
Scan specific device characteristics Target device
MAC
BLE
Passive sniffing?
central peripheral
Bluetooth 4 security (specification)
Pairing
Key Generation
Encryption
Encryption in Bluetooth LE uses AES-CCM cryptography. Like BR/EDR, the LE Controller
will perform the encryption function. This function generates 128-bit encryptedData
from a 128-bit key and 128-bit plaintextData using the AES-128-bit block cypher as
defined in FIPS-1971.
Signed Data
https://developer.bluetooth.org/TechnologyOverview/Pages/LE-Security.aspx
Bluetooth 4 security (specification)
http://www.connectblue.com/press/articles/shaping-the-wireless-future-with-low-energy-applications-and-systems/
BLE channel hopping
http://lacklustre.net/bluetooth/bluetooth_with_low_energy_comes_low_securit
y-mikeryan-usenix_woot_2013-slides.pdf
Catching initial packet to follow
External antenna.
http://greatscottgadgets.com/ubertoothone/
Nordic BLE sniffer
Take out the module from BLE400 board, it will now work as
a standalone device.
Just VCC (3V, not 5!) and GND.
Our „smartlockpicking” device can work standalone
VCC GND
BTW, you can connect external USB TTL
External USB TTL
RXD->P09
TXD->P011
Second module to
flash with sniffer
Standalone
„smartlockpicking” device,
just powered from board
Flash second module with a sniffer firmware
> halt
> nrf51 mass_erase
> reset
> halt
> flash write_image
nrf/sniffer/sniffer_pca10028_51296aa.hex
(...)
> reset
Setting up the sniffer – connect to USB
root@kali:~# dmesg
(...)
[25958.451531] usb 2-2.2: new full-speed USB device number 10 using
uhci_hcd
[25958.707592] usb 2-2.2: New USB device found, idVendor=10c4,
idProduct=ea60
[25958.707596] usb 2-2.2: New USB device strings: Mfr=1, Product=2,
SerialNumber=3
[25958.707598] usb 2-2.2: Product: CP2102 USB to UART Bridge Controller
[25958.707600] usb 2-2.2: Manufacturer: Silicon Labs
[25958.707601] usb 2-2.2: SerialNumber: 0001
[25958.713131] cp210x 2-2.2:1.0: cp210x converter detected
[25958.717133] usb 2-2.2: cp210x converter now attached to ttyUSB0
Wireshark installation #1 (already in your VM)
Help->About->Folders
root@kali:~/nrf_sniffer_2.0.0-beta-1_51296aa/extcap# ls
root@kali:~/nrf_sniffer_2.0.0-beta-1_51296aa/extcap# cp -r
* /usr/lib/x86_64-linux-gnu/wireshark/extcap/
Wireshark install #3 – turn on interface toolbar
View-> Interface
Toolbars -> nRF Sniffer
Wireshark
http://www.connectblue.com/press/articles/shaping-the-wireless-future-with-low-energy-applications-and-systems/
Limit the channels for sniffing
https://media.defcon.org/DEF%20CON%2024/DEF%20CON%2024%20presentations/DEFCON-24-Rose-Ramsey-Picking-Bluetooth-Low-Energy-Locks.pdf
Manufacturer’s statement
The electronic codes necessary to open are passed wirelessly and are
unencrypted (by design) to allow vendors flexibility when integrating the
bluetooth device into existing platforms. Because keys are passed wirelessly,
they are open to Bluetooth hacking only for a few seconds, when a hacker is
within range of the device. However, this level of security is similar to a
standard lock and key scenario! Standard mechanical devices offer far fewer
benefits than Bluetooth connected locks!
https://www.thequicklock.com/security-notice.php
ANDROID HCIDUMP
„WHITEBOX” APPROACH
How do we hack BLE?
Passive sniffing?
central peripheral
Android HCI dump – white box approach
# hcidump
Hcidump
You will see only public advertisements and data exchanged with your
host.
https://github.com/nccgroup/BLE-Replay
Parses hcidump to json, wraps into python BLE client for
replay/fuzzing
Example btsnoop_hci.log for our padlock
How do we hack BLE?
Passive sniffing Android HCI dump
Using simple hw is unreliable, Catches all the packets (of our
easy to loose packets. transmission)
Can be helpful to diagnose what Does not cover link-layer. Only data
is happening on link-layer (e.g. exchanged between Android and BT
Bluetooth encryption) adapter
a
Frida
Passive sniffing?
central peripheral
Frida hooks in mobile application
https://www.pentestpartners.com/security-blog/reverse-engineering-ble-from-android-apps-with-frida/
Frida - results
https://www.pentestpartners.com/security-blog/reverse-engineering-ble-from-android-apps-with-frida/
Possible advantage
Active
HCI dump BLE MITM
Passive sniffing?
central peripheral
How do we MITM RF?
Mallory
Alice
Bob
Isolate the signal?
Physics...
https://en.wikipedia.org/wiki/Diffraction
https://en.wikipedia.org/wiki/Huygens%E2%80%93Fresnel_principle
Stronger signal? More signals?
Advertise
Specific advertisement
received, stop scanning
Further communication
Attack?
Start scanning for
advertisements
Advertise more
frequently
Specific advertisement
received, stop scanning
MITM?
Keep connection to
original device. It
does not advertise
Connect the advertising device (MAC) while connected ;)
Further communication
MITM – what actually works
Open source
Node.js
Websockets
Modular design
Json
.io website
services services
„PROXY” –
interception,
tampering
We will team up for 2 separate boxes
Advertising „cloned”
device Advertise
root@kali:~# cd node_modules/gattacker
GATTacker ws-slave
Box 1 (emulating device) – edit config file
root@kali:~# cd node_modules/gattacker/
advertisement
WIFI
Advertisement
+ services JSON scan.js
ws-slave.js
Scan for advertisements (Kali)
on open
poweredOn
Start scanning.
GATTacker: scan for devices
Device MAC
Scan device characteristics Target device
MAC
advertisement Advertisement
+ services JSON
advertise.js
Free the BT interface
In case you have running ws-slave on the same machine, stop it (we
will need the BT interface):
(...) ws -> close
^Croot@kali:~/node_modules/gattacker#
# hciconfig
hci0: Type: Primary Bus: USB
BD Address: 00:1A:7D:DA:72:00 ACL MTU: 310:10 SCO MTU: 64:8
DOWN RUNNING
RX bytes:574 acl:0 sco:0 events:30 errors:0
TX bytes:368 acl:0 sco:0 commands:30 errors:0
# hciconfig hci0 up
# hciconfig
hci0: Type: Primary Bus: USB
BD Address: 00:1A:7D:DA:72:00 ACL MTU: 310:10 SCO MTU: 64:8
UP RUNNING
RX bytes:1148 acl:0 sco:0 events:60 errors:0
TX bytes:736 acl:0 sco:0 commands:60 errors:0
advertise
dump/<MAC>.log
Dump data format
example:
You can edit the dump file, e.g. change value „01” to „00”
2018.03.22 05:52:14.321 | < C | a000 | a001 | 00 ( )
Replay script
https://github.com/securing/gattacker/wiki/Dump-and-replay
nRF Connect:
https://play.google.com/store/apps/details?id=no.nordicsemi.android.mcp
Macros functionality
root@kali:~/node_modules/gattacker/helpers/bdaddr# make
gcc -c bdaddr.c
gcc -c oui.c
# cp bdaddr /usr/local/sbin
Change MAC
root@kali:~# bdaddr
Can't read version info for hci0: Network is down (100)
root@kali:~# hciconfig hci0 up
root@kali:~# bdaddr
Manufacturer: Cambridge Silicon Radio (10)
Device address: 00:1A:7D:DA:72:00 Your target MAC
root@kali:~# bdaddr -i hci0 00:1A:7D:DA:72:01
Manufacturer: Cambridge Silicon Radio (10)
Device address: 00:1A:7D:DA:72:00
New BD address: 00:1A:7D:DA:72:01 Now re-plug the interface
to reset it
Address changed - Reset device now
root@kali:~# hciconfig hci0 up
root@kali:~# bdaddr
Manufacturer: Cambridge Silicon Radio (10) Check the MAC address is
Device address: 00:1A:7D:DA:72:01 changed
Simple helper script to change MAC automatically
For the helper script (changing MAC automatically)
Uncomment in config.env
# "peripheral" device emulator
BLENO_HCI_DEVICE_ID=0
ID of your advertising
adapter (0 for hci0)
Start device – mac_adv (wrapper to advertise.js)
root@kali:~node_modules/gattacker# ./mac_adv -a
devices/f4b85ec06ea5_Padlock-.adv.json -s devices/f4b85ec06ea5.srv.json
Advertise with cloned MAC address
Manufacturer: Cambridge Silicon Radio (10)
Helper bash script to
Device address: B0:EC:8F:00:91:0D
change MAC addr
New BD address: F4:B8:5E:C0:6E:A5
https://github.com/DigitalSecurity/btlejuice
https://speakerdeck.com/virtualabs/btlejuice-the-bluetooth-smart-mitm-framework
https://en.wikipedia.org/wiki/Multiple_discovery
root@kali:~# btlejuice-proxy
Right-click on a row
and select „Set hook”
Btlejuice - hook
Does not require access to device Requires access to smartphone Does not require access to device
nor smartphone nor smartphone
Even if the connection is
Limited possibilities to decode encrypted, we have the packets in Will not work (out of box) against
encrypted connections (intercept cleartext (de-/encrypted by link-layer Bluetooth encryption
pairing + CrackLE). adapter)
THE SEX TOY AGAIN
BTW the sex toy intercepted in GATTacker
https://www.lovense.com/sex-toy-blog/lovense-hack
https://www.lovense.com/sex-toy-blog/lovense-hack
https://www.lovense.com/sex-toy-blog/lovense-hack
BtleJack, Defcon 26
https://media.defcon.org/DEF%20CON%2026/DEF%20CON%2026%20presentations/Damien%20Cauquil%20-%20Updated/DEFCON-26-Damien-
Cauquil-Secure-Your-BLE-Devices-Updated.pdf
Hijacking Lovense sex toy
https://media.defcon.org/DEF%20CON%2026/DEF%20CON%2026%20presentations/Damien%20Cauquil%20-%20Updated/DEFCON-26-Damien-
Cauquil-Secure-Your-BLE-Devices-Demo-Videos/demo-hush.mp4
BTLEJACK
BtleJack
Slides:
https://media.defcon.org/DEF%20CON%2026/DEF%20CON%2026%20presentations/Da
mien%20Cauquil%20-%20Updated/DEFCON-26-Damien-Cauquil-Secure-Your-BLE-
Devices-Updated.pdf
Source:
https://github.com/virtualabs/btlejack
BtleJack
> halt
> nrf51 mass_erase
> reset
> halt
> flash write_image nrf/btlejack-firmware-ble400.hex
(...)
> reset
For the new Btlejack version
Kali Linux:
# pip3 install btlejack
Btlejack – catch and follow connection requests
Value 00
Write 01 to 0x27
Value 01
Hijack the connection
https://smartlockpicking.com/hackmelock
Sources:
https://github.com/smartlockpicking/hackmelock-device/
https://github.com/smartlockpicking/hackmelock-android/
Requirements – emulator script
Hackmelock is written using node.js bleno library (and additional libs: colors,
async). It is already installed on your Raspberry.
It was tested on Linux (Kali, Raspberry Pi, ...), should run also on Mac,
probably Windows.
https://github.com/sandeepmistry/bleno
Install (already in your Kali)
Emulated device:
$ npm install hackmelock
Android app:
https://play.google.com/store/apps/details?id=com.smartlockpicking.hackmelock
Run emulator
$ cd node_modules/hackmelock/
$ node peripheral
advertising...
In configuration mode, it advertises iBeacon
Major/Minor=1
Pairing
After pairing emulator stores config.txt
$ node peripheral.js
advertising...
Client 4a:00:e9:88:16:63 connected!
Status read request:
Initialization mode!
initializing... 0 531ce397
initializing... 1 325d18fe1481151073dc4d4a
initializing... 2 7ca71db0196bda712131dc57
(...)
Config loaded - iBeaconMajor: 21276 iBeaconMinor: 58263
Sharing access
See also
Trainings
Tutorials
Events
...
https://www.smartlockpicking.com