"Scanner" allow selection of targets
Made Configuration static so it can be called from anywhere. Thing's awesome, yo.
This commit is contained in:
@@ -11,11 +11,23 @@ import os
|
|||||||
class Airodump(object):
|
class Airodump(object):
|
||||||
''' Wrapper around airodump-ng program '''
|
''' 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 '''
|
''' 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.interface = interface
|
||||||
|
|
||||||
|
self.targets = []
|
||||||
|
|
||||||
|
if channel == None:
|
||||||
|
channel = Configuration.target_channel
|
||||||
self.channel = channel
|
self.channel = channel
|
||||||
|
|
||||||
self.encryption = encryption
|
self.encryption = encryption
|
||||||
self.wps = wps
|
self.wps = wps
|
||||||
|
|
||||||
@@ -144,7 +156,7 @@ class Airodump(object):
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
''' Example usage. wlan0mon should be in Monitor Mode '''
|
''' Example usage. wlan0mon should be in Monitor Mode '''
|
||||||
with Airodump('wlan0mon', channel=6) as airodump:
|
with Airodump() as airodump:
|
||||||
|
|
||||||
from time import sleep
|
from time import sleep
|
||||||
sleep(7)
|
sleep(7)
|
||||||
|
|||||||
@@ -5,11 +5,20 @@ import os
|
|||||||
class Configuration(object):
|
class Configuration(object):
|
||||||
''' Stores configuration variables for Wifite. '''
|
''' Stores configuration variables for Wifite. '''
|
||||||
|
|
||||||
temp_dir = None
|
initialized = False # Flag indicating config has been initialized
|
||||||
|
temp_dir = None # Temporary directory
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def initialize():
|
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.version = 2.00 # Program version
|
||||||
Configuration.tx_power = 0 # Wifi transmit power (0 is default)
|
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_timeout = 600 # Seconds to wait before failing
|
||||||
Configuration.wps_max_retries = 20 # Retries before failing
|
Configuration.wps_max_retries = 20 # Retries before failing
|
||||||
|
|
||||||
|
# Overwrite config values with arguments (if defined)
|
||||||
|
Configuration.load_from_arguments()
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@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 '''
|
''' Sets configuration values based on Argument.args object '''
|
||||||
if args.channel: Configuration.target_channel = args.channel
|
if args.channel: Configuration.target_channel = args.channel
|
||||||
if args.interface: Configuration.interface = args.interface
|
if args.interface: Configuration.interface = args.interface
|
||||||
@@ -104,7 +118,7 @@ class Configuration(object):
|
|||||||
''' (Colorful) string representation of the configuration '''
|
''' (Colorful) string representation of the configuration '''
|
||||||
from Color import Color
|
from Color import Color
|
||||||
|
|
||||||
max_len = 0
|
max_len = 20
|
||||||
for key in Configuration.__dict__.keys():
|
for key in Configuration.__dict__.keys():
|
||||||
max_len = max(max_len, len(key))
|
max_len = max(max_len, len(key))
|
||||||
|
|
||||||
@@ -120,8 +134,5 @@ class Configuration(object):
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
Configuration.initialize()
|
Configuration.initialize()
|
||||||
from Arguments import Arguments
|
|
||||||
a = Arguments()
|
|
||||||
Configuration.load_from_arguments(a.args)
|
|
||||||
print Configuration.dump()
|
print Configuration.dump()
|
||||||
|
|
||||||
|
|||||||
83
py/Scanner.py
Normal file
83
py/Scanner.py
Normal file
@@ -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
|
||||||
@@ -55,7 +55,7 @@ class Target(object):
|
|||||||
self.essid = '(%s)' % self.bssid
|
self.essid = '(%s)' % self.bssid
|
||||||
self.essid_known = False
|
self.essid_known = False
|
||||||
|
|
||||||
self.wps = False
|
self.wps = None
|
||||||
|
|
||||||
self.clients = []
|
self.clients = []
|
||||||
|
|
||||||
@@ -100,9 +100,11 @@ class Target(object):
|
|||||||
color = 'R'
|
color = 'R'
|
||||||
power = Color.s('{%s}%s' % (color, power))
|
power = Color.s('{%s}%s' % (color, power))
|
||||||
|
|
||||||
wps = Color.s('{R} no')
|
wps = Color.s('{O} n/a')
|
||||||
if self.wps:
|
if self.wps:
|
||||||
wps = Color.s('{G} yes')
|
wps = Color.s('{G} yes')
|
||||||
|
else:
|
||||||
|
wps = Color.s('{R} no')
|
||||||
|
|
||||||
clients = ' '
|
clients = ' '
|
||||||
if len(self.clients) == 1:
|
if len(self.clients) == 1:
|
||||||
|
|||||||
@@ -43,6 +43,11 @@ class Wash(object):
|
|||||||
# Update the WPS flag
|
# Update the WPS flag
|
||||||
t.wps = True
|
t.wps = True
|
||||||
|
|
||||||
|
# Mark other targets as "no" wps support
|
||||||
|
for t in targets:
|
||||||
|
if t.wps: continue
|
||||||
|
t.wps = False
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
from Target import Target
|
from Target import Target
|
||||||
|
|||||||
Reference in New Issue
Block a user