© Aditya Gupta 2019
Aditya GuptaThe IoT Hacker's Handbookhttps://doi.org/10.1007/978-1-4842-4300-8_10

10. Exploiting ZigBee and BLE

Aditya Gupta1 
(1)
Walnut, CA, USA
 

Now that we have a good enough familiarity with radio communications and SDR, it is time to look at some of the most commonly used radio communication protocols, ZigBee and BLE.

When you are pentesting any IoT device, chances are that the device will be using one of these protocols. In this chapter, we cover how both of these protocols work and how we can assess the security of the devices that use these communication protocols.

We start by first looking into ZigBee and its architecture, and then move into finer details such as identifying the channel on which a given ZigBee device operates, and finally into performing things like sniffing and replaying of ZigBee packets. We then follow the same procedure for BLE.

ZigBee 101

ZigBee is a wireless communication networking standard used extensively in IoT devices designed for low-power usage scenarios with a low data transfer rate. ZigBee protocols are used in a number of settings including smart homes, building automation, industrial control devices (ICSs), smart health care, and more. A number of companies (400+) such as Philips, SiLabs, Texas Instruments, NXP, and others have combined to be known as the ZigBee Alliance and regularly use and contribute to the ZigBee protocol. This also allows various ZigBee devices to interact with each other; for example, a ZigBee-enabled smart socket from a given manufacturer is able to communicate with a ZigBee smart light bulb from another manufacturer.

The ZigBee communication protocol allows devices to communicate using a mesh network topology, which enables it to be used both for small and large networks, some including thousands of devices. ZigBee is based on 802.15.4 MAC and PHY layer, allowing it to leverage various capabilities, including basic message handling, congestion control, and techniques for joining a new network. The ZigBee stack is shown in Figure 10-1.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig1_HTML.png
Figure 10-1

ZigBee stack

ZigBee uses a frequency of 2.4 GHz in most countries, 915 MHz in the United States, and 868 MHz in Europe.

Understanding ZigBee Communication

A given ZigBee network can have various kinds of devices, as detailed here.
  • Coordinator: A single device in the entire network responsible for a number of actions, such as selecting the correct channel, creating a network, forming security settings, handling authentication, and later even acting as a router.

  • Router: Provides routing services to the various network devices present on the ZigBee network.

  • End devices: Perform operations such as reading the temperature or actions such as turning on a light. The end devices sleep most of the time to save power and only wake up on a read or write request.

In discussing the underlying concepts in ZigBee networking, it is important to also understand the addressing mode in ZigBee. A ZigBee device would have two addresses—one from 802.15 standards, which is a globally unique 64-bit number, one that is a 16-bit NWK address.

To communicate with a device, the addressing needs to contain three information components:
  • Address of the target device.

  • Endpoint number.

  • Cluster ID.

However, to send a broadcast, all a device needs to do is send a broadcast packet to the address 0xFFFF, which would be received by all the devices present on the ZigBee network.

Another thing that will be useful once we are exploiting ZigBee devices is the knowledge of channels used in ZigBee communications. There are a total of 16 channels used in ZigBee devices, so as we move forward into sniffing ZigBee channels, we would first need to figure out which channel the device is operating on and then capture ZigBee packets on that specific channel.

Hardware for ZigBee

A typical ZigBee hardware radio contains a combination of digital logic circuitry with analog circuits. One of the popular ZigBee modules, which you can also use to perform your initial security research, is the XBee module by Digi, shown in Figure 10-2.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig2_HTML.jpg
Figure 10-2

XBee module for ZigBee communication from Digi (Source: https://www.digi.com/lp/xbee )

In a real-world scenario, the ZigBee protocol can be implemented in a device in various ways:
  • In a system-on-chip (SoC)-based architecture where all the functions and implementations are done in a single chip.

  • As a microcontroller and transceiver where the transceiver manages the activities of the PHY and MAC layers, and the microcontroller handles the entire operation and implementation of the ZigBee stack.

  • As a network coprocessor (NXP), which is similar to the SoC model, but all the function interfaces are done through a serial interface such as UART.

ZigBee Security

Just like any other communication medium, there are a number of security issues that are possible with ZigBee, such as the ability to capture and intercept communication, replay packets, jam signals, and more. We will be looking into some of these security issues later in this chapter, but before we do that, we need to get ourselves a working setup to perform ZigBee exploitation.

Setting Up XBee

The first thing that we start with is programming an XBee with our corresponding channel and PAN ID. For this, we will use XCTU, which is a software tool to configure XBee devices, and an XBee explorer (or an XBee adapter), which is an adapter for XBee modules that can be plugged into our system. To get started, simply place the XBee module on the XBee adapter and connect it using a mini USB cable to your system.

The next step is to fire up XCTU and click Search Radio Modules as shown in Figure 10-3.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig3_HTML.jpg
Figure 10-3

Searching for available XBee modules in XCTU

XCTU then asks which interface to scan for radio modules, as shown in Figure 10-4.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig4_HTML.jpg
Figure 10-4

Selecting interfaces to scan for radio modules

You can keep the configurations as shown in Figure 10-5—which is searching for the radio modules at the baud rate of 2400 and 9600, 8 data bits, no parity bit, and one stop bit (8N1). Click Finish once you have selected the configuration and XCTU will start scanning for all the radio modules.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig5_HTML.jpg
Figure 10-5

Configurations for scanning for radio modules

As you can see in Figure 10-6, we have identified an XCTU module.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig6_HTML.jpg
Figure 10-6

One radio module found

Click Add Selected Devices and you’ll be able to see the radio module now added to the XCTU workspace. You will be able to change various properties of the XBee module as shown in Figure 10-7.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig7_HTML.jpg
Figure 10-7

Editing properties of the XBee module

For this, set the channel to 16 and leave the other parameters unchanged, then save the configuration. This is how we can set up our XBee module in the desired configuration.

Creating a Vulnerable ZigBee Setup

Now that we have our XBee configured, the next thing that we need to do is use an XBee shield with Arduino and our programmed XBee module plugged in. Figure 10-8 shows an XBee shield, which has an interface to connect Arduino and XBee.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig8_HTML.png
Figure 10-8

XBee Nano IO shield where we will place Arduino Nano and XBee

For this, we need to first program our Arduino with the code shown in Figure 10-9, which is an authentication program where the authentication happens over the ZigBee network. The complete code is given in the Downloads bundle for this book.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig9_HTML.jpg
Figure 10-9

Sample Arduino code performing authentication over a ZigBee network

Once we have flashed the Arduino with our vulnerable program, we are ready to plug everything in and start with our initial security analysis.

Introduction to KillerBee

Now that we have our vulnerable setup, the next step is to attack the target setup and perform radio-based attacks. For these purposes, we use a tool called KillerBee, which is an open source tool developed by RiverLoop Security to help assess and exploit ZigBee-based devices.

KillerBee supports a number of various hardware devices such as Atmel RzRaven USB Stick, APIMote, MoteIV Tmote Sky, TelosB mote, and Sewino Sniffer. For our current exercises and entire ZigBee exploitation, we use the Atmel RzRaven USB Stick, displayed in Figure 10-10.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig10_HTML.png
Figure 10-10

Atmel RzRaven USB stick for ZigBee sniffing

Before you start assessing ZigBee-based devices with KillerBee and RzRaven, the first step would be to flash the KillerBee firmware onto the RzRaven USB stick using AVR Dragon over JTAG interface . You can also get preflashed RzRaven sniffers ready to use from attify-store.com.

Once we have flashed the RzRaven USB stick, the next step is to download and set up KillerBee on our local system as shown in Listing 10-1.
# apt-get install python-gtk2 python-cairo python-usb python-crypto python-serial python-dev libgcrypt-dev
# hg clone https://bitbucket.org/secdev/scapy-com
# cd scapy-com
# python setup.py install
Listing 10-1

Setting Up KillerBee

The next step is to go to the killerbee/tools folder and run the zbid utility . Make sure your RzRaven USB stick is plugged in, and you should see the RzRaven device with an ID of all Fs, as shown in Figure 10-11.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig11_HTML.jpg
Figure 10-11

RzRaven USB stick connected to the VM

In case of an APIMote instead of RzRaven, you will see the device listed as GoodFET, as shown in Figure 10-12, instead of KillerBee.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig12_HTML.jpg
Figure 10-12

Running KillerBee tools with APIMote

The next step in any ZigBee security assessment is determining the channel of our target device. This can be done using another utility in the KillerBee tool suite called zbstumbler . Make sure to run zbstumbler with the –v flag to ensure that you get verbose messages, as in some cases when the packets detected by zbstumbler are not in the proper ZigBee packet format, it won’t show it on the terminal without the verbose flag.

To identify the channel being used by a ZigBee device, we need to look for the keyword Received Frame while running zbstumbler in verbose (-v flag) mode. As you can see in Figure 10-13, we have identified our target ZigBee setup on channel 20 in this case.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig13_HTML.jpg
Figure 10-13

Identifying the target IoT device’s ZigBee channel

../images/473264_1_En_10_Chapter/473264_1_En_10_Fig14_HTML.jpg
Figure 10-14

Capturing data on ZigBee channel 20 and writing to test.pcap

Sniffing ZigBee Packets

The next thing we can do is to capture all the packets using zbdump . This can be done by specifying the channel identified in Figure 10-13.

During this step, we try authenticating with our target device by entering the password in the serial monitor (Figure 10-15).
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig15_HTML.jpg
Figure 10-15

Serial monitor console in Arduino IDE

Once we have captured the packets, we can run strings on it and we will be able to see the strings that we mentioned in the Arduino program, as expected (see Figure 10-16).
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig16_HTML.jpg
Figure 10-16

Correct password ATTIFY visible in strings from the captured packets

We can also, instead of capturing packets to a dump file, sniff them actively using zbwireshark, and by specifying the channel ID on which you want to capture the packets. As you just saw, we were able to identify the channel ID of the ZigBee device and sniff the packets on that channel revealing our clear-text traffic.

Replaying ZigBee Packets

One of the other interesting things one could do with ZigBee communication is to perform replay-based attacks. This is extremely straightforward, as you would expect.

First, we need to capture the packets while a user is legitimately controlling the device. In this case, our target device is a Philips Hue Smart Hub and the connected light bulb. To perform this capture, we use the Attify ZigBee Framework, which is a GUI toolkit built on top of KillerBee.

To do this, you will need to specify the channel on which you want to perform the capture, the number of packets to capture, and the file in which the packets need to be stored, as shown in Figure 10-17.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig17_HTML.jpg
Figure 10-17

Exploiting Philips Hue light bulb using a ZigBee replay attack

During the sniffing period, we perform actions from the mobile application to control the Philips Hue smart light bulb, such as changing colors and turning it on and off.

Once we have captured the packets, the next step is to simply replay the packets. As we replay the packets, you would see the bulb being controlled without any user interaction and without the requirement of any authorization. This is also shown in Figure 10-18.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig18_HTML.jpg
Figure 10-18

Replaying captured packets on the same channel

We are able to control the ZigBee-enabled smart device by replaying packets because the CRC verification mechanism was not implemented.

This is all for the attacks on ZigBee here. As you can imagine, though, there are a number of additional attack vectors that you can now perform with the knowledge of foundational techniques used for exploitation.

Bluetooth Low Energy

Now that we have read about ZigBee, the other most common communication protocol is BLE. BLE has applications in a number of areas in IoT, especially because it is one of the communication protocols with which smartphones can speak.

You will find BLE in a number of smart devices including those used for health care, smart home automation, retail, smart enterprises, and so on. BLE has a number of advantages over other communication protocols, including the ability to conserve power for a longer duration of time, extremely low usage of resources even with higher amounts of data transfer, and so on.

Bluetooth was originally designed by Nokia with the name Wibree in 2006, which was then later adopted by the Bluetooth Special Interest Group (SIG) in 2010. Later on, the Bluetooth 4.0 core specification was released with the focus on designing a radio standard with low power consumption targeting use in devices with low resources, power, and bandwidth.

BLE Internals and Association

Before jumping into BLE security and the various exploitation techniques, let’s have a look at some of the BLE internals, so that we have a greater in-depth understanding of the foundational concepts when we are working with BLE-based IoT devices. Figure 10-19 shows the BLE stack structure.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig19_HTML.jpg
Figure 10-19

Bluetooth Low Energy stack (Source: https://www.bluetooth.com/specifications/bluetooth-core-specification )

As you can see from Figure 10-19, the BLE stack consists of two different layers—Host and Controller—bound via the Host Controller Interface (HCI). All the different components in various layers perform their own functionality; for example, the Physical layer is responsible for all the modulation and demodulation of the signals; the Link layer handles CRC generation, encryption, and defining how devices communicate with each other; and the Logical Link Control and Adaption Protocol (L2CAP) takes multiple data formats from the upper layers and puts them into a BLE packet structure.

At the very top of the BLE stack, inside the Host layer, you will notice a couple of more interesting components such as Attribute Protocol (ATT), Generic Attribute Profile (GATT), and Generic Access Profile (GAP).

Let’s explore what the functionalities of GAP and GATT are, as these are the two most important components in the BLE stack, and also something that you will encounter very frequently during your security research.
  • GAP is responsible for all the discovery and related aspects in any BLE network. ATT defines the client/server protocol for data exchange, which is then grouped together into meaningful services using the GATT.

  • GATT is responsible for the entire exchange of all user data and profile information in a BLE connection.

So as you can imagine, it will be GATT (or ATT) that we are mostly concerned with during our further security research journey. As we go deep inside a BLE connection, it is also vital to understand how all of the data are stored on a device in a BLE connection. This is better illustrated in Figure 10-20.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig20_HTML.jpg
Figure 10-20

BLE service, profile. and characteristics

Inside any BLE device, there can be a number of profiles, each of which will have different services. Services are a collection of characteristics (which we will come to in a while) or in layman’s terms, just a collection of information of a related nature. Services in this case could be anything that is defined by the Bluetooth SIG such as heart rate, blood pressure, alarm level, and so on. BLE developers are free to choose from one of the services defined by the Bluetooth SIG ( https://www.bluetooth.com/specifications/gatt/services ) or create their own.

Moving further in Figure 10-20, we have various characteristics that have a value and a descriptor. Characteristics are the actual values that are stored for a given service. As you can probably imagine here, it is the characteristics that we are interested in sniffing, reading, and modifying to exploit a given IoT device.

Now that we are familiar with the underlying concept of BLE internals, let’s have a quick look at what a typical authentication process looks like in BLE.

Figure 10-21 shows a representation of how BLE association and communication happens in IoT devices.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig21_HTML.jpg
Figure 10-21

BLE association and communication (Source: When Encryption is Not Enough [Shakacon 2016] by Sumanth Naropanth, Chandra Prakash Gopalaiah, & Kavya Racharla)

The entire process can be divided into the following steps:
  1. 1.

    There are two devices involved—a broadcaster and a peripheral. The broadcaster’s role is to collect and monitor data, and it is also constantly broadcasting for its availability. The observer observes these broadcasts.

     
  2. 2.

    Once an observer observes a broadcast message corresponding to what the observer is interested in, it sends a connection request to the peripheral.

     
  3. 3.

    Based on which pairing mechanism is selected, both the devices are now connected to each other.

     
  4. 4.

    Next, the data transmission starts, during which both the observer and the peripheral are sending and receiving data from each other.

     
One of the other things that is important to note during the association process is the pairing encryption that is used by devices. BLE provides four different ways of handling pairing, as given here.
  1. 1.
    JustWorks (JW)
    • One of the most common pairing modes.

    • Used in devices without a display or a small display without keypad.

    • Uses a key of six 0s: 000000.

     
  2. 2.
    Numeric comparison
    • Mostly used in devices with display for yes or no.

    • Shows the same number on both the devices and asks the user to confirm whether the numbers match.

     
  3. 3.
    Passkey
    • Uses a six-digit passkey.

    • Can be easily brute forced as a six-digit passkey only has 999,999 possible combinations.

     
  4. 4.
    Out of band
    • Very rare.

    • Shares the pin using an out-of-band channel like Near Field Communication (NFC).

     

Interacting with BLE Devices

Now that we understand the BLE architecture and how devices communicate, let’s go a step further and see it in action. Figure 10-22 shows our setup for this section.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig22_HTML.jpg
Figure 10-22

BLE dongle interacting with a BLE beacon

In this section, we interact with a BLE beacon and look at the various characteristics that are stored in the beacon. For this, we use a BLE adapter dongle and a utility called Gatttool.

Plug in the BLE dongle inside your system; if you are using a VM, make sure it is detected by the VM. You can verify it by using the command hciconfig, which should show an hci interface if the BLE dongle is successfully connected.

As you can see from Figure 10-23, we have a BLE adapter dongle connected with the Bluetooth Address (BD_ADDR) of 78:4F:43:55:A2:31.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig23_HTML.jpg
Figure 10-23

Configuring BLE adapter and dongle with hciconfig

Once we have connected the adapter, the next step is to search for BLE devices around us. We can use either the hcitool utility for this, or other open source projects such as Blue Hydra. Here we use hcitool’s lescan functionality to scan for nearby BLE devices.

As you can see in Figure 10-24, we have a couple of BLE devices nearby, such as the LEDBlue smart light bulb, UNI-LOCK smart lock, and a few other devices for which names have not been resolved.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig24_HTML.jpg
Figure 10-24

Hcitool lescan shows BLE devices in the vicinity

In this case, our beacon is with the address 0C:F3:EE:0E:19:97, which we can now connect with. We launch Gatttool using the additional flag of –I to launch in an interactive mode and –b providing the BD_ADDR of the target device, as shown in Figure 10-25. Once you’re at the Gatttool prompt, type connect to connect to the target device (see Figure 10-25).
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig25_HTML.jpg
Figure 10-25

Connecting to the target device using Gatttool

At this point, as shown in Figure 10-26, we can do primary services discovery and list all the various characteristics of the target device, which in this case is a beacon.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig26_HTML.jpg
Figure 10-26

Listing characteristics and services of target BLE device

Let’s try to read one of the characteristics here—0x000c—using char-read-hnd, also shown in Figure 10-27.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig27_HTML.jpg
Figure 10-27

Reading the handle value of 0x000c

If we go ahead and decode this as ASCII hex, we get the actual name that we have given to the beacon, in this case, testname, as shown in Figure 10-28.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig28_HTML.jpg
Figure 10-28

Decoding the hex value to ASCII

We can also try reading other handles such as 0x0014, which contains the hex string shown in Figure 10-29.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig29_HTML.jpg
Figure 10-29

Reading another handle from the target BLE device

Again, if we decode this, we get to see that this contains the URL wth which we have configured the beacon as shown in Figure 10-30.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig30_HTML.jpg
Figure 10-30

Decoding the URL value stored in the beacon

Let’s try this on another beacon—iTag. As earlier, the first step would be to find out the BD_ADDR of our target device using the lescan functionality of hcitool, as shown in Figure 10-31.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig31_HTML.jpg
Figure 10-31

Performing recon on another BLE device

In this case, our beacon has the address 20:CD:39:A8:3E:1E as shown in Figure 10-31.

Next, let’s go ahead and find out all the services that are present in this beacon using the primary command. As shown in Figure 10-32, it now lists all the services running on the target device along with attr handle, grp handle, and UUIDs. With the help of the first part of Universally Unique Identifier (UUID), we can also determine the service it relates to.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig32_HTML.jpg
Figure 10-32

Services list of iTag device

For example, for a UUID value of 00002800-0000-1000-8000-00805f9b34fb, the value 00002800 indicates that this is a GATT primary service.

In the case of this specific beacon, it is designed in such a way that during the normal operational state, the beacon stays connected to the device in all instances, but only for around five seconds. After that it disconnects and tries to connect again. This functionality allows users to tag this beacon to their valuables and makes sure they are not leaving the valuable item behind. This works on the principle that if the mobile application is not able to connect to the beacon every five seconds, the item is far away from the user. Let’s see if by modifying the properties of the beacon we are able to change this condition and make it stay connected all of the time.

If we look up the Bluetooth SIG web site mentioning the different UUIDs and their use cases at https://www.bluetooth.com/specifications/gatt/services , we see that UUID 0xfff0 is not one of the services defined by Bluetooth SIG. Let’s have a look at the handle for that particular UUID, and see if we find anything useful.

Using the char-desc command, we can get a list of all the handles, optionally also specifying the attr and end group handles, which in this case are 0x0021 and 0x0037, respectively. You can find the attr and end group handle of a particular UUID using this primary command:
char-desc 0x0021 0x0037
If we look at Figure 10-33, we can see the complete list of handles for UUID 0xff0 using the command char-desc.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig33_HTML.jpg
Figure 10-33

Listing characteristic descriptors

If we relate this to what has been defined by the Bluetooth SIG, we see that the service 0xfff1 to 0xfff7 is defined by the manufacturers, and the others are services adopted by the Bluetooth SIG such as primary service, characteristic, characteristic user description, and so on.

Let’s finally go ahead and read the handle 0x0023 using the command char-read-hnd 0x0023. As shown in Figure 10-34, the current value in that handle is 03.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig34_HTML.jpg
Figure 10-34

Reading characteristic value of handle 0x0023

We can also change this value to something like 01, as shown in Figure 10-35.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig35_HTML.jpg
Figure 10-35

Writing new value to the handle 0x0023

On the device side now, the device no longer disconnects every five seconds and an attacker can now steal the valuable item attached to the beacon without the user getting a notification that this valuable item is missing.

In our current device itself, the beacon that we are using has a sound buzzer. This buzzer gets triggered whenever the device is not close to the pairing device. This is another potential attack surface that we can try exploiting.

In the following steps, we take a deeper look at the buzzer functionality, the current value of the characteristic, and how we can modify the value to trigger the buzzer as per desire. Let’s again go ahead and have a look at the primary services in Figure 10-36.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig36_HTML.jpg
Figure 10-36

Listing of all the services of iTag

If we look up the Bluetooth SIG documentation online for the BLE GATT services available at https://www.bluetooth.com/specifications/gatt/services , we find that the UUID 00001802 is an immediate alert service, which is something of interest to us.

If you look at the output of the preceding command, the UUID 00001802 corresponds to the attr handle 0x0038. Let’s now go ahead and expand the handles of this particular UUID.

We can use the char-desc command to expand any given UUID as shown in Figure 10-37.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig37_HTML.jpg
Figure 10-37

Listing characteristic descriptors

In Figure 10-33, if we analyze the output, we are able to identify that out of the four UUID values,
  • 0x2800 corresponds to primary service.

  • 0x2803 corresponds to characteristic.

  • 0x2a06 corresponds to alert level.

  • 0x2901 corresponds to characteristic user description.

Next, we can read the value of the alert level handle, which is the UUID beginning with 00002a06, which corresponds to the handle 0x003a.
char-read-hnd 0x003a
As we can see from Figure 10-38, the current value of the handle 0x003a is 00.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig38_HTML.jpg
Figure 10-38

Reading handle 0x003a

We can write our own data to this handle using char-write-req, as shown in Figure 10-39, and make it 01.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig39_HTML.jpg
Figure 10-39

Writing a new value to the handle to trigger an alarm

As soon as we do this, the beacon starts making a loud buzzing sound, which was our goal.

In this section, we were able to dig deep into various devices using BLE and explore how the entire BLE stack was laid out. We were also able to read and modify data that changed the behavior of the target device.

Exploiting a Smart Bulb Using BLE

Now that we know how to work with basic BLE devices, and read and modify data, let’s move to more complicated real-world IoT devices using BLE. In this case, we will use a BLE-enabled smart light bulb. The goal of this exercise is to control the light bulb without any authentication required whatsoever.

The first step, as in all the cases, is to determine the BD_ADDR, which is the Bluetooth address of the target device. We can again find this using hcitool lescan as shown in Figure 10-40.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig40_HTML.jpg
Figure 10-40

Scanning for BLE light bulb

Our smart bulb in this case has the Bluetooth address of 88:C2:55:CA:E9:4A. Now before we jump into Gatttool and modify the handles to change the behavior of the device, we need to know what properties to change.

This is easier if the device has defined its various characteristics as per the Bluetooth SIG, but in cases where it is custom implemented, the only option left is to sniff the BLE traffic and figure out what the handles being written in the normal operation are, and write those handle values manually.

Sniffing BLE Packets

To sniff BLE packets, you can use various devices such as the Ubertooth One or the Adafruit BLE Sniffer. For our exercise purposes, we use the Ubertooth One by GreatScottGadgets.

Setting up Ubertooth is straightforward and can be done by following the instructions on the Ubertooth wiki located at https://github.com/greatscottgadgets/ubertooth/wiki/Building-from-git .

Once everything is installed, we use the utility ubertooth-btle to sniff BLE packets. The additional flags that we use are –f to follow the connections (because of channel hopping) and -t to specify the BD_ADDR of the target device, which in this case is 88:C2:55:CA:E9:4A. Once you run this, you will see the packets on the screen shown in Figure 10-41.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig41_HTML.jpg
Figure 10-41

BLE sniffing using Ubertooth

Here are some of the things that we note from Figure 10-41.
  1. 1.

    The Access address (AA) is 0x8e89bed6, which is used to manage the Link layer.

     
  2. 2.

    It is on channel 37, which is one of the dedicated advertising channels.

     
  3. 3.

    Packet PDU is ADV_IND, which means it is connectable, unidirectional, and scannable.

     
  4. 4.

    AdvA ID 88:c2:55:ca:e9:4a, which is the same as the BD_ADDR of the advertising device.

     
If you also look further into the scanning process, you will see what is shown in Figure 10-42.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig42_HTML.jpg
Figure 10-42

SCAN request and response in the BLE sniffing

If you look at Figure 10-42, it has both the scan response (SCAN_RSP) from the target device and scan request (SCAN_REQ) from the mobile application communicating with the smart light bulb.

SCAN_REQ
  • ScanA is a six-byte scanner address that also specifies, based on the Tx address, whether it is a random or public address.

  • AdvA is a six-byte advertiser address that also specifies, based on the RxAdd in PDU, whether the address is public or random.

SCAN_RSP
  • AdvA is a six-byte advertiser address where the TxAdd indicates the type of address, whether it is random or public.

  • ScanRspData is optional advertising data from the advertiser.

As we discussed in the very first sections regarding BLE, you will also see CONNECT_REQ packets as shown in Figure 10-43.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig43_HTML.jpg
Figure 10-43

CONNECT_REQ packet in BLE sniffing

Instead of just viewing the packets on the screen, it’s better to dump the data to a device and then to look at the packets in Wireshark and analyze them. To do this, simply add the –c flag pointing to where you would like to save it. This could point to either a capture file or to a pipe interface, which you can then actively listen to in Wireshark.
sudo ubertooth-btle –f –t [address-of-target] –c smartbulb.pcap
Let’s open the captured file in Wireshark. Figure 10-44 is what we see. If you are not able to see proper packets, make sure you are using the latest version of Wireshark with the DLT_USER (in Preferences | Protocols) set to btle.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig44_HTML.jpg
Figure 10-44

Using Wireshark for BLE sniffing

Because there are a lot of packets during the entire network communication, let’s filter out the packets that are of interest to us. In the top bar, which says Apply a display filter, type btl2cap.cid==0x004. If we look at the packets now in Figure 10-45, we see that there are only ATT packets with interesting information.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig45_HTML.jpg
Figure 10-45

Analyzing BLE packets (write and read) in Wireshark

During the packet capturing process, I changed the color of the light bulb, so let’s look for write packets in the Wireshark packet list. As we can see in Figure 10-45, the packet number 337 has the Write Request.

As we can see in Figure 10-46, the data are being written to the handle 0x0012. Let’s dissect this a step further and look into the packet details for this specific packet.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig46_HTML.jpg
Figure 10-46

Dissecting a BLE packet with write request to handle 0x0012

Here are some of the things that are noticeable in Figure 10-46.
  • Access address: 0xaf9a9515

    Master and slave address

    CRC: 0x6dcb56

    Handle: 0x0012

    UUID: 0xfff1

  • Value: 03c90006000a03000101000024ff00000000

While actually working on this exercise, if we perform the changing of colors a number of times, we notice that the value actually follows a specific pattern, which is shown in Figure 10-47.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig47_HTML.jpg
Figure 10-47

BLE packet data structure for a light bulb showing the RGB and ON/OFF values

This means that:
  • Header is two bytes in length, which comes along the PDU.

  • Mode selection is hard-coded for controlling the color of the lamp.

  • The six-byte 0024ff is the RGB value. These six bytes can be changed accordingly to get the desired color.

Now that we know which values in the packet are the ones controlling the color and turning the bulb on and off, we can either replay these packets or use Gatttool to write the values manually to the bulb as shown here.
  • char-write-req 0x0012 03c90006000a03000101000024ff00000000

  • char-write-req 0x0012 03c90006000a0300010100ff000000000000

  • char-write-req 0x0012 03c90006000a030001010000ff0000000000

  • char-write-req 0x0012 03c90006000a03000101000000ff00000000

Here are the results found from those commands:
  • 03c90006000a03000101000024ff00000000 made the bulb turn bluish green.

  • 03c90006000a0300010100ff000000000000 made the bulb turn red.

  • 03c90006000a030001010000ff0000000000 made the bulb turn green.

  • 03c90006000a03000101000000ff00000000 made the bulb turn blue.

It was also possible to turn the bulb on and off by toggling the on/off bit in the data.
  • char-write-req 0x0012 03c90006000a030101010000000000000000

  • char-write-req 0x0012 03c90006000a0300010100ff000000000000

Here are the results of those commands:
  • 03c90006000a030101010000000000000000 will turn off your bulb. Make sure to keep the RGB value as zero.

  • 03c90006000a0300010100ff0000000000000 will turn on your bulb, where the RGB value is mandatory.

This is how we can take control of a given BLE device using techniques such as sniffing and manually writing the value of the BLE devices.

Exploiting a BLE Smart Lock

In some cases, there might be two writes required to take control of the target device—the first one being the authentication, and the next one being the actual data that need to be written.

Let’s take a smart lock for example. If we capture the packets during the normal lock and unlock process and look at Wireshark for the captured packets, Figure 10-48 is what we see. Therefore, in exploiting the device with Gatttool, we first need to pass it the authentication data, which we were able to sniff in this case, because they were being passed in clear text on an insecure BLE channel.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig48_HTML.jpg
Figure 10-48

Writing values to a smart door lock –sending password

Next, we simply write the value that determines whether the lock is locked or unlocked, as shown in Figure 10-49.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig49_HTML.jpg
Figure 10-49

Writing values to a smart door lock –unlock command

Now, if you check the smart lock, it has been unlocked. This was all about sniffing BLE packets and manipulating them using Gatttool, both for basic devices and for complex real-world devices such as a smart lock and a smart light bulb.

Replaying BLE Packets

One of the additional things you can try is using tools such as BTLEJuice, which is an excellent handy utility for performing processed such as replay-based attacks. What follows is a demonstration of how to use the tool.

The first step is to connect the target device from the BTLEJuice web interface, shown in Figure 10-50.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig50_HTML.jpg
Figure 10-50

Using BTLEJuice for BLE sniffing

Now, as we start performing actions in the smart light bulb, we will be able to see traffic in the BTLEJuice interface in the Data section along with a specific column mentioning the characteristic that’s being read or written, the service value, and the action that is taking place, as shown in Figure 10-51.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig51_HTML.jpg
Figure 10-51

Real-time BLE sniffing using BTLEJuice

You can right-click any particular data packet and select Replay as shown in Figure 10-52.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig52_HTML.jpg
Figure 10-52

Replaying a BLE packet

This opens a dialog box mentioning the data that are being replayed, and if you want to perform any changes in the data that are replayed. You can change the RGB values and on/off toggle bit here.

Once you click Write (see Figure 10-53), you will see that the bulb’s color has changed or the bulb has turned on or off, depending on what data you wrote.
../images/473264_1_En_10_Chapter/473264_1_En_10_Fig53_HTML.jpg
Figure 10-53

Modifying BLE packet data and replying

Conclusion

In this chapter, we covered a number of topics concerning the security of the two most popular communication protocols used in IoT devices, ZigBee and BLE. We had a look at some of the attacks concerning these protocols and laid a foundation for you to research further into the security issues that these communication protocols bring with them when implemented in an IoT device.

In case you encounter other protocols, such as 6LoWPAN, LoRA, ZWave, and others, remember that the attack categories and techniques would be pretty much the same; just the selection of tools and hardware will change in cases other than the ones covered in this chapter.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.23.101.60