Example #1
0
def setup():
    # Find connected sniffers
    ports = UART.find_sniffer()

    if len(ports) > 0:
        # Initialize the sniffer on the first port found with baudrate 1000000.
        # If you are using an old firmware version <= 2.0.0, simply remove the baudrate parameter here.
        sniffer = Sniffer.Sniffer(portnum=ports[0], baudrate=1000000)

    else:
        print("No sniffers found!")
        return

    sniffer.start()

    tls_dev_addr = [0xde, 0xde, 0x96, 0xdf, 0x92, 0x4a, True]

    for _ in range(10):
        time.sleep(1)
        devlist = sniffer.getDevices()
        found_dev = [
            dev for dev in devlist.devices if dev.address == tls_dev_addr
        ]
        if found_dev:
            follow(sniffer, found_dev[0])
            break
Example #2
0
def setup():
    global mySniffer

    # Find connected sniffers
    ports = UART.find_sniffer()

    if len(ports) > 0:
        # Initialize the sniffer on the first COM port found with baudrate 1000000.
        # If you are using an old firmware version <= 2.0.0, simply remove the baudrate parameter here.
        mySniffer = Sniffer.Sniffer(portnum=ports[0], baudrate=1000000)

    else:
        print("No sniffers found!")
        return

    # Start the sniffer module. This call is mandatory.
    mySniffer.start()

    # Wait to allow the sniffer to discover device mySniffer.
    time.sleep(5)
    # Retrieve list of discovered devicemySniffer.
    d = mySniffer.getDevices()
    # Find device with name "Example".
    dev = d.find('Example')

    if dev is not None:
        # Follow (sniff) device "Example". This call sends a REQ_FOLLOW command over UART.
        mySniffer.follow(dev)
    else:
        print("Could not find device")
    def start(self) -> None:
        interface = self.get_interfaces()[0]
        baudrate = self.get_baud_rates(interface)
        sniffer = Sniffer.Sniffer(interface, baudrate["default"])
        sniffer.subscribe("NEW_BLE_PACKET", self.new_packet)
        sniffer.setAdvHopSequence([37, 38, 39])
        sniffer.start()
        sniffer.scan()
        self.sniffer = sniffer

        while True:
            time.sleep(10)
def setup():
    sniffer = Sniffer.Sniffer("/dev/ttyACM0")
    sniffer.start()

    tls_dev_addr = [0xde, 0xde, 0x96, 0xdf, 0x92, 0x4a, True]

    for _ in range(10):
        time.sleep(1)
        devlist = sniffer.getDevices()
        found_dev = [dev for dev in devlist.devices if dev.address == tls_dev_addr]
        if found_dev:
            follow(sniffer, found_dev[0])
            break
Example #5
0
def setup():
    sniffer = Sniffer.Sniffer("/dev/cu.usbmodem0006821628261")
    sniffer.start()

    tls_dev_addr = [0xDE, 0xDE, 0x96, 0xDF, 0x92, 0x4A, True]

    for _ in range(10):
        time.sleep(1)
        devlist = sniffer.getDevices()
        print(devlist)
        found_dev = [
            dev for dev in devlist.devices if dev.address == tls_dev_addr
        ]
        if found_dev:
            follow(sniffer, found_dev[0])
            break
def sniffer_capture(interface, baudrate, fifo, control_in, control_out):
    """Start the sniffer to capture packets"""
    global fn_capture, fn_ctrl_in, fn_ctrl_out, write_new_packets

    with open(fifo, 'wb', 0) as fn_capture:
        capture_write(make_pcap_header())

        with open(control_out, 'wb', 0) as fn_ctrl_out:
            logging.info("control_out open: {}".format(fn_ctrl_out))
            control_write(CTRL_ARG_LOG, CTRL_CMD_SET, "")
            logging.info("Log started at " + time.strftime("%c"))

            validate_interface(interface, fifo)
            if baudrate is None:
                baudrate = get_default_baudrate(interface, fifo)

            with open(control_in, 'rb', 0) as fn_ctrl_in:
                logging.info("control_in open: {}".format(fn_ctrl_in))
                # Initialize the sniffer and discover devices.
                sniffer = Sniffer.Sniffer(interface, baudrate)
                sniffer.subscribe("NEW_BLE_PACKET", new_packet)
                sniffer.subscribe("DEVICE_ADDED", device_added)
                sniffer.subscribe("DEVICE_UPDATED", device_added)
                sniffer.subscribe("DEVICE_REMOVED", device_removed)
                sniffer.setAdvHopSequence([37, 38, 39])

                logging.info("sniffer created")

                sniffer.start()
                logging.info("sniffer started")
                sniffer.scan()
                logging.info("scanning started")

                # First read initial control values
                control_read_initial_values(sniffer)

                # Then write default values
                control_write_defaults()
                logging.info("defaults written")

                # Start receiving packets
                write_new_packets = True

                # Start the control loop
                logging.info("control loop")
                control_loop(sniffer)
                logging.info("exiting control loop")
Example #7
0
def setup(serport, delay=3):
    """
    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)
Example #8
0
def setup():
    global mySniffer

    # Initialize the sniffer on COM port COM19.
    # mySniffer = Sniffer.Sniffer("COM19")
    # Or initialize and let the sniffer discover the hardware.
    mySniffer = Sniffer.Sniffer()
    # Start the sniffer module. This call is mandatory.
    mySniffer.start()

    # Wait to allow the sniffer to discover device mySniffer.
    time.sleep(5)
    # Retrieve list of discovered devicemySniffer.
    d = mySniffer.getDevices()
    # Find device with name "Example".
    dev = d.find('Example')

    if dev is not None:
        # Follow (sniff) device "Example". This call sends a REQ_FOLLOW command over UART.
        mySniffer.follow(dev)
    else:
        print "Could not find device"
Example #9
0
def sniffer_capture(interface, fifo, control_in, control_out):
    """Start the sniffer to capture packets"""
    global fn_capture, fn_ctrl_in, fn_ctrl_out, write_new_packets

    with open(fifo, 'wb', 0) as fn_capture:
        capture_write(make_pcap_header())

        with open(control_out, 'wb', 0) as fn_ctrl_out:
            control_write(CTRL_ARG_LOG, CTRL_CMD_SET, "")
            logging.info("Log started at " + time.strftime("%c"))

            validate_interface(interface, fifo)

            # Initialize the sniffer and discover devices.
            sniffer = Sniffer.Sniffer(interface)
            sniffer.subscribe("NEW_BLE_PACKET", new_packet)
            sniffer.subscribe("DEVICE_ADDED", device_added)
            sniffer.subscribe("DEVICE_UPDATED", device_added)
            sniffer.subscribe("DEVICE_REMOVED", device_removed)
            sniffer.setAdvHopSequence([37, 38, 39])

            sniffer.start()
            sniffer.scan()

            with open(control_in, 'rb', 0) as fn_ctrl_in:
                print('control in file opened')
                # First read initial control values
                control_read_initial_values(sniffer)

                # Then write default values
                control_write_defaults()

                # Start receiving packets
                write_new_packets = True

                # Start the control loop
                control_loop(sniffer)
Example #10
0
def sniffer_capture(interface, baudrate, fifo, control_in, control_out):
    """Start the sniffer to capture packets"""
    global fn_capture, fn_ctrl_in, fn_ctrl_out, write_new_packets, extcap_log_handler

    try:
        fn_capture = open(fifo, 'wb', 0)

        if control_out is not None:
            fn_ctrl_out = open(control_out, 'wb', 0)
            setup_extcap_log_handler()

        if control_in is not None:
            fn_ctrl_in = open(control_in, 'rb', 0)

        logging.info("Log started at %s", time.strftime("%c"))

        capture_write(Pcap.get_global_header())
        validate_interface(interface, fifo)
        if baudrate is None:
            baudrate = get_default_baudrate(interface, fifo)

        sniffer = Sniffer.Sniffer(interface, baudrate)
        sniffer.subscribe("NEW_BLE_PACKET", new_packet)
        sniffer.subscribe("DEVICE_ADDED", device_added)
        sniffer.subscribe("DEVICE_UPDATED", device_added)
        sniffer.subscribe("DEVICE_REMOVED", device_removed)
        sniffer.setAdvHopSequence([37, 38, 39])
        logging.info("Sniffer created")

        sniffer.start()
        logging.info("sniffer started")
        sniffer.scan()
        logging.info("scanning started")

        if fn_ctrl_in is not None and fn_ctrl_out is not None:
            # First read initial control values
            control_read_initial_values(sniffer)

            # Then write default values
            control_write_defaults()
            logging.info("defaults written")

            # Start receiving packets
            write_new_packets = True

            # Start the control loop
            logging.info("control loop")
            control_loop(sniffer)
            logging.info("exiting control loop")

        else:
            logging.info("")
            # Start receiving packets
            write_new_packets = True
            while True:
                # Wait for keyboardinterrupt
                pass

    except OSError:
        # We'll get OSError=22 when/if wireshark kills the pipe(s) on capture
        # stop.
        teardown_extcap_log_handler()

    finally:
        # In case we got something else than OSError.
        teardown_extcap_log_handler()
        sniffer.doExit()
        if fn_capture is not None and not fn_capture.closed:
            fn_capture.close()

        if fn_ctrl_in is not None and not fn_ctrl_in.closed:
            fn_ctrl_in.close()

        if fn_ctrl_out is not None and not fn_ctrl_out.closed:
            fn_ctrl_out.close()

        fn_capture = None
        fn_ctrl_out = None
        fn_ctrl_in = None

        logging.info("exiting")
Example #11
0
        global udp_socket
        udp_socket = socket(AF_INET, SOCK_STREAM)
        print udp_host, udp_port, type(udp_port)
        udp_socket.connect((udp_host, udp_port))
    except socket_error, msg:
        print 'Failed to create socket. Error Code: %s | Message: %s' % (str(
            msg[0]), str(msg[1]))
        sys.exit()

    print 'UDP Socket created, Host: %s Port: %s' % (udp_host, udp_port)

    # initialize sniffer over the serial connection
    print "Connecting to sniffer on " + device_addr

    global ble_sniffer
    ble_sniffer = Sniffer.Sniffer(device_addr)
    ble_sniffer.start()


def scan_devices_and_follow():
    global ble_sniffer
    global udp_socket
    #devices = {}
    while True:
        packets = ble_sniffer.getPackets()
        for packet in packets:
            if packet.blePacket is not None:
                try:
                    addr = ':'.join(
                        ["%02X" % x for x in packet.blePacket.advAddress])
                    # Display the raw BLE packet payload