From 03509d436e4b8611f21b9dd78e9f824a5ea57ffb Mon Sep 17 00:00:00 2001 From: derv82 Date: Thu, 28 May 2015 19:36:58 -0700 Subject: [PATCH] "Scanner" allow selection of targets Made Configuration static so it can be called from anywhere. Thing's awesome, yo. --- py/Airodump.py | 18 ++++++++-- py/Configuration.py | 25 ++++++++++---- py/Scanner.py | 83 +++++++++++++++++++++++++++++++++++++++++++++ py/Target.py | 6 ++-- py/Wash.py | 5 +++ 5 files changed, 125 insertions(+), 12 deletions(-) create mode 100644 py/Scanner.py diff --git a/py/Airodump.py b/py/Airodump.py index 4518bff..599d3d2 100644 --- a/py/Airodump.py +++ b/py/Airodump.py @@ -11,11 +11,23 @@ import os class Airodump(object): ''' Wrapper around airodump-ng program ''' - def __init__(self, interface, channel=None, encryption=None, wps=False): + def __init__(self, interface=None, channel=None, encryption=None, wps=False): ''' Constructor, sets things up ''' - self.targets = [] + + Configuration.initialize() + + if interface == None: + interface = Configuration.interface + if interface == None: + raise Exception("Interface must be defined") self.interface = interface + + self.targets = [] + + if channel == None: + channel = Configuration.target_channel self.channel = channel + self.encryption = encryption self.wps = wps @@ -144,7 +156,7 @@ class Airodump(object): if __name__ == '__main__': ''' Example usage. wlan0mon should be in Monitor Mode ''' - with Airodump('wlan0mon', channel=6) as airodump: + with Airodump() as airodump: from time import sleep sleep(7) diff --git a/py/Configuration.py b/py/Configuration.py index fc5fd78..a941e08 100644 --- a/py/Configuration.py +++ b/py/Configuration.py @@ -5,11 +5,20 @@ import os class Configuration(object): ''' Stores configuration variables for Wifite. ''' - temp_dir = None + initialized = False # Flag indicating config has been initialized + temp_dir = None # Temporary directory @staticmethod def initialize(): - ''' Sets up default initial configuration values ''' + ''' + Sets up default initial configuration values. + Also sets config values based on command-line arguments. + ''' + + # Only initialize this class once + if Configuration.initialized: + return + Configuration.initialized = True Configuration.version = 2.00 # Program version Configuration.tx_power = 0 # Wifi transmit power (0 is default) @@ -54,9 +63,14 @@ class Configuration(object): Configuration.wps_timeout = 600 # Seconds to wait before failing Configuration.wps_max_retries = 20 # Retries before failing + # Overwrite config values with arguments (if defined) + Configuration.load_from_arguments() + @staticmethod - def load_from_arguments(args): + def load_from_arguments(): + from Arguments import Arguments + args = Arguments().args ''' Sets configuration values based on Argument.args object ''' if args.channel: Configuration.target_channel = args.channel if args.interface: Configuration.interface = args.interface @@ -104,7 +118,7 @@ class Configuration(object): ''' (Colorful) string representation of the configuration ''' from Color import Color - max_len = 0 + max_len = 20 for key in Configuration.__dict__.keys(): max_len = max(max_len, len(key)) @@ -120,8 +134,5 @@ class Configuration(object): if __name__ == '__main__': Configuration.initialize() - from Arguments import Arguments - a = Arguments() - Configuration.load_from_arguments(a.args) print Configuration.dump() diff --git a/py/Scanner.py b/py/Scanner.py new file mode 100644 index 0000000..aab4524 --- /dev/null +++ b/py/Scanner.py @@ -0,0 +1,83 @@ +#!/usr/bin/python + +from Airodump import Airodump +from Color import Color +from Target import Target +from Configuration import Configuration + +from time import sleep + +class Scanner(object): + ''' Scans wifi networks & provides menu for selecting targets ''' + + # Console code for moving up one line + UP_CHAR = '\x1B[1F' + + def __init__(self): + ''' + Starts scan, prints as it goes. + Upon interrupt, sets 'targets'. + ''' + self.previous_target_count = 0 + self.targets = [] + # Loads airodump with interface/channel/etc from Configuration + with Airodump() as airodump: + try: + while True: + client_count = sum([len(t.clients) for t in self.targets]) + Color.p("\r {+} Scanning, found {G}%d{W} target(s), {G}%d{W} clients" % (len(self.targets), client_count)) + sleep(1) + self.targets = airodump.get_targets() + self.print_targets() + except KeyboardInterrupt: + pass + + + def print_targets(self): + ''' + Prints targets to console + ''' + if len(self.targets) == 0: + return + + if self.previous_target_count > 0: + # "Move" cursor up so we will print over the previous list + print Scanner.UP_CHAR * (3 + self.previous_target_count) + + self.previous_target_count = len(self.targets) + + # Overwrite the current line + Color.p('\r') + + Target.print_header() + for (index, target) in enumerate(self.targets): + index += 1 + Color.pl(' {G}%s %s' % (str(index).rjust(3), target)) + + def select_targets(self): + ''' Asks user to select target(s) ''' + self.print_targets() + input_str = '{+} Select target(s)' + input_str += ' ({G}1-%d{W})' % len(self.targets) + input_str += ' separated by commas, or {G}all{W}: ' + + chosen_targets = [] + for choice in raw_input(Color.s(input_str)).split(','): + if '-' in choice: + # User selected a range + (lower,upper) = [int(x) - 1 for x in choice.split('-')] + for i in xrange(lower, upper): + chosen_targets.append(self.targets[i]) + else: + choice = int(choice) - 1 + chosen_targets.append(self.targets[choice]) + return chosen_targets + + +if __name__ == '__main__': + # Example displays targets and selects the appropriate one + s = Scanner() + targets = s.select_targets() + for t in targets: + Color.p("{W}Selected: ") + print t diff --git a/py/Target.py b/py/Target.py index f246ca0..d7f692b 100644 --- a/py/Target.py +++ b/py/Target.py @@ -55,7 +55,7 @@ class Target(object): self.essid = '(%s)' % self.bssid self.essid_known = False - self.wps = False + self.wps = None self.clients = [] @@ -100,9 +100,11 @@ class Target(object): color = 'R' power = Color.s('{%s}%s' % (color, power)) - wps = Color.s('{R} no') + wps = Color.s('{O} n/a') if self.wps: wps = Color.s('{G} yes') + else: + wps = Color.s('{R} no') clients = ' ' if len(self.clients) == 1: diff --git a/py/Wash.py b/py/Wash.py index 751f06c..ef20fe4 100644 --- a/py/Wash.py +++ b/py/Wash.py @@ -43,6 +43,11 @@ class Wash(object): # Update the WPS flag t.wps = True + # Mark other targets as "no" wps support + for t in targets: + if t.wps: continue + t.wps = False + if __name__ == '__main__': from Target import Target