def _hosts_handler(self, args):
        """
        Handles 'hosts' command-line argument
        Displays discovered hosts
        """
        table_data = [[
            '{}ID{}'.format(IO.Style.BRIGHT, IO.Style.RESET_ALL),
            '{}IP-Address{}'.format(IO.Style.BRIGHT, IO.Style.RESET_ALL),
            '{}MAC-Address{}'.format(IO.Style.BRIGHT, IO.Style.RESET_ALL),
            '{}Hostname{}'.format(IO.Style.BRIGHT, IO.Style.RESET_ALL),
            '{}Status{}'.format(IO.Style.BRIGHT, IO.Style.RESET_ALL)
        ]]

        for i, host in enumerate(self.hosts):
            table_data.append([
                '{}{}{}'.format(IO.Fore.LIGHTYELLOW_EX, i, IO.Style.RESET_ALL),
                host.ip, host.mac, host.name if host.name is not None else '',
                host.pretty_status()
            ])

        table = SingleTable(table_data, 'Hosts')

        if not table.ok:
            IO.error(
                'table does not fit terminal. resize or decrease font size.')
            return

        IO.spacer()
        IO.print(table.table)
        IO.spacer()
示例#2
0
def run():
    """
    Main entry point of the application
    """
    version = get_version()
    args = parse_arguments()

    IO.initialize(args.colorless)
    IO.print(get_main_banner(version))

    if not is_linux():
        IO.error('run under linux.')
        return

    if not is_privileged():
        IO.error('run as root.')
        return

    args = process_arguments(args)

    if args is None:
        return
    
    if initialize(args.interface):
        IO.spacer()        
        menu = MainMenu(version, args.interface, args.gateway_ip, args.gateway_mac, args.netmask)
        menu.start()
        cleanup(args.interface)
示例#3
0
    def _hosts_handler(self, args):
        """
        Handles 'hosts' command-line argument
        Displays discovered hosts
        """
        table_data = [[
            '{}ID{}'.format(IO.Style.BRIGHT, IO.Style.RESET_ALL),
            '{}IP address{}'.format(IO.Style.BRIGHT, IO.Style.RESET_ALL),
            '{}MAC address{}'.format(IO.Style.BRIGHT, IO.Style.RESET_ALL),
            '{}Hostname{}'.format(IO.Style.BRIGHT, IO.Style.RESET_ALL),
            '{}Status{}'.format(IO.Style.BRIGHT, IO.Style.RESET_ALL)
        ]]

        with self.hosts_lock:
            for host in self.hosts:
                table_data.append([
                    '{}{}{}'.format(IO.Fore.LIGHTYELLOW_EX,
                                    self._get_host_id(host, lock=False),
                                    IO.Style.RESET_ALL), host.ip, host.mac,
                    host.name,
                    host.pretty_status()
                ])

        table = SingleTable(table_data, 'Hosts')

        if not args.force and not table.ok:
            IO.error(
                'table does not fit terminal. resize or decrease font size. you can also force the display (--force).'
            )
            return

        IO.spacer()
        IO.print(table.table)
        IO.spacer()
 def _clear_handler(self, args):
     """
     Handler for the 'clear' command-line argument
     Clears the terminal window and re-prints the banner
     """
     IO.clear()
     IO.print(get_main_banner(self.version))
     self._print_help_reminder()
示例#5
0
    def _help_handler(self, args):
        """
        Handles 'help' command-line argument
        Prints help message including commands and usage
        """
        spaces = ' ' * 35

        IO.print("""
{y}scan (--range [IP range]){r}{}scans for online hosts on your network.
{s}required to find the hosts you want to limit.
{b}{s}e.g.: scan
{s}      scan --range 192.168.178.1-192.168.178.50
{s}      scan --range 192.168.178.1/24{r}

{y}hosts (--force){r}{}lists all scanned hosts.
{s}contains host information, including IDs.

{y}limit [ID1,ID2,...] [rate]{r}{}limits bandwith of host(s) (uload/dload).
{y}      (--upload) (--download){r}{}{b}e.g.: limit 4 100kbit
{s}      limit 2,3,4 1gbit --download
{s}      limit all 200kbit --upload{r}

{y}block [ID1,ID2,...]{r}{}blocks internet access of host(s).
{y}      (--upload) (--download){r}{}{b}e.g.: block 3,2
{s}      block all --upload{r}

{y}free [ID1,ID2,...]{r}{}unlimits/unblocks host(s).
{b}{s}e.g.: free 3
{s}      free all{r}

{y}add [IP] (--mac [MAC]){r}{}adds custom host to host list.
{s}mac resolved automatically.
{b}{s}e.g.: add 192.168.178.24
{s}      add 192.168.1.50 --mac 1c:fc:bc:2d:a6:37{r}

{y}monitor (--interval [time in ms]){r}{}monitors bandwidth usage of limited hosts.
{b}{s}e.g.: monitor --interval 600{r}

{y}clear{r}{}clears the terminal window.

{y}quit{r}{}quits the application.
            """.format(spaces[len('scan (--range [IP range])'):],
                       spaces[len('hosts (--force)'):],
                       spaces[len('limit [ID1,ID2,...] [rate]'):],
                       spaces[len('      (--upload) (--download)'):],
                       spaces[len('block [ID1,ID2,...]'):],
                       spaces[len('      (--upload) (--download)'):],
                       spaces[len('free [ID1,ID2,...]'):],
                       spaces[len('add [IP] (--mac [MAC])'):],
                       spaces[len('monitor (--interval [time in ms])'):],
                       spaces[len('clear'):],
                       spaces[len('quit'):],
                       y=IO.Fore.LIGHTYELLOW_EX,
                       r=IO.Style.RESET_ALL,
                       b=IO.Style.BRIGHT,
                       s=spaces))
示例#6
0
    def _help_handler(self, args):
        """
        Handles 'help' command-line argument
        Prints help message including commands and usage
        """
        spaces = ' ' * 20

        IO.print("""
{y}scan{r}{}scans for online hosts on your network.
{s}required to find the hosts you want to limit.

{y}hosts{r}{}lists all scanned hosts.
{s}contains host information, including IDs.

{y}limit [ID] [rate]{r}{}limits bandwith of host (uload/dload).
{b}{s}e.g.: limit 4 100kbit
{s}      limit 2 1gbit
{s}      limit 5 500tbit{r}

{y}block [ID]{r}{}blocks internet access of host.
{b}{s}e.g.: block 3{r}

{y}free [ID]{r}{}unlimits/unblocks host.
{b}{s}e.g.: free 3{r}

{y}clear{r}{}clears the terminal window.
            """.format(spaces[len('scan'):],
                       spaces[len('hosts'):],
                       spaces[len('limit [ID] [rate]'):],
                       spaces[len('block [ID]'):],
                       spaces[len('free [ID]'):],
                       spaces[len('clear'):],
                       y=IO.Fore.LIGHTYELLOW_EX,
                       r=IO.Style.RESET_ALL,
                       b=IO.Style.BRIGHT,
                       s=spaces))
 def _print_help_reminder(self):
     IO.print(
         'type {Y}help{R} or {Y}?{R} to show command information.'.format(
             Y=IO.Fore.LIGHTYELLOW_EX, R=IO.Style.RESET_ALL))
示例#8
0
    def _help_handler(self, args):
        """
        Handles 'help' command-line argument
        Prints help message including commands and usage
        """
        spaces = ' ' * 35

        IO.print("""
{y}scan (--range [IP range]){r}{}scans for online hosts on your network.
{s}required to find the hosts you want to limit.
{b}{s}e.g.: scan
{s}      scan --range 192.168.178.1-192.168.178.50
{s}      scan --range 192.168.178.1/24{r}

{y}hosts (--force){r}{}lists all scanned hosts.
{s}contains host information, including IDs.

{y}auto [usage] [rate]{r}{}Limit bandwidth if host(s)
{y}     (--interval [time in ms]){r}{}reached maximum usage
{b}{s}e.g.: auto 1gbit 1mbit
{s}      auto 500mbit 200kbit --interval 600{r}

{y}limit [ID1,ID2,...] [rate]{r}{}limits bandwith of host(s) (uload/dload).
{y}      (--upload) (--download){r}{}{b}e.g.: limit 4 100kbit
{s}      limit 2,3,4 1gbit --download
{s}      limit all 200kbit --upload{r}

{y}block [ID1,ID2,...]{r}{}blocks internet access of host(s).
{y}      (--upload) (--download){r}{}{b}e.g.: block 3,2
{s}      block all --upload{r}

{y}free [ID1,ID2,...]{r}{}unlimits/unblocks host(s).
{b}{s}e.g.: free 3
{s}      free all{r}

{y}add [IP] (--mac [MAC]){r}{}adds custom host to host list.
{s}mac resolved automatically.
{b}{s}e.g.: add 192.168.178.24
{s}      add 192.168.1.50 --mac 1c:fc:bc:2d:a6:37{r}

{y}remove [ID1,ID2,...]{r}{}remove host(s) from list.
{b}{s}e.g.: remove 0,1
{s}      remove all{r} 

{y}monitor (--interval [time in ms]){r}{}monitors bandwidth usage of limited host(s).
{b}{s}e.g.: monitor --interval 600{r}

{y}analyze [ID1,ID2,...]{r}{}analyzes traffic of host(s) without limiting
{y}        (--duration [time in s]){r}{}to determine who uses how much bandwidth.
{b}{s}e.g.: analyze 2,3 --duration 120{r}

{y}watch{r}{}detects host reconnects with different IP.
{y}watch add [ID1,ID2,...]{r}{}adds host to the reconnection watchlist.
{b}{s}e.g.: watch add 3,4{r}
{y}watch remove [ID1,ID2,...]{r}{}removes host from the reconnection watchlist.
{b}{s}e.g.: watch remove all{r}
{y}watch set [attr] [value]{r}{}changes reconnect watch settings.
{b}{s}e.g.: watch set interval 120{r}

{y}clear{r}{}clears the terminal window.

{y}quit{r}{}quits the application.
            """.format(spaces[len('scan (--range [IP range])'):],
                       spaces[len('hosts (--force)'):],
                       spaces[len('auto [usage] [rate]'):],
                       spaces[len('     (--interval [time in ms])'):],
                       spaces[len('limit [ID1,ID2,...] [rate]'):],
                       spaces[len('      (--upload) (--download)'):],
                       spaces[len('block [ID1,ID2,...]'):],
                       spaces[len('      (--upload) (--download)'):],
                       spaces[len('free [ID1,ID2,...]'):],
                       spaces[len('add [IP] (--mac [MAC])'):],
                       spaces[len('remove [ID1,ID2,...]'):],
                       spaces[len('monitor (--interval [time in ms])'):],
                       spaces[len('analyze [ID1,ID2,...]'):],
                       spaces[len('        (--duration [time in s])'):],
                       spaces[len('watch'):],
                       spaces[len('watch add [ID1,ID2,...]'):],
                       spaces[len('watch remove [ID1,ID2,...]'):],
                       spaces[len('watch set [attr] [value]'):],
                       spaces[len('clear'):],
                       spaces[len('quit'):],
                       y=IO.Fore.LIGHTYELLOW_EX,
                       r=IO.Style.RESET_ALL,
                       b=IO.Style.BRIGHT,
                       s=spaces))
示例#9
0
    def _watch_handler(self, args):
        if len(args) == 0:
            watch_table_data = [[
                '{}ID{}'.format(IO.Style.BRIGHT, IO.Style.RESET_ALL),
                '{}IP address{}'.format(IO.Style.BRIGHT, IO.Style.RESET_ALL),
                '{}MAC address{}'.format(IO.Style.BRIGHT, IO.Style.RESET_ALL)
            ]]

            set_table_data = [[
                '{}Attribute{}'.format(IO.Style.BRIGHT, IO.Style.RESET_ALL),
                '{}Value{}'.format(IO.Style.BRIGHT, IO.Style.RESET_ALL)
            ]]

            hist_table_data = [[
                '{}ID{}'.format(IO.Style.BRIGHT, IO.Style.RESET_ALL),
                '{}Old IP address{}'.format(IO.Style.BRIGHT,
                                            IO.Style.RESET_ALL),
                '{}New IP address{}'.format(IO.Style.BRIGHT,
                                            IO.Style.RESET_ALL),
                '{}Time{}'.format(IO.Style.BRIGHT, IO.Style.RESET_ALL)
            ]]

            iprange = self.host_watcher.iprange
            interval = self.host_watcher.interval

            set_table_data.append([
                '{}range{}'.format(IO.Fore.LIGHTYELLOW_EX, IO.Style.RESET_ALL),
                '{} addresses'.format(len(iprange))
                if iprange is not None else 'default'
            ])

            set_table_data.append([
                '{}interval{}'.format(IO.Fore.LIGHTYELLOW_EX,
                                      IO.Style.RESET_ALL),
                '{}s'.format(interval)
            ])

            for host in self.host_watcher.hosts:
                watch_table_data.append([
                    '{}{}{}'.format(IO.Fore.LIGHTYELLOW_EX,
                                    self._get_host_id(host),
                                    IO.Style.RESET_ALL), host.ip, host.mac
                ])

            for recon in self.host_watcher.log_list:
                hist_table_data.append([
                    recon['old'].mac, recon['old'].ip, recon['new'].ip,
                    recon['time']
                ])

            watch_table = SingleTable(watch_table_data, "Watchlist")
            set_table = SingleTable(set_table_data, "Settings")
            hist_table = SingleTable(hist_table_data, 'Reconnection History')

            IO.spacer()
            IO.print(watch_table.table)
            IO.spacer()
            IO.print(set_table.table)
            IO.spacer()
            IO.print(hist_table.table)
            IO.spacer()
示例#10
0
    def _analyze_handler(self, args):
        hosts = self._get_hosts_by_ids(args.id)
        if hosts is None or len(hosts) == 0:
            IO.error('no hosts to be analyzed.')
            return

        duration = 30  # in s
        if args.duration:
            if not args.duration.isdigit():
                IO.error('invalid duration.')
                return

            duration = int(args.duration)

        hosts_to_be_freed = set()
        host_values = {}

        for host in hosts:
            if not host.spoofed:
                hosts_to_be_freed.add(host)

            self.arp_spoofer.add(host)
            self.bandwidth_monitor.add(host)

            host_result = self.bandwidth_monitor.get(host)
            host_values[host] = {}
            host_values[host]['prev'] = (host_result.upload_total_size,
                                         host_result.download_total_size)

        IO.ok('analyzing traffic for {}s.'.format(duration))
        time.sleep(duration)

        error_occurred = False
        for host in hosts:
            host_result = self.bandwidth_monitor.get(host)

            if host_result is None:
                # host reconnected during analysis
                IO.error('host reconnected during analysis.')
                error_occurred = True
            else:
                host_values[host]['current'] = (
                    host_result.upload_total_size,
                    host_result.download_total_size)

        IO.ok('cleaning up...')
        for host in hosts_to_be_freed:
            self._free_host(host)

        if error_occurred:
            return

        upload_chart = BarChart(max_bar_length=29)
        download_chart = BarChart(max_bar_length=29)

        for host in hosts:
            upload_value = host_values[host]['current'][0] - host_values[host][
                'prev'][0]
            download_value = host_values[host]['current'][1] - host_values[
                host]['prev'][1]

            prefix = '{}{}{} ({}, {})'.format(IO.Fore.LIGHTYELLOW_EX,
                                              self._get_host_id(host),
                                              IO.Style.RESET_ALL, host.ip,
                                              host.name)

            upload_chart.add_value(upload_value.value, prefix, upload_value)
            download_chart.add_value(download_value.value, prefix,
                                     download_value)

        upload_table = SingleTable([[upload_chart.get()]], 'Upload')
        download_table = SingleTable([[download_chart.get()]], 'Download')

        upload_table.inner_heading_row_border = False
        download_table.inner_heading_row_border = False

        IO.spacer()
        IO.print(upload_table.table)
        IO.print(download_table.table)
        IO.spacer()