def startListener(self): p = pcap.pcapObject() p.open_live(self.getInterfaceName(), 1600, 0, 100) out.verbose("legitHost listener started") try: while True: p.dispatch(1, self.handlePackets) except KeyboardInterrupt: out.error("Got keyboard interrupt.") self.stop()
def loadModule(self, name): try: f, pathname, desc = imp.find_module(name, [self.mod_dir]) except ImportError: out.error("Couldn't find %s module." % name) self.stop() lm = imp.load_source(name, pathname) module = [x for x in getmembers(lm) if x[0] == name][0][1] out.debug("loaded module %s" % name, 0) self.addModule(module)
def __init__(self, ifacename, modules): self.mod_dir = 'modules' self.modules = list() self.interface = None # Get interface to use for iface in pcap.findalldevs(): if ifacename == iface[0]: self.interface = iface break if not self.interface: out.error("Can't find %s interface. Priveleges ?" % ifacename) self.stop() # Load modules self.loadModules(modules)
#! /usr/bin/env python import imp import os import argparse from inspect import getmembers from output import out from utils import ip_to_bin, get_mac try: import pcap except: out.error("pylibpcap not found.") out.error("$sudo pip install pylibpcap.") out.error("Exiting.") exit() try: import dpkt except: out.error("dpkt not found.") out.error("$sudo pip install dpkt.") out.error("Exiting.") exit() class LegitHost: def __init__(self, ifacename, modules, listen=False): self.mod_dir = 'modules' self.modules = list() self.interface = None self.listen = listen