0

BLE Sniffer Wireshark Hangs
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

BLE Sniffer Wireshark Hangs

by csete on Wed Jun 02, 2021 11:38 am

Hello,

I picked up a https://www.adafruit.com/product/2269 . I've tried to follow a variety of internet directions to get this set up to work with Wireshark, but every time I attempt to start the packet capture Wireshark hangs and I have to "force close" it. The device is blinking blue and appears to be functional, so I'm not sure if I just have something misconfigured? My version information:
Code: Select all | TOGGLE FULL SIZE
Ubuntu 21.04
Python 3.9.5
Wireshark 3.4.4
nRF Sniffer 3.1.0 (from https://www.nordicsemi.com/Software-and-tools/Development-Tools/nRF-Sniffer-for-Bluetooth-LE/Download#infotabs)


The interfaces command is successful from CLI:

Code: Select all | TOGGLE FULL SIZE
./nrf_sniffer_ble.sh --extcap-interfaces
extcap {version=3.1.0}{display=nRF Sniffer for Bluetooth LE}{help=https://www.nordicsemi.com/Software-and-Tools/Development-Tools/nRF-Sniffer-for-Bluetooth-LE}
interface {value=/dev/ttyUSB0}{display=nRF Sniffer for Bluetooth LE}
control {number=0}{type=selector}{display=Device}{tooltip=Device list}
control {number=1}{type=string}{display=Passkey / OOB key}{tooltip=6 digit temporary key or 16 byte Out-of-band (OOB) key in hexadecimal starting with '0x', big endian format. If the entered key is shorter than 16 bytes, it will be zero-padded in front'}{validation=\b^(([0-9]{6})|(0x[0-9a-fA-F]{1,32}))$\b}
control {number=2}{type=string}{display=Adv Hop}{default=37,38,39}{tooltip=Advertising channel hop sequence. Change the order in which the siffer switches advertising channels. Valid channels are 37, 38 and 39 separated by comma.}{validation=^\s*((37|38|39)\s*,\s*){0,2}(37|38|39){1}\s*$}{required=true}
control {number=3}{type=button}{role=help}{display=Help}{tooltip=Access user guide (launches browser)}
control {number=4}{type=button}{role=restore}{display=Defaults}{tooltip=Resets the user interface and clears the log file}
control {number=5}{type=button}{role=logger}{display=Log}{tooltip=Log per interface}
value {control=0}{value= }{display=All advertising devices}{default=true}


I'm able to see the device in Wireshark UI, but when I attempt to start the capture, Wireshark just freezes. I could use some help in troubleshooting the issue, as I can't figure out next steps.

Thanks!
Craig

csete
 
Posts: 6
Joined: Wed Jun 02, 2021 11:27 am

Re: BLE Sniffer Wireshark Hangs

by mikeysklar on Wed Jun 02, 2021 5:54 pm

Craig,

Are you running the sniffer wrapper?

Code: Select all | TOGGLE FULL SIZE
$ sudo python sniffer.py /dev/ttyACM0


https://learn.adafruit.com/introducing- ... 1329658-13

mikeysklar
 
Posts: 4925
Joined: Mon Aug 01, 2016 8:10 pm

Re: BLE Sniffer Wireshark Hangs

by csete on Wed Jun 02, 2021 8:45 pm

mikeysklar wrote:Craig,

Are you running the sniffer wrapper?

Code: Select all | TOGGLE FULL SIZE
$ sudo python sniffer.py /dev/ttyACM0


https://learn.adafruit.com/introducing- ... 1329658-13


Am I supposed to start something outside of Wireshark? I've tried a few combinations of parameters to the nrf_sniffer app, with no luck thus far. For instance:
Code: Select all | TOGGLE FULL SIZE
 ./nrf_sniffer_ble.sh --capture --extcap-interface /dev/ttyUSB0


just shows the usage information.

csete
 
Posts: 6
Joined: Wed Jun 02, 2021 11:27 am

Re: BLE Sniffer Wireshark Hangs

by csete on Thu Jun 03, 2021 1:37 pm

I should add. If I start up wireshark and look at associated processes, I'm seeing:

Code: Select all | TOGGLE FULL SIZE
╰─➤  ps ax | grep -i wireshark                                                                                      1 ↵
  13788 ?        S      0:00 /bin/sh /home/setera/.config/wireshark/extcap/nrf_sniffer_ble.sh --capture --extcap-interface /dev/ttyUSB0 --fifo /tmp/wireshark_extcap_-dev-ttyUSB0GZ5K40 --extcap-control-out /tmp/wireshark_control_ext_to_ws_-dev-ttyUSB0VO5K40 --extcap-control-in /tmp/wireshark_control_ws_to_ext_-dev-ttyUSB0GV5K40
  13793 ?        Sl     0:00 /usr/bin/python3 /home/setera/.config/wireshark/extcap/nrf_sniffer_ble.py --capture --extcap-interface /dev/ttyUSB0 --fifo /tmp/wireshark_extcap_-dev-ttyUSB0GZ5K40 --extcap-control-out /tmp/wireshark_control_ext_to_ws_-dev-ttyUSB0VO5K40 --extcap-control-in /tmp/wireshark_control_ws_to_ext_-dev-ttyUSB0GV5K40
  50935 ?        Sl     0:01 wireshark


Does this off any clues?

csete
 
Posts: 6
Joined: Wed Jun 02, 2021 11:27 am

Re: BLE Sniffer Wireshark Hangs

by csete on Thu Jun 03, 2021 2:30 pm

mikeysklar wrote:Craig,

Are you running the sniffer wrapper?

Code: Select all | TOGGLE FULL SIZE
$ sudo python sniffer.py /dev/ttyACM0


https://learn.adafruit.com/introducing- ... 1329658-13


I figured out after my other responses that this is an Adafruit-specific wrapper around the SnifferAPI stuff. I pulled that down from Github and was able to get a capture, so I know that the hardware is working. Now, I'd really like to figure out how to get this working properly inside of Wireshark. Still hopeful someone can point me in the right direction.

Thanks again,
Craig

csete
 
Posts: 6
Joined: Wed Jun 02, 2021 11:27 am

Re: BLE Sniffer Wireshark Hangs

by mikeysklar on Thu Jun 03, 2021 6:36 pm

@csete,

When you start up wireshark using our sniffer.py wrapper everything works correctly?

If your goal is to startup wireshark without the sniffer you can take a look at what the wrapper is doing. It looks to be mostly BLE device scanning oriented.

https://github.com/adafruit/Adafruit_BL ... sniffer.py

Code: Select all | TOGGLE FULL SIZE
from __future__ import absolute_import
from __future__ import print_function
from six.moves import input
__author__ = "ktown"
__copyright__ = "Copyright Adafruit Industries 2014 (adafruit.com)"
__license__ = "MIT"
__version__ = "0.1.0"

import os
import sys
import time
import argparse

from SnifferAPI import Logger
from SnifferAPI import Sniffer
from SnifferAPI import CaptureFiles
from SnifferAPI.Devices import Device
from SnifferAPI.Devices import DeviceList


mySniffer = None
"""@type: SnifferAPI.Sniffer.Sniffer"""


def setup(serport, delay=6):
    """
    Tries to connect to and initialize the sniffer using the specific serial port
    @param serport: The name of the serial port to connect to ("COM14", "/dev/tty.usbmodem1412311", etc.)
    @type serport: str
    @param delay: Time to wait for the UART connection to be established (in seconds)
    @param delay: int
    """
    global mySniffer

    # Initialize the device on the specified serial port
    print("Connecting to sniffer on " + serport)
    mySniffer = Sniffer.Sniffer(serport)
    # Start the sniffer
    mySniffer.start()
    # Wait a bit for the connection to initialise
    time.sleep(delay)


def scanForDevices(scantime=5):
    """
    @param scantime: The time (in seconds) to scan for BLE devices in range
    @type scantime: float
    @return: A DeviceList of any devices found during the scanning process
    @rtype: DeviceList
    """
    if args.verbose:
        print("Starting BLE device scan ({0} seconds)".format(str(scantime)))

    mySniffer.scan()
    time.sleep(scantime)
    devs = mySniffer.getDevices()
    return devs


def selectDevice(devlist):
    """
    Attempts to select a specific Device from the supplied DeviceList
    @param devlist: The full DeviceList that will be used to select a target Device from
    @type devlist: DeviceList
    @return: A Device object if a selection was made, otherwise None
    @rtype: Device
    """
    count = 0

    if len(devlist):
        print("Found {0} BLE devices:\n".format(str(len(devlist))))
        # Display a list of devices, sorting them by index number
        for d in devlist.asList():
            """@type : Device"""
            count += 1
            print("  [{0}] {1} ({2}:{3}:{4}:{5}:{6}:{7}, RSSI = {8})".format(count, d.name,
                                                                             "%02X" % d.address[0],
                                                                             "%02X" % d.address[1],
                                                                             "%02X" % d.address[2],
                                                                             "%02X" % d.address[3],
                                                                             "%02X" % d.address[4],
                                                                             "%02X" % d.address[5],
                                                                             d.RSSI))
        try:
            i = int(input("\nSelect a device to sniff, or '0' to scan again\n> "))
        except KeyboardInterrupt:
            raise KeyboardInterrupt
            return None
        except:
            return None

        # Select a device or scan again, depending on the input
        if (i > 0) and (i <= count):
            # Select the indicated device
            return devlist.find(i - 1)
        else:
            # This will start a new scan
            return None


def dumpPackets():
    """Dumps incoming packets to the display"""
    # Get (pop) unprocessed BLE packets.
    packets = mySniffer.getPackets()
    # Display the packets on the screen in verbose mode
    if args.verbose:
        for packet in packets:
            if packet.blePacket is not None:
                # Display the raw BLE packet payload
                # Note: 'BlePacket' is nested inside the higher level 'Packet' wrapper class
                print(packet.blePacket.payload)
            else:
                print(packet)
    else:
        print('.' * len(packets))


if __name__ == '__main__':
    """Main program execution point"""

    # Instantiate the command line argument parser
    argparser = argparse.ArgumentParser(
        description="Interacts with the Bluefruit LE Friend Sniffer firmware")

    # Add the individual arguments
    # Mandatory arguments:
    argparser.add_argument("serialport",
                           help="serial port location ('COM14', '/dev/tty.usbserial-DN009WNO', etc.)")

    # Optional arguments:
    argparser.add_argument("-l", "--logfile",
                           dest="logfile",
                           default=CaptureFiles.captureFilePath,
                           help="log packets to file, default: " + CaptureFiles.captureFilePath)

    argparser.add_argument("-t", "--target",
                           dest="target",
                           help="target device address")

    argparser.add_argument("-r", "--random_txaddr",
                           dest="txaddr",
                           action="store_true",
                           default=False,
                           help="Target device is using random address")

    argparser.add_argument("-v", "--verbose",
                           dest="verbose",
                           action="store_true",
                           default=False,
                           help="verbose mode (all serial traffic is displayed)")

    # Parser the arguments passed in from the command-line
    args = argparser.parse_args()

    # Display the libpcap logfile location
    print("Capturing data to " + args.logfile)
    CaptureFiles.captureFilePath = args.logfile

    # Try to open the serial port
    try:
        setup(args.serialport)
    except OSError:
        # pySerial returns an OSError if an invalid port is supplied
        print("Unable to open serial port '" + args.serialport + "'")
        sys.exit(-1)
    except KeyboardInterrupt:
        sys.exit(-1)

    # Optionally display some information about the sniffer
    if args.verbose:
        print("Sniffer Firmware Version: " + str(mySniffer.swversion))

    # Scan for devices in range until the user makes a selection
    try:
        d = None
        """@type: Device"""
        if args.target:
            print("specified target device", args.target)
            _mac = [int(x, 16) for x in args.target.split(':')]
            if len(_mac) != 6:
                raise ValueError("Invalid device address")
            # -72 seems reasonable for a target device right next to the sniffer
            d = Device(_mac, name="NoDeviceName", RSSI=-72, txAdd=args.txaddr)

        # loop will be skipped if a target device is specified on commandline
        while d is None:
            print("Scanning for BLE devices (5s) ...")
            devlist = scanForDevices()
            if len(devlist):
                # Select a device
                d = selectDevice(devlist)

        # Start sniffing the selected device
        print("Attempting to follow device {0}:{1}:{2}:{3}:{4}:{5}".format("%02X" % d.address[0],
                                                                           "%02X" % d.address[1],
                                                                           "%02X" % d.address[2],
                                                                           "%02X" % d.address[3],
                                                                           "%02X" % d.address[4],
                                                                           "%02X" % d.address[5]))
        # Make sure we actually followed the selected device (i.e. it's still available, etc.)
        if d is not None:
            mySniffer.follow(d)
        else:
            print("ERROR: Could not find the selected device")

        # Dump packets
        while True:
            dumpPackets()
            time.sleep(1)

        # Close gracefully
        mySniffer.doExit()
        sys.exit()

    except (KeyboardInterrupt, ValueError, IndexError) as e:
        # Close gracefully on CTRL+C
        if 'KeyboardInterrupt' not in str(type(e)):
            print("Caught exception:", e)
        mySniffer.doExit()
        sys.exit(-1)

mikeysklar
 
Posts: 4925
Joined: Mon Aug 01, 2016 8:10 pm

Re: BLE Sniffer Wireshark Hangs

by csete on Mon Jun 07, 2021 1:42 pm

mikeysklar wrote:@csete,

When you start up wireshark using our sniffer.py wrapper everything works correctly?

If your goal is to startup wireshark without the sniffer you can take a look at what the wrapper is doing. It looks to be mostly BLE device scanning oriented.

https://github.com/adafruit/Adafruit_BL ... sniffer.py



Apologies for not responding sooner. I did not get notification of updates to this thread for some reason.

When I used the Adafruit wrapper, I did not try to connect Wireshark up to it directly. From what I saw in the code, it says that it is just used to write out pcap files? I'm still unsure why the Nordic Wireshark extcap stuff won't work with the dongle. Is there a difference in the firmware that is loaded on to the Adafruit sniffer hardware?

Thanks again for your help.
Craig

csete
 
Posts: 6
Joined: Wed Jun 02, 2021 11:27 am

Re: BLE Sniffer Wireshark Hangs

by mikeysklar on Mon Jun 07, 2021 5:31 pm

Craig,

I believe Adafruit is just using the Nordic firmware so you are on the latest 3.1.0 current release which is great.

I suspect the issue is just in your Wireshark configuration profile. You could take a look at a third party site as shown here that mentions configuring Wireshark for profiles.

https://jimmywongiot.com/2020/07/08/how ... -dk-board/

jump down to :

To add the nRF Sniffer profile in Wireshark, complete the following steps:

Go to Help > About Wireshark (on Windows or Linux) or Wireshark > About Wireshark (on macOS).

mikeysklar
 
Posts: 4925
Joined: Mon Aug 01, 2016 8:10 pm

Re: BLE Sniffer Wireshark Hangs

by csete on Mon Jun 07, 2021 10:31 pm

mikeysklar wrote:Craig,

I believe Adafruit is just using the Nordic firmware so you are on the latest 3.1.0 current release which is great.

I suspect the issue is just in your Wireshark configuration profile. You could take a look at a third party site as shown here that mentions configuring Wireshark for profiles.

https://jimmywongiot.com/2020/07/08/how ... -dk-board/

jump down to :

To add the nRF Sniffer profile in Wireshark, complete the following steps:

Go to Help > About Wireshark (on Windows or Linux) or Wireshark > About Wireshark (on macOS).


I did follow these instructions along the way, but I will take another look to see if I missed anything. I figure worst case scenario, I can add a bunch of extra logging to the Python code to try to narrow down the issue.

Thanks!
Craig

csete
 
Posts: 6
Joined: Wed Jun 02, 2021 11:27 am

Please be positive and constructive with your questions and comments.