Example #1
0
def devlist(vendor=None, product=None, gps=None, include=None):
    '''
    Return device information for all present devices, 
    filtering if requested by vendor and/or product IDs on USB devices, and
    running device fingerprint functions on serial devices.
    @type gps: String
    @param gps: Optional serial device identifier for an attached GPS
        unit. If provided, or if global variable has previously been set, 
        KillerBee skips that device in device enumeration process.
    @type include: List of Strings
    @param include: Optional list of device handles to be appended to the 
        normally found devices. This is useful for providing IP addresses for
        remote scanners.
    @rtype: List
    @return: List of device information present.
                For USB devices, get [busdir:devfilename, productString, serialNumber]
                For serial devices, get [serialFileName, deviceDescription, ""]
    '''
    global usbVendorList, usbProductList, gps_devstring
    if gps is not None and gps_devstring is None:
        gps_devstring = gps
    devlist = []

    if USBVER == 0:
        devlist = devlist_usb_v0x(vendor, product)
    elif USBVER == 1:
        devlist = devlist_usb_v1x(vendor, product)

    for serialdev in get_serial_ports(include=include):
        if serialdev == gps_devstring:
            print("kbutils.devlist is skipping ignored/GPS device string {0}".format(serialdev)) #TODO remove debugging print
            continue
        elif (DEV_ENABLE_ZIGDUINO and iszigduino(serialdev)):
            devlist.append([serialdev, "Zigduino", ""])
        elif (DEV_ENABLE_FREAKDUINO and isfreakduino(serialdev)):
            #TODO maybe move support for freakduino into goodfetccspi subtype==?
            devlist.append([serialdev, "Dartmouth Freakduino", ""])
        else:
            gfccspi,subtype = isgoodfetccspi(serialdev)
            if gfccspi and subtype == 0:
                devlist.append([serialdev, "GoodFET TelosB/Tmote", ""])
            elif gfccspi and subtype == 1:
                devlist.append([serialdev, "GoodFET Api-Mote v1", ""])
            elif gfccspi and subtype == 2:
                devlist.append([serialdev, "GoodFET Api-Mote v2", ""])
            elif gfccspi:
                print("kbutils.devlist has an unknown type of GoodFET CCSPI device ({0}).".format(serialdev))

    if include is not None:
        # Ugly nested load, so we don't load this class when unneeded!
        import dev_sewio #use isSewio, getFirmwareVersion
        for ipaddr in filter(isIpAddr, include):
            if dev_sewio.isSewio(ipaddr):
                devlist.append([ipaddr, "Sewio Open-Sniffer v{0}".format(dev_sewio.getFirmwareVersion(ipaddr)), dev_sewio.getMacAddr(ipaddr)])
            #NOTE: Enumerations of other IP connected sniffers go here.
            else:
                print("kbutils.devlist has an unknown type of IP sniffer device ({0}).".format(ipaddr))
    
    return devlist
Example #2
0
def devlist(vendor=None, product=None, gps=None, include=None):
    '''
    Return device information for all present devices, 
    filtering if requested by vendor and/or product IDs on USB devices, and
    running device fingerprint functions on serial devices.
    @type gps: String
    @param gps: Optional serial device identifier for an attached GPS
        unit. If provided, or if global variable has previously been set, 
        KillerBee skips that device in device enumeration process.
    @type include: List of Strings
    @param include: Optional list of device handles to be appended to the 
        normally found devices. This is useful for providing IP addresses for
        remote scanners.
    @rtype: List
    @return: List of device information present.
                For USB devices, get [busdir:devfilename, productString, serialNumber]
                For serial devices, get [serialFileName, deviceDescription, ""]
    '''
    global usbVendorList, usbProductList, gps_devstring
    if gps is not None and gps_devstring is None:
        gps_devstring = gps
    devlist = []

    if USBVER == 0:
        devlist = devlist_usb_v0x(vendor, product)
    elif USBVER == 1:
        devlist = devlist_usb_v1x(vendor, product)

    for serialdev in get_serial_ports(include=include):
        if serialdev == gps_devstring:
            print("kbutils.devlist is skipping ignored/GPS device string {0}".format(serialdev)) #TODO remove debugging print
            continue
        elif (DEV_ENABLE_ZIGDUINO and iszigduino(serialdev)):
            devlist.append([serialdev, "Zigduino", ""])
        elif (DEV_ENABLE_FREAKDUINO and isfreakduino(serialdev)):
            #TODO maybe move support for freakduino into goodfetccspi subtype==?
            devlist.append([serialdev, "Dartmouth Freakduino", ""])
        else:
            gfccspi,subtype = isgoodfetccspi(serialdev)
            if gfccspi and subtype == 0:
                devlist.append([serialdev, "GoodFET TelosB/Tmote", ""])
            elif gfccspi and subtype == 1:
                devlist.append([serialdev, "GoodFET Api-Mote v1", ""])
            elif gfccspi and subtype == 2:
                devlist.append([serialdev, "GoodFET Api-Mote v2", ""])
            elif gfccspi:
                print("kbutils.devlist has an unknown type of GoodFET CCSPI device ({0}).".format(serialdev))

    if include is not None:
        # Ugly nested load, so we don't load this class when unneeded!
        import dev_sewio #use isSewio, getFirmwareVersion
        for ipaddr in filter(isIpAddr, include):
            if dev_sewio.isSewio(ipaddr):
                devlist.append([ipaddr, "Sewio Open-Sniffer v{0}".format(dev_sewio.getFirmwareVersion(ipaddr)), dev_sewio.getMacAddr(ipaddr)])
            #NOTE: Enumerations of other IP connected sniffers go here.
            else:
                print("kbutils.devlist has an unknown type of IP sniffer device ({0}).".format(ipaddr))
    
    return devlist
Example #3
0
    def __init__(self, device=None, datasource=None, gps=None):
        '''
        Instantiates the KillerBee class.

        @type device:   String
        @param device:  Device identifier, either USB vendor:product, serial device node, or IP address
        @type datasource: String
        @param datasource: A known datasource type that is used
        by dblog to record how the data was captured.
        @type gps: String
        @param gps: Optional serial device identifier for an attached GPS
            unit. If provided, or if global variable has previously been set, 
            KillerBee skips that device in initalization process.
        @return: None
        @rtype: None
        '''

        global gps_devstring
        if gps_devstring is None and gps is not None:
            gps_devstring = gps

        self.dev = None
        self.__bus = None
        self.driver = None

        # IP devices may be the most straightforward, and we aren't doing
        # discovery, just connecting to defined addresses, so we'll check
        # first to see if we have an IP address given as our device parameter.
        if (device is not None) and kbutils.isIpAddr(device):
            from dev_sewio import isSewio
            if isSewio(device):
                from dev_sewio import SEWIO
                self.driver = SEWIO(dev=device)  #give it the ip address
            else:
                del isSewio

        # Figure out a device is one is not set, trying USB devices next
        if self.driver is None:
            if device is None:
                result = kbutils.search_usb(None)
                if result != None:
                    if USBVER == 0:
                        (self.__bus, self.dev) = result
                    elif USBVER == 1:
                        #TODO remove self.__bus attribute, not needed in 1.x as all info in self.dev
                        self.dev = result
            # Recognize if device is provided in the USB format (like a 012:456 string):
            elif ":" in device:
                result = kbutils.search_usb(device)
                if result == None:
                    raise KBInterfaceError(
                        "Did not find a USB device matching %s." % device)
                else:
                    if USBVER == 0:
                        (self.__bus, self.dev) = result
                    elif USBVER == 1:
                        #TODO remove self.__bus attribute, not needed in 1.x as all info in self.dev
                        self.dev = result

            if self.dev is not None:
                if self.__device_is(RZ_USB_VEND_ID, RZ_USB_PROD_ID):
                    from dev_rzusbstick import RZUSBSTICK
                    self.driver = RZUSBSTICK(self.dev, self.__bus)
                elif self.__device_is(ZN_USB_VEND_ID, ZN_USB_PROD_ID):
                    raise KBInterfaceError(
                        "Zena firmware not yet implemented.")
                else:
                    raise KBInterfaceError(
                        "KillerBee doesn't know how to interact with USB device vendor=%04x, product=%04x."
                        .format(self.dev.idVendor, self.dev.idProduct))

        # Figure out a device from serial if one is not set
        #TODO be able to try more than one serial device here (merge with devlist code somehow)
#        if device == None:
#            seriallist = get_serial_ports()
#            if len(seriallist) > 0:
#                device = seriallist[0]

# If a USB device driver was not loaded, now we try serial devices
        if self.driver is None:
            # If no device was specified
            if device is None:
                glob_list = get_serial_ports()
                if len(glob_list) > 0:
                    #TODO be able to check other devices if this one is not correct
                    device = glob_list[0]
            # Recognize if device specified by serial string:
            if (device is not None) and kbutils.isSerialDeviceString(device):
                self.dev = device
                if (self.dev == gps_devstring):
                    pass
                elif (DEV_ENABLE_ZIGDUINO and kbutils.iszigduino(self.dev)):
                    from dev_zigduino import ZIGDUINO
                    self.driver = ZIGDUINO(self.dev)
                elif (DEV_ENABLE_FREAKDUINO
                      and kbutils.isfreakduino(self.dev)):
                    from dev_freakduino import FREAKDUINO
                    self.driver = FREAKDUINO(self.dev)
                else:
                    gfccspi, subtype = isgoodfetccspi(self.dev)
                    if gfccspi and subtype == 0:
                        from dev_telosb import TELOSB
                        self.driver = TELOSB(self.dev)
                    elif gfccspi and subtype == 1:
                        from dev_apimote import APIMOTE
                        self.driver = APIMOTE(self.dev, revision=1)
                    elif gfccspi and subtype == 2:
                        from dev_apimote import APIMOTE
                        self.driver = APIMOTE(self.dev, revision=2)
                    else:
                        raise KBInterfaceError(
                            "KillerBee doesn't know how to interact with serial device at '%s'."
                            % self.dev)
            # Otherwise unrecognized device string type was provided:
            else:
                raise KBInterfaceError(
                    "KillerBee doesn't understand device given by '%s'." %
                    device)

        # Start a connection to the remote packet logging server, if able:
        if datasource is not None:
            try:
                import dblog
                self.dblog = dblog.DBLogger(datasource)
            except Exception as e:
                warn("Error initializing DBLogger (%s)." % e)
                datasource = None  #give up nicely if error connecting, etc.
Example #4
0
    def __init__(self, device=None, datasource=None, gps=None):
        """
        Instantiates the KillerBee class.

        @type device:   String
        @param device:  Device identifier, either USB vendor:product, serial device node, or IP address
        @type datasource: String
        @param datasource: A known datasource type that is used
        by dblog to record how the data was captured.
        @type gps: String
        @param gps: Optional serial device identifier for an attached GPS
            unit. If provided, or if global variable has previously been set, 
            KillerBee skips that device in initalization process.
        @return: None
        @rtype: None
        """

        global gps_devstring
        if gps_devstring is None and gps is not None:
            gps_devstring = gps

        self.dev = None
        self.__bus = None
        self.driver = None

        # IP devices may be the most straightforward, and we aren't doing
        # discovery, just connecting to defined addresses, so we'll check
        # first to see if we have an IP address given as our device parameter.
        if (device is not None) and kbutils.isIpAddr(device):
            from dev_sewio import isSewio

            if isSewio(device):
                from dev_sewio import SEWIO

                self.driver = SEWIO(dev=device)  # give it the ip address
            else:
                del isSewio

        # Figure out a device is one is not set, trying USB devices next
        if self.driver is None:
            if device is None:
                result = kbutils.search_usb(None)
                if result != None:
                    if USBVER == 0:
                        (self.__bus, self.dev) = result
                    elif USBVER == 1:
                        # TODO remove self.__bus attribute, not needed in 1.x as all info in self.dev
                        self.dev = result
            # Recognize if device is provided in the USB format (like a 012:456 string):
            elif ":" in device:
                result = kbutils.search_usb(device)
                if result == None:
                    raise KBInterfaceError("Did not find a USB device matching %s." % device)
                else:
                    if USBVER == 0:
                        (self.__bus, self.dev) = result
                    elif USBVER == 1:
                        # TODO remove self.__bus attribute, not needed in 1.x as all info in self.dev
                        self.dev = result

            if self.dev is not None:
                if self.__device_is(RZ_USB_VEND_ID, RZ_USB_PROD_ID):
                    from dev_rzusbstick import RZUSBSTICK

                    self.driver = RZUSBSTICK(self.dev, self.__bus)
                elif self.__device_is(ZN_USB_VEND_ID, ZN_USB_PROD_ID):
                    raise KBInterfaceError("Zena firmware not yet implemented.")
                else:
                    raise KBInterfaceError(
                        "KillerBee doesn't know how to interact with USB device vendor=%04x, product=%04x.".format(
                            self.dev.idVendor, self.dev.idProduct
                        )
                    )

        # Figure out a device from serial if one is not set
        # TODO be able to try more than one serial device here (merge with devlist code somehow)
        #        if device == None:
        #            seriallist = get_serial_ports()
        #            if len(seriallist) > 0:
        #                device = seriallist[0]

        # If a USB device driver was not loaded, now we try serial devices
        if self.driver is None:
            # If no device was specified
            if device is None:
                glob_list = get_serial_ports()
                if len(glob_list) > 0:
                    # TODO be able to check other devices if this one is not correct
                    device = glob_list[0]
            # Recognize if device specified by serial string:
            if (device is not None) and kbutils.isSerialDeviceString(device):
                self.dev = device
                if self.dev == gps_devstring:
                    pass
                elif DEV_ENABLE_ZIGDUINO and kbutils.iszigduino(self.dev):
                    from dev_zigduino import ZIGDUINO

                    self.driver = ZIGDUINO(self.dev)
                elif DEV_ENABLE_FREAKDUINO and kbutils.isfreakduino(self.dev):
                    from dev_freakduino import FREAKDUINO

                    self.driver = FREAKDUINO(self.dev)
                else:
                    gfccspi, subtype = isgoodfetccspi(self.dev)
                    if gfccspi and subtype == 0:
                        from dev_telosb import TELOSB

                        self.driver = TELOSB(self.dev)
                    elif gfccspi and subtype == 1:
                        from dev_apimote import APIMOTE

                        self.driver = APIMOTE(self.dev, revision=1)
                    elif gfccspi and subtype == 2:
                        from dev_apimote import APIMOTE

                        self.driver = APIMOTE(self.dev, revision=2)
                    else:
                        raise KBInterfaceError(
                            "KillerBee doesn't know how to interact with serial device at '%s'." % self.dev
                        )
            # Otherwise unrecognized device string type was provided:
            else:
                raise KBInterfaceError("KillerBee doesn't understand device given by '%s'." % device)

        # Start a connection to the remote packet logging server, if able:
        if datasource is not None:
            try:
                import dblog

                self.dblog = dblog.DBLogger(datasource)
            except Exception as e:
                warn("Error initializing DBLogger (%s)." % e)
                datasource = None  # give up nicely if error connecting, etc.