Ejemplo n.º 1
0
 def __init__(self):
     with shelve.open(get_cache_path() + '/config.db',
                      writeback=True) as db:
         if ("config" in db):
             self.config = db["config"]
         else:
             self.config = self.getDefaultConfig()
     logging.info("restored config: " + str(self.config))
Ejemplo n.º 2
0
    def __init__(self):
        self.library_path = get_cache_path() + '/database.db'

        if not os.path.exists(self.library_path):
            logging.info("[*] creating new database")
            self.initialize_db(self.library_path)

        logging.info("database can be found at " + self.library_path)
        logging.info(str(self.get_basic_device_list()))
Ejemplo n.º 3
0
 def __init__(self):
     with shelve.open(get_cache_path() + '/device.db',
                      writeback=True) as db:
         if ("devices" in db):
             self.device_list = db["devices"]
         else:
             self.device_list = []
         if ("history" in db):
             self.history = db["history"]
         else:
             self.history = []
     logging.info("restored device list: " + str(self.device_list))
Ejemplo n.º 4
0
    def sniff_devices(self, device_list, timeout):
        """
        Perform ARP-poisoning to a set of devices and capture their traffic
        :param device_list: list of devices to monitor
        :param timeout: number of seconds to sniff
        :return: the captured packages
        """

        packets = []
        self.p_count = {}

        gateway_ip = self.get_default_gateway()
        gateway_mac = self.get_mac(gateway_ip)
        if gateway_mac is None:
            logging.info("[!] Unable to get gateway MAC address. Exiting..")
        else:
            logging.info("[*] Gateway MAC address: " + "XX:XX:XX:XX:XX:XX")

        # ARP poison thread
        self.still_poisoning = True
        for device in device_list:
            self.p_count[device["ip"]] = {}
            poison_thread = threading.Thread(target=self.arp_poison,
                                             args=(gateway_ip, gateway_mac,
                                                   device["ip"]),
                                             name="ARP poison")
            poison_thread.start()

        # Sniff traffic and write to file. Capture is filtered on target machine
        ips = map(lambda x: "ip host " + x["ip"], device_list)
        sniff_filter = " or ".join(ips)
        logging.info("[*] Starting network capture.")
        #TODO: think about reintroducing filter
        logging.info("[*] Timeout:" + str(timeout))
        packets = sniff(iface=conf.iface, timeout=timeout)
        wrpcap(get_cache_path() + "/full_capture.pcap", packets)
        logging.info("[*] Stopping network capture..Restoring network")
        self.still_poisoning = False
        for device in device_list:
            self.restore_network(gateway_ip, gateway_mac, device["ip"],
                                 device["mac"])
        return packets
Ejemplo n.º 5
0
 def save_scan_result(self, scan_result):
     self.history.append(scan_result)
     with shelve.open(get_cache_path() + '/device.db',
                      writeback=True) as db:
         db["history"] = self.history
Ejemplo n.º 6
0
 def save_device_list(self):
     with shelve.open(get_cache_path() + '/device.db',
                      writeback=True) as db:
         db["devices"] = self.device_list