Ph0wn 2021: Wazabee write-up [EN]

Publié le 23 janvier 2022

Note aux francophones: j'ai rédigé ce write-up initialement en anglais, et je n'ai pas eu/pris le temps de le traduire en français. Je sais, je commence mal l'année 2022 (mais lisez ce write-up, l'épreuve était vraiment sympa =)

During the ph0wn CTF that took place virtually on December the 3rd, a strange challenge called Wazabee were available with the following description:

Hint: Do some OSINT on the challenge author to find what this can be about.

Jean Reno has created a network surveillance startup, called Wazabee. He
installed this Android application (download it) on his smartphone and it
looks like it is transmitting something important. But what? Help him,
and you might get to play in Wasabi 2.

Install the application on an Android smartphone (it is not malicious)
that supports Extended advertising and LE 2M. You can easily test your phone's
capabilities with the nRF Connect application. Go in "Device information" and
check the corresponding labels are green.

Your smartphone does not support it? Too bad :=) Get one! Or find another way
to solve the challenge (there are several solutions).

The flag follows the usual format: ph0wn{ .... } where it can any printable
character between the brackets.

We are provided with an Android APK that must be run on a smartphone that supports Extended advertising and LE 2M.

Well, let's have a look at it.

Bluetooth 5, OSINT and Zigbee

First of all, I don't own a smartphone that supports Extended advertising and LE 2M but I know a little of Bluetooth Low Energy. Extended advertisements and a bitrate of 2 Mbps have been introduced in the version 5 of the Bluetooth core specification, that allows any compatible device to send BLE advertisements on all channels (instead of the only 3 advertising channels 37, 38, and 39 as specified in previous versions) at 2 Mbit per second.

Second, a hint is given in the description, telling us to do a background search on the author of this challenge (Romain Cayre). A quick search revealed that Romain Cayre published a paper written in French, at the French SSTIC conference, called "WazaBee : attaque de réseaux Zigbee par détournement de puces Bluetooth Low Energy" (or "WazaBee: attacking Zigbee networks by subverting Bluetooth Low Energy chips").

This paper presents a way to make a BLE 5 compatible chip send Zigbee frames by abusing the GFSK modulation used in Bluetooth Low Energy PHY. This paper contains the word "Wazabee" in its title (which sounds like "wasabi" in French -- also a French movie starring Jean Reno) and is about Bluetooth Low Energy (and Zigbee). Well, that's becoming interesting !

Analyzing the Android APK

Once disassembled using Jadx, the interesting code is found in the radio.sploit.phownchallenge.SecondFragment class:

@Override // androidx.fragment.app.Fragment
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    final BluetoothLeAdvertiser advertiser = BluetoothAdapter.getDefaultAdapter()
    final View v = getView();
    if (!adapter.isLe2MPhySupported()) {
        Snackbar.make(v, "2M PHY not supported!", -1).show();
    } else if (!adapter.isLeExtendedAdvertisingSupported()) {
        Snackbar.make(v, "LE Extended Advertising not supported!", -1).show();
    } else {

This code checks that the 2 Mbps bitrate and extended advertising are supported, and then builds a payload that is sent in bluetooth low energy advertisements:

AdvertisingSetParameters.Builder parameters = new AdvertisingSetParameters.Builder()

String a = getString(R.string.a);
String b = getString(R.string.b);
String c = getString(R.string.c);
String d = getString(R.string.d);
String e = getString(R.string.e);
String out = "";
int x = 0;
while (out.length() != 64) {
    if (x % 4 == 0) {
        out = a + out + b;
    if (x % 4 == 1) {
        out = c + out + d;
    if (x % 4 == 2) {
        out = d + out + c;
    if (x % 4 == 3) {
        out = b + out + a;
AdvertiseData data = new AdvertiseData.Builder()
    dewhiten(hexStringToByteArray(out + e), 17, 16)

The referenced strings are the following:

  • R.string.a = "1b"
  • R.string.b = "03"
  • R.string.c = "3a"
  • R.string.d = "f7"
  • R.string.e = "70afb33965...0afb3393970af33"

Let's write some Python code to generate the same advertising data:

# generate out
a = '1b'
b = '03'
c = '3a'
d = 'f7'
e = '70afb33965fc08453b9b03773970af3303f73a1b70afb339fc08c564f73a9b03' \
    '03f73a1bb239702f70afb33970afb33908c5647cf73a9b034dc68f5070afb339' \
    'c68f504cb239702f514cc60fb239702f4dc68f50f73a9b0303f73a1b70afb339' \
    'c464fc08aeb33970b239702ff73a9b03f73a9b0370afb33965fc0845aeb33970' \
x = 0
out = ''
while len(out)!=64:
    if x%4==0:
        out = a + out + b
    if x%4==1:
        out = c + out + d
    if x%4==2:
        out = d + out + c
    if x%4==3:
        out = b + out + a
    x += 1

# Payload is dewhitened before sending, because it will be whitened
# again when sent by the BLE chip =)
payload = out + e
print('advertising payload:\n%s' % payload)
data = bytearray.fromhex(payload)

This script produces the following output:

advertising payload:

This data is what is sent in BLE advertisements as manufacturer data, but the meaning is still unknown. It's now time to dig into Cayre's paper to understand what is going on !

From Bluetooth Low Energy to Zigbee

We won't cover all the details of Cayre's paper (so read it if you are looking for more information) but only the most interesting aspects that may be useful to decode this data.

Cayre found out that Bluetooth Low Energy PHY layer uses a Gaussian Frequency Shift Keying (GFSK) modulation that can be considered (in a way) as an Minimum Shift Keying (MSK) modulation. This MSK modulation when used with a 2 Mbit per second bitrate may be used to generate a RF signal (composed of I/Q samples) that fits the O-QPSK modulation used by Zigbee. In short, a BLE chip can send BLE data at 2 Mbps on a specific BLE channel that would be interpreted by a Zigbee receiver (using an O-QPSK demodulator) as a valid series of bits representing a Zigbee frame.

Cayre provides in his paper a specific table (table 2) that can be used to convert a block of 4 bits of Zigbee data into a series of 31 bits that would be interpreted as a PN sequence used in Zigbee PHY layer. And this is exactly what this Android application does: it sends a series of bits using MSK modulation that will be decoded as PN sequences and then turned into a series of 4-bit blocks by a Zigbee receiver and interpreted as such. For the record, the payload is dewhitened before sending because the BLE chip will whiten the data (and undo this dewhitening) before sending it, thus ensuring our payload is sent as-is.

Therefore, we need to do some bit-level magic with our recovered advertising payload in order to extract the MSK-encoded PN sequences with the help of some Python code:

# reverse lookup table from Cayre's paper (table 2)
msk_to_block = {

def msk_to_chip(seq):
    assert seq in msk_to_block
    return msk_to_block[seq]

def byte_to_bits(b):
    return bin(b)[2:].rjust(8,'0')[::-1]

# generate out
a = '1b'
b = '03'
c = '3a'
d = 'f7'
e = '70afb33965fc08453b9b03773970af3303f73a1b70afb339fc08c564f73a9b03' \
    '03f73a1bb239702f70afb33970afb33908c5647cf73a9b034dc68f5070afb339' \
    'c68f504cb239702f514cc60fb239702f4dc68f50f73a9b0303f73a1b70afb339' \
    'c464fc08aeb33970b239702ff73a9b03f73a9b0370afb33965fc0845aeb33970' \
x = 0
out = ''
while len(out)!=64:
    if x%4==0:
        out = a + out + b
    if x%4==1:
        out = c + out + d
    if x%4==2:
        out = d + out + c
    if x%4==3:
        out = b + out + a
    x += 1

# Payload is dewhitened before sending, because it will be whitened
again when sent by the BLE chip =)
payload = out + e
data = bytearray.fromhex(payload)

# Convert payload into bits
data_bits = ''
for c in data:
    data_bits += byte_to_bits(c)

# Split by blocks of 31 bits (MSK-encoded PN sequences)
# and convert to corresponding 4-bit chip
chips = [data_bits[32*i:32*(i+1)] for i in range(int(len(data_bits)/32))]
output = ''.join([msk_to_chip(chip[:31]) for chip in chips])

This small script produces the following output:


A little bit more of Python to convert this into bytes:

# Group output by 8 bits and rebuild data
nbytes = int(len(output)/8.)
output_bytes = [chr(int(output[8*i:8*(i+1)][::-1],2)) for i in range(nbytes)]

And this displays the following text (the first null bytes are omitted): §ph0wn{9=kpcvZ|wU}. These bytes may correspond to a Zigbee beacon, but we don't need to decode it as the flag is clearly readable.

Les contenus disponibles sur ce blog sont publiés sous licence Creative Commons BY-NC-SA.
Vous pouvez réutiliser tout ou partie de ces contenus à condition de citer l'auteur et l'origine, vous ne pouvez en faire une utilisation commerciale, et enfin vous devez partager tout travail ou œuvre dérivée sous les mêmes conditions — c'est-à-dire avec la même licence d'utilisation Creative Commons.