Example #1
0
def main():
    options = parse_options()

    if options.verbose:
        logging.basicConfig(level=logging.DEBUG)

    parser = DiagParser(options)

    def print_interfaces():
        print("[*] Available interfaces:")
        for iface in get_if_list():
            print("[ ]\t%s (%s)" % (iface, get_if_addr(iface)))

    if not (options.interface or options.pcap):
        print("[*] Must provide a pcap file or an interface to sniff on")
        print_interfaces()
        return

    if options.pcap:
        print("[*] Parsing pcap file (%s)" % options.pcap)
    else:
        if options.interface not in get_if_list():
            print("[*] Invalid interface '%s'" % options.interface)
            print_interfaces()
            return
        print("[*] Listening on interface (%s)" % options.interface)

    try:
        sniff(iface=options.interface, offline=options.pcap, prn=parser.parse_packet, store=0)
    except KeyboardInterrupt:
        pass

    print("[*] Finished parsing/sniffing")
    parser.reassemble()
Example #2
0
    def interface(self, interface):
        # If interface does not exist.
        if interface not in get_if_list():
            raise InterfaceDoesNotExistException(
                f"Interface {interface} does not exist")

        self._interface = interface
Example #3
0
def main():
    options = parse_options()

    if options.verbose:
        logging.basicConfig(level=logging.DEBUG)

    parser = DiagParser(options)

    def print_interfaces():
        print("[*] Available interfaces:")
        for iface in get_if_list():
            print("[ ]\t%s (%s)" % (iface, get_if_addr(iface)))

    if not (options.interface or options.pcap):
        print("[*] Must provide a pcap file or an interface to sniff on")
        print_interfaces()
        return

    if options.pcap:
        print("[*] Parsing pcap file (%s)" % options.pcap)
    else:
        if options.interface not in get_if_list():
            print("[*] Invalid interface '%s'" % options.interface)
            print_interfaces()
            return
        print("[*] Listening on interface (%s)" % options.interface)

    try:
        sniff(iface=options.interface, offline=options.pcap, prn=parser.parse_packet, store=0)
    except KeyboardInterrupt:
        pass

    print("[*] Finished parsing/sniffing")
    parser.reassemble()
Example #4
0
def return_interfaces():
    win_list = get_windows_if_list()
    intf_list = get_if_list()

    # Pull guids and names from the windows list
    guid_to_name_dict = {e["guid"]: e["name"] for e in win_list}

    # Extract the guids from the interface listEth
    guids_from_intf_list = [(e.split("_"))[1] for e in intf_list]

    # Using the interface list of guids, pull the names from the
    # Windows map of guids to names
    names_allowed_list = [
        guid_to_name_dict.get(e) for e in guids_from_intf_list
    ]
    print(names_allowed_list)
Example #5
0
    def run(self):
        self.ipdb.register_callback(self.callback, )

        self.log.info("Welcome to py-pingu! ")
        self.log.info(json.dumps(self.configuration, indent=2))
        self.route_monitor.start()

        signal.signal(signal.SIGINT, self.on_sigint)
        signal.signal(signal.SIGUSR1, self.print_fetched_gws)

        self.load_route_table()

        self.load_next_checks()

        while not self.exited.is_set():

            name, period = self.fetch_next_interface()

            if period > 0:
                if self.loop_event.wait(timeout=period):
                    self.loop_event.clear()
                    continue

            try:
                self.log.debug("Probing %s" % name)
                ifaces = get_if_list()

                if name not in ifaces:
                    self.log.debug("Interface %s does not exists." % name)
                    continue

                self.run_on_interface(name)

            except Exception as ex:
                self.log.exception("Error in main loop:", exc_info=True)
            finally:
                self.next_check_timestamps[
                    name] = self.get_interface_next_check(name)

        self.log.info("Exit signal received")
Example #6
0
 def print_interfaces():
     print("[*] Available interfaces:")
     for iface in get_if_list():
         print("[ ]\t%s (%s)" % (iface, get_if_addr(iface)))
Example #7
0
	def validate_iface_name(name):
		if name not in get_if_list():
			raise EnvironmentError("Could not find interface %s" % name)
Example #8
0
def setup():
    print('On which interfaces would you like to discover and attack?')
    interfaces = get_if_list()
    powerset_interfaces = powerset(interfaces)
    chosen = let_user_pick_options(powerset_interfaces, True)
    settings['chosen interfaces'] = powerset_interfaces[chosen]
    if len(settings['chosen interfaces']) == 0:
        return

    print('How long would you like to discover hosts initially?')
    print('Recommended: ' + str(settings['initial discovery time']))
    settings['initial discovery time'] = let_user_input_number(True)

    # Start passive discovery
    print('Started passive network discovery ...')
    main_lock.acquire()
    for interface in settings['chosen interfaces']:
        thread = Thread(target=discover.passive, args=(interface, settings))
        thread.daemon = True
        thread.start()
        settings['passive discover threads'].add(thread)
    main_lock.release()

    sleep(settings['initial discovery time'])
    settings['currently discovering'] = False
    sleep(2)

    print('Would you like to ARP poison all hosts?')
    chosen = let_user_pick_options(['yes', 'no'], True)
    if chosen == 0:
        print('Would you like to continue host discovery while poisoning?')
        chosen2 = let_user_pick_options(['yes', 'no'], True)
        if chosen2 == 0:
            settings['continue discovery during poisoning'] = True
    elif chosen == 1:
        print(
            'Would you like to whitelist hosts or select hosts to be attacked?'
        )
        chosen2 = let_user_pick_options(
            ['whitelist hosts', 'select hosts to be attacked'], True)
        if chosen2 == 0:
            for interface in settings['chosen interfaces']:
                if len(settings['hosts'][interface].keys()) > 0:
                    print('Which hosts would you like to whitelist on ' +
                          interface + '?')
                    powerset_hosts_interface = powerset(
                        settings['hosts'][interface].keys())
                    settings['whitelist poisoned hosts'][
                        interface] = powerset_hosts_interface[
                            let_user_pick_options(powerset_hosts_interface,
                                                  True)]
        elif chosen2 == 1:
            for interface in settings['chosen interfaces']:
                if len(settings['hosts'][interface].keys()) > 0:
                    print('Which hosts would you like to attack on ' +
                          interface + '?')
                    powerset_hosts_interface = powerset(
                        settings['hosts'][interface].keys())
                    settings['hosts'][interface] = powerset_hosts_interface[
                        let_user_pick_options(powerset_hosts_interface, True)]
        elif chosen2 is None:
            return
    elif chosen is None:
        return

    print('At what frequency would you like to ARP poison hosts?')
    print('Recommended: ' + str(settings['arp poison frequency']))
    settings['arp poison frequency'] = let_user_input_number(True)

    print('Which intercepted packages would you like to forward?')
    chosen = let_user_pick_options([
        'all',
        'all, except non-spoofed DNS answers that correspond to a spoofed domain',
        'none'
    ], True)
    if chosen == 0:
        settings['forward'] = 'all'
    if chosen == 1:
        settings['forward'] = 'all-except'

    print(
        'Would you like to restore ARP caches when the attack is broken off?')
    chosen = let_user_pick_options(['yes', 'no'], True)
    if chosen == 1:
        settings['restore arp cache'] = False

    print('Would you like to spoof all domains with DNS poisoning?')
    chosen = let_user_pick_options(['yes', 'no'], True)
    if chosen == 1:
        print(
            'Would you like to whitelist domains or select domains to be spoofed?'
        )
        chosen2 = let_user_pick_options(
            ['whitelist domains', 'select domains to be spoofed'], True)
        if chosen2 == 0:
            print('Which domain names would you like to whitelist?')
            print('You can enter multiple domains ony by one.')
            domain = let_user_input_domain(True)
            while domain is not None:
                settings['whitelist spoofed domains'].add(domain)
                domain = let_user_input_domain(False)
        elif chosen2 == 1:
            settings['spoof all domains'] = False
            print('Which domain names would you like to spoof?')
            print(
                'You can enter multiple domains ony by one or enter no domains at all.'
            )
            domain = let_user_input_domain(False)
            while domain is not None:
                settings['spoofed domains'].add(domain)
                domain = let_user_input_domain(False)

    if settings['spoof all domains'] or len(settings['spoofed domains']) > 0:
        print('To which IP would you like to redirect spoofed domains?')
        settings['redirect spoofed domains to'] = let_user_input_ip(True)

    if settings['continue discovery during poisoning']:
        settings['currently discovering'] = True

    # Start continuous poisoning
    print('Started initial poisoning ...')
    for interface in settings['chosen interfaces']:
        thread = Thread(target=forward.forward, args=(interface, settings))
        thread.daemon = True
        thread.start()
        settings['forward threads'].add(thread)

        thread = Thread(target=arp.poison, args=(interface, settings))
        thread.daemon = True
        thread.start()
        settings['arp poison threads'].add(thread)

        if settings['spoof all domains'] or len(
                settings['spoofed domains']) > 0:
            thread = Thread(target=dns.spoof, args=(interface, settings))
            thread.daemon = True
            thread.start()
            settings['dns spoof threads'].add(thread)
        sleep(settings['arp poison frequency'] /
              len(settings['chosen interfaces']))

    # Wait for keyboard interrupt
    while True:
        sleep(1)
Example #9
0
 def print_interfaces():
     print("[*] Available interfaces:")
     for iface in get_if_list():
         print("[ ]\t%s (%s)" % (iface, get_if_addr(iface)))