示例#1
0
def handle(mac, addresses, iface):
    if mac in _HOSTS:
        logging.debug("Ignoring already managed TCP host {}" .format (mac, ))

    logging.info("Now handling TCP SYNs for {}:{} on {}".format (mac, addresses, iface))

    for address in addresses:
        #we can be fancier, wake on port 22 with plain packets, not just syn
        #http://www.opensource.apple.com/source/mDNSResponder/mDNSResponder-522.1.11/mDNSCore/mDNS.c mDNSCoreReceiveRawTransportPacket()
        if ':' in address: #ipv6
            expr = "ip6[6]=6 && ip6[53]&4!=0 and ip6[6]=6 && ip6[53]&1=0 and dst host {}".format(address) #ipv6 can have multiple headers, so no tcp* shortcuts in pcap-filter
        else:
            expr = "tcp[tcpflags] & tcp-syn != 0 and tcp[tcpflags] & tcp-ack = 0 and dst host {}".format(address)
        thread = SnifferThread( filterexp=expr, prn=partial(_handle_packet, mac, address), iface=iface) #using a callback, but nut not doing it async
        _HOSTS[mac] = thread
        thread.start() #make this a greenlet?
示例#2
0
def handle(othermac, addresses, mymac, iface):
    print 'Pretending to handle arp for %s on %s' % (addresses, iface)

    if othermac in _HOSTS:
        print "I already seem to be managing %s, ignoring"
        return

    for address in addresses:
        if ':' in address:
            # TODO: Handle IP6
            continue
        thread = SnifferThread(
            filterexp="arp host %s" % (address, ),
            prn=partial(_handle_packet, address, mymac),
            iface=iface,
        )
        _HOSTS[othermac] = thread
        thread.start()
示例#3
0
def handle(mac, addresses, iface):
    print "Pretending to handle incoming SYN for %s: %s" % (mac, addresses, )

    if mac in _HOSTS:
        print "Ignoring already managed host %s" % (mac, )

    for address in addresses:
        if ':' in address:
            # TODO: Handle IP6
            continue
        print 'Starting TCP sniffer for %s' % (address, )
        thread = SnifferThread(
            filterexp="tcp[tcpflags] & tcp-syn != 0 and tcp[tcpflags] & tcp-ack = 0 and dst host %s" % (address, ),
            prn=partial(_handle_packet, mac, address),
            iface=iface,
        )
        _HOSTS[mac] = thread
        thread.start()
示例#4
0
def handle(othermac, addresses, mymac, iface):
    if othermac in _HOSTS:
        logging.info("I already seem to be managing %s, ignoring" % othermac)
        return
    logging.info('Now handling ARPs for %s:%s on %s' %
                 (othermac, addresses, iface))

    for address in addresses:
        if ':' in address:  #ipv6
            expr = "ip6 && icmp6 && (ip6[40] == 135 || ip6[40] == 136) and host %s" % (
                address)  #ipv6 uses ndp, not arp
        else:
            expr = "arp host %s" % (address)
        thread = SnifferThread(
            filterexp=expr,
            prn=partial(_handle_packet, address, mymac, othermac),
            iface=iface,
        )  #using a callback, but not doing it async
        _HOSTS[othermac] = thread
        thread.start()  #make this a greenlet?