Warm tip: This article is reproduced from serverfault.com, please click

BLE sniffing: btsnoop log from adb bugreport using python script

发布于 2020-11-30 08:27:41

I'm new to reading Bluetooth device (BLE) data, and tried to follow this Medium tutorial (my Bluetooth Device is an Amazfit Bip).

I got stuck with finding the btsnoop_hci.log file (from a Samsung Galaxy S7), so I ran adb bugreport anewbugreportfolder as recommended in this Stack Overflow answer here.
In order for reproducibility, I uploaded the relevant part of my bugreport to Dropbox here.

My issue is: when I try to run btsnoop.py (can be found here) as recommended in the Stack Overflow answer linked above, I get very strange output that can't possibly be intended (for example, it starts with ��^D#} and contains lots of those weird question mark characters).

Is there some parts of the Python script that need to be adjusted for it to work correctly, for example encodings (none of the standard ones seem to give better results)? I am using Python 3.7. Alternatively, might it be about my Bluetooth device?

Questioner
Nico Autia
Viewed
0
pklaus 2020-12-06 17:51:05

There's nothing wrong with the output of the tool. It's your expectation of what to expect, that's incorrect: The output of the tool is binary content, not a text file.

The following command (not that the tool is called btsnooz, not btsnoop) redirects the binary output to a new file called btsnoop_hci.log:

$ python2 ./btsnooz.py ./bugreport-part.txt > btsnoop_hci.log

$ file btsnoop_hci.log
btsnoop_hci.log: BTSnoop version 1, HCI UART (H4)

The software Wireshark is perfectly able to interpret the produced BTSnoop logfile:

wireshark btsnoop_hci.log

Screenshot of Wireshark interpreting the file btsnoop_hci.log

A good filter to see only the relevant packets with CID 0x0004 is btl2cap.cid == 0x0004:

enter image description here

More hints on how to proceed can be found in this tutorial: Reverse Engineering BLE Devices - Application Protocol Reverse Engineering