Documentation, code-formatting, and refactoring.
* Added some docs, updated existing docs. * Use single-quotes for strings when possible. * Color.pexception() prints exception and stack trace.
This commit is contained in:
@@ -33,7 +33,7 @@ class Color(object):
|
||||
'''
|
||||
Prints text using colored format on same line.
|
||||
Example:
|
||||
Color.p("{R}This text is red. {W} This text is white")
|
||||
Color.p('{R}This text is red. {W} This text is white')
|
||||
'''
|
||||
sys.stdout.write(Color.s(text))
|
||||
sys.stdout.flush()
|
||||
@@ -62,7 +62,7 @@ class Color(object):
|
||||
for (key,value) in Color.replacements.items():
|
||||
output = output.replace(key, value)
|
||||
for (key,value) in Color.colors.items():
|
||||
output = output.replace("{%s}" % key, value)
|
||||
output = output.replace('{%s}' % key, value)
|
||||
return output
|
||||
|
||||
@staticmethod
|
||||
@@ -76,7 +76,8 @@ class Color(object):
|
||||
def clear_entire_line():
|
||||
import os
|
||||
(rows, columns) = os.popen('stty size', 'r').read().split()
|
||||
Color.p("\r" + (" " * int(columns)) + "\r")
|
||||
Color.p('\r' + (' ' * int(columns)) + '\r')
|
||||
|
||||
|
||||
@staticmethod
|
||||
def pattack(attack_type, target, attack_name, progress):
|
||||
@@ -86,13 +87,31 @@ class Color(object):
|
||||
ESSID (Pwr) Attack_Type: Progress
|
||||
e.g.: Router2G (23db) WEP replay attack: 102 IVs
|
||||
'''
|
||||
essid = "{C}%s{W}" % target.essid if target.essid_known else "{O}unknown{W}"
|
||||
Color.p("\r{+} {G}%s{W} ({C}%sdb{W}) {G}%s {C}%s{W}: %s " % (
|
||||
essid = '{C}%s{W}' % target.essid if target.essid_known else '{O}unknown{W}'
|
||||
Color.p('\r{+} {G}%s{W} ({C}%sdb{W}) {G}%s {C}%s{W}: %s ' % (
|
||||
essid, target.power, attack_type, attack_name, progress))
|
||||
|
||||
if __name__ == '__main__':
|
||||
Color.pl("{R}Testing{G}One{C}Two{P}Three{W}Done")
|
||||
print(Color.s("{C}Testing{P}String{W}"))
|
||||
Color.pl("{+} Good line")
|
||||
Color.pl("{!} Danger")
|
||||
|
||||
@staticmethod
|
||||
def pexception(exception):
|
||||
'''Prints an exception. Includes stack trace if necessary.'''
|
||||
Color.pl('\n{!} {R}Error: {O}%s' % str(exception))
|
||||
|
||||
from ..config import Configuration
|
||||
if Configuration.verbose > 0 or Configuration.print_stack_traces:
|
||||
Color.pl('\n{!} {O}Full stack trace below')
|
||||
from traceback import format_exc
|
||||
Color.p('\n{!} ')
|
||||
err = format_exc().strip()
|
||||
err = err.replace('\n', '\n{!} {C} ')
|
||||
err = err.replace(' File', '{W}File')
|
||||
err = err.replace(' Exception: ', '{R}Exception: {O}')
|
||||
Color.pl(err)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
Color.pl('{R}Testing{G}One{C}Two{P}Three{W}Done')
|
||||
print(Color.s('{C}Testing{P}String{W}'))
|
||||
Color.pl('{+} Good line')
|
||||
Color.pl('{!} Danger')
|
||||
|
||||
|
||||
@@ -11,9 +11,10 @@ from datetime import datetime
|
||||
|
||||
import os
|
||||
|
||||
|
||||
class CrackHandshake(object):
|
||||
def __init__(self):
|
||||
self.wordlist = Configuration.wordlist or "path_to_wordlist_here"
|
||||
self.wordlist = Configuration.wordlist or 'path_to_wordlist_here'
|
||||
if os.path.exists(self.wordlist):
|
||||
self.wordlist = os.path.abspath(self.wordlist)
|
||||
|
||||
@@ -21,81 +22,81 @@ class CrackHandshake(object):
|
||||
self.crack_handshake(handshake)
|
||||
|
||||
def crack_handshake(self, handshake):
|
||||
cap_file = handshake["handshake_file"]
|
||||
bssid = handshake["bssid"]
|
||||
Color.pl("\n Below are commands to crack the handshake {C}%s{W}:" % cap_file)
|
||||
cap_file = handshake['handshake_file']
|
||||
bssid = handshake['bssid']
|
||||
Color.pl('\n Below are commands to crack the handshake {C}%s{W}:' % cap_file)
|
||||
self.print_aircrack(cap_file, bssid)
|
||||
self.print_pyrit(cap_file, bssid)
|
||||
self.print_john(cap_file)
|
||||
self.print_oclhashcat(cap_file)
|
||||
Color.pl("")
|
||||
# TODO: cowpatty, oclhashcat
|
||||
# TODO: cowpatty
|
||||
Color.pl('')
|
||||
|
||||
def print_aircrack(self, cap_file, bssid):
|
||||
Color.pl("")
|
||||
if not Process.exists("aircrack-ng"):
|
||||
Color.pl(" {R}aircrack-ng not found.");
|
||||
Color.pl(" {O}More info on installing {R}Aircrack{O} here: {C}https://www.aircrack-ng.org/downloads.html{W}");
|
||||
Color.pl('')
|
||||
if not Process.exists('aircrack-ng'):
|
||||
Color.pl(' {R}aircrack-ng not found.');
|
||||
Color.pl(' {O}More info on installing {R}Aircrack{O} here: {C}https://www.aircrack-ng.org/downloads.html{W}');
|
||||
return
|
||||
Color.pl(" {O}# AIRCRACK: CPU-based cracking. Slow.")
|
||||
Color.pl(" {G}aircrack-ng {W}-a {C}2 {W}-b {C}%s {W}-w {C}%s %s{W}" % (bssid, self.wordlist, cap_file))
|
||||
Color.pl(' {O}# AIRCRACK: CPU-based cracking. Slow.')
|
||||
Color.pl(' {G}aircrack-ng {W}-a {C}2 {W}-b {C}%s {W}-w {C}%s %s{W}' % (bssid, self.wordlist, cap_file))
|
||||
|
||||
def print_pyrit(self, cap_file, bssid):
|
||||
Color.pl("")
|
||||
if not Process.exists("pyrit"):
|
||||
Color.pl(" {R}pyrit not found.");
|
||||
Color.pl(" {O}More info on installing {R}Pyrit{O} here: {C}https://github.com/JPaulMora/Pyrit{W}");
|
||||
Color.pl('')
|
||||
if not Process.exists('pyrit'):
|
||||
Color.pl(' {R}pyrit not found.');
|
||||
Color.pl(' {O}More info on installing {R}Pyrit{O} here: {C}https://github.com/JPaulMora/Pyrit{W}');
|
||||
return
|
||||
Color.pl(" {O}# PYRIT: GPU-based cracking. Fast.")
|
||||
Color.pl(" {G}pyrit {W}-b {C}%s {W}-i {C}%s {W}-r {C}%s {W}attack_passthrough{W}" % (bssid, self.wordlist, cap_file))
|
||||
Color.pl(' {O}# PYRIT: GPU-based cracking. Fast.')
|
||||
Color.pl(' {G}pyrit {W}-b {C}%s {W}-i {C}%s {W}-r {C}%s {W}attack_passthrough{W}' % (bssid, self.wordlist, cap_file))
|
||||
|
||||
def print_john(self, cap_file):
|
||||
Color.pl("")
|
||||
Color.pl(" {O}# JOHN: CPU or GPU-based cracking. Fast.")
|
||||
if not Process.exists("john"):
|
||||
Color.pl(" {O}# {R}john{O} is not installed. More info on installing {R}John The Ripper{O} here: {C}http://www.openwall.com/john/{W}");
|
||||
Color.pl('')
|
||||
Color.pl(' {O}# JOHN: CPU or GPU-based cracking. Fast.')
|
||||
if not Process.exists('john'):
|
||||
Color.pl(' {O}# {R}john{O} is not installed. More info on installing {R}John The Ripper{O} here: {C}http://www.openwall.com/john/{W}');
|
||||
else:
|
||||
Color.pl(" {O}# Use --format=wpapsk-cuda (or wpapsk-opengl) to enable GPU acceleration")
|
||||
Color.pl(" {O}# See http://openwall.info/wiki/john/WPA-PSK for more info on this process")
|
||||
Color.pl(" {O}# Generate hccap file:")
|
||||
Color.pl(" {G}aircrack-ng {W}-J hccap {C}%s{W}" % cap_file)
|
||||
Color.pl(" {O}# Convert hccap file to john file:")
|
||||
Color.pl(" {G}hccap2john {C}hccap.hccap {W}> {C}%s.john{W}" % cap_file)
|
||||
Color.pl(" {O}# Crack john file:")
|
||||
Color.pl(" {G}john {W}--wordlist {C}\"%s\" {W}--format=wpapsk {C}\"%s.john\"{W}" % (self.wordlist, cap_file))
|
||||
Color.pl(' {O}# Use --format=wpapsk-cuda (or wpapsk-opengl) to enable GPU acceleration')
|
||||
Color.pl(' {O}# See http://openwall.info/wiki/john/WPA-PSK for more info on this process')
|
||||
Color.pl(' {O}# Generate hccap file:')
|
||||
Color.pl(' {G}aircrack-ng {W}-J hccap {C}%s{W}' % cap_file)
|
||||
Color.pl(' {O}# Convert hccap file to john file:')
|
||||
Color.pl(' {G}hccap2john {C}hccap.hccap {W}> {C}%s.john{W}' % cap_file)
|
||||
Color.pl(' {O}# Crack john file:')
|
||||
Color.pl(' {G}john {W}--wordlist {C}"%s" {W}--format=wpapsk {C}"%s.john"{W}' % (self.wordlist, cap_file))
|
||||
|
||||
def print_oclhashcat(self, cap_file):
|
||||
Color.pl("")
|
||||
if not Process.exists("hashcat"):
|
||||
Color.pl(" {R}hashcat {O}not found.");
|
||||
Color.pl(" {O}More info on installing {R}hashcat{O} here: {C}https://hashcat.net/hashcat/");
|
||||
Color.pl('')
|
||||
if not Process.exists('hashcat'):
|
||||
Color.pl(' {R}hashcat {O}not found.');
|
||||
Color.pl(' {O}More info on installing {R}hashcat{O} here: {C}https://hashcat.net/hashcat/');
|
||||
return
|
||||
Color.pl(" {O}# HASHCAT: GPU-based cracking. Fast.")
|
||||
Color.pl(" {O}# See {C}https://hashcat.net/wiki/doku.php?id=cracking_wpawpa2 {O}for more info")
|
||||
Color.pl(" {O}# Step 1: Generate .hccapx file")
|
||||
Color.pl(' {O}# HASHCAT: GPU-based cracking. Fast.')
|
||||
Color.pl(' {O}# See {C}https://hashcat.net/wiki/doku.php?id=cracking_wpawpa2 {O}for more info')
|
||||
Color.pl(' {O}# Step 1: Generate .hccapx file')
|
||||
|
||||
hccapx_file = "/tmp/generated.hccapx"
|
||||
cap2hccapx = "/usr/lib/hashcat-utils/cap2hccapx.bin"
|
||||
hccapx_file = '/tmp/generated.hccapx'
|
||||
cap2hccapx = '/usr/lib/hashcat-utils/cap2hccapx.bin'
|
||||
if os.path.exists(cap2hccapx):
|
||||
Color.pl(" {G} %s {W}%s {C}%s{W}" % (cap2hccapx, cap_file, hccapx_file))
|
||||
Color.pl(' {G} %s {W}%s {C}%s{W}' % (cap2hccapx, cap_file, hccapx_file))
|
||||
else:
|
||||
Color.pl(" {O}# Install {R}cap2hccapx{O}: {C}https://hashcat.net/wiki/doku.php?id=hashcat_utils")
|
||||
Color.pl(" {G}./cap2hccapx.bin {W}%s {C}%s{W}" % (cap_file, hccapx_file))
|
||||
Color.pl(" {O}# OR visit https://hashcat.net/cap2hccapx to generate a .hccapx file{W}")
|
||||
Color.pl(" {O}# Then click BROWSE -> %s -> CONVERT and save to %s" % (cap_file, hccapx_file))
|
||||
Color.pl(' {O}# Install {R}cap2hccapx{O}: {C}https://hashcat.net/wiki/doku.php?id=hashcat_utils')
|
||||
Color.pl(' {G}./cap2hccapx.bin {W}%s {C}%s{W}' % (cap_file, hccapx_file))
|
||||
Color.pl(' {O}# OR visit https://hashcat.net/cap2hccapx to generate a .hccapx file{W}')
|
||||
Color.pl(' {O}# Then click BROWSE -> %s -> CONVERT and save to %s' % (cap_file, hccapx_file))
|
||||
|
||||
Color.pl(" {O}# Step 2: Crack the .hccapx file")
|
||||
Color.pl(" {G}hashcat {W}-m 2500 {C}%s %s{W}" % (hccapx_file, self.wordlist))
|
||||
Color.pl(' {O}# Step 2: Crack the .hccapx file')
|
||||
Color.pl(' {G}hashcat {W}-m 2500 {C}%s %s{W}' % (hccapx_file, self.wordlist))
|
||||
|
||||
def choose_handshake(self):
|
||||
hs_dir = Configuration.wpa_handshake_dir
|
||||
Color.pl("{+} Listing captured handshakes from {C}%s{W}\n" % os.path.realpath(hs_dir))
|
||||
Color.pl('{+} Listing captured handshakes from {C}%s{W}\n' % os.path.realpath(hs_dir))
|
||||
handshakes = []
|
||||
for hs_file in os.listdir(hs_dir):
|
||||
if not hs_file.endswith('.cap') or hs_file.count("_") != 3:
|
||||
if not hs_file.endswith('.cap') or hs_file.count('_') != 3:
|
||||
continue
|
||||
|
||||
name, essid, bssid, date = hs_file.split("_")
|
||||
name, essid, bssid, date = hs_file.split('_')
|
||||
|
||||
if name != 'handshake':
|
||||
continue
|
||||
@@ -110,33 +111,33 @@ class CrackHandshake(object):
|
||||
handshakes.sort(key=lambda x: x['date'], reverse=True)
|
||||
|
||||
if len(handshakes) == 0:
|
||||
raise Exception("No handshakes found in %s" % os.path.realpath(hs_dir))
|
||||
raise Exception('No handshakes found in %s' % os.path.realpath(hs_dir))
|
||||
|
||||
# Handshakes Header
|
||||
max_essid_len = max(max([len(hs["essid"]) for hs in handshakes]), len('(truncated) ESSDID'))
|
||||
Color.p(" NUM")
|
||||
Color.p(" " + "ESSID (truncated)".ljust(max_essid_len))
|
||||
Color.p(" " + "BSSID".ljust(17))
|
||||
Color.p(" DATE CAPTURED\n")
|
||||
Color.p(" ---")
|
||||
Color.p(" " + ("-" * max_essid_len))
|
||||
Color.p(" " + ("-" * 17))
|
||||
Color.p(" " + ("-" * 19) + "\n")
|
||||
max_essid_len = max(max([len(hs['essid']) for hs in handshakes]), len('(truncated) ESSDID'))
|
||||
Color.p(' NUM')
|
||||
Color.p(' ' + 'ESSID (truncated)'.ljust(max_essid_len))
|
||||
Color.p(' ' + 'BSSID'.ljust(17))
|
||||
Color.p(' DATE CAPTURED\n')
|
||||
Color.p(' ---')
|
||||
Color.p(' ' + ('-' * max_essid_len))
|
||||
Color.p(' ' + ('-' * 17))
|
||||
Color.p(' ' + ('-' * 19) + '\n')
|
||||
# Print all handshakes
|
||||
for idx, hs in enumerate(handshakes, start=1):
|
||||
bssid = hs["bssid"]
|
||||
essid = hs["essid"]
|
||||
date = hs["date"]
|
||||
Color.p(" {G}%s{W}" % str(idx).rjust(3))
|
||||
Color.p(" {C}%s{W}" % essid.ljust(max_essid_len))
|
||||
Color.p(" {O}%s{W}" % bssid)
|
||||
Color.p(" {W}%s{W}\n" % date)
|
||||
bssid = hs['bssid']
|
||||
essid = hs['essid']
|
||||
date = hs['date']
|
||||
Color.p(' {G}%s{W}' % str(idx).rjust(3))
|
||||
Color.p(' {C}%s{W}' % essid.ljust(max_essid_len))
|
||||
Color.p(' {O}%s{W}' % bssid)
|
||||
Color.p(' {W}%s{W}\n' % date)
|
||||
# Get number from user
|
||||
hs_index = raw_input(Color.s("\n{+} Select handshake num to crack ({G}1-%d{W}): " % len(handshakes)))
|
||||
hs_index = raw_input(Color.s('\n{+} Select handshake num to crack ({G}1-%d{W}): ' % len(handshakes)))
|
||||
if not hs_index.isdigit():
|
||||
raise ValueError("Handshake NUM must be numeric, got (%s)" % hs_index)
|
||||
raise ValueError('Handshake NUM must be numeric, got (%s)' % hs_index)
|
||||
hs_index = int(hs_index)
|
||||
if hs_index < 1 or hs_index > len(handshakes):
|
||||
raise Exception("Handshake NUM must be between 1 and %d" % len(handshakes))
|
||||
raise Exception('Handshake NUM must be between 1 and %d' % len(handshakes))
|
||||
|
||||
return handshakes[hs_index - 1]
|
||||
|
||||
@@ -29,11 +29,11 @@ class Process(object):
|
||||
if type(command) is not str or ' ' in command or shell:
|
||||
shell = True
|
||||
if Configuration.verbose > 1:
|
||||
Color.pe("\n {C}[?] {W} Executing (Shell): {B}%s{W}" % command)
|
||||
Color.pe('\n {C}[?] {W} Executing (Shell): {B}%s{W}' % command)
|
||||
else:
|
||||
shell = False
|
||||
if Configuration.verbose > 1:
|
||||
Color.pe("\n {C}[?]{W} Executing: {B}%s{W}" % command)
|
||||
Color.pe('\n {C}[?]{W} Executing: {B}%s{W}' % command)
|
||||
|
||||
pid = Popen(command, cwd=cwd, stdout=PIPE, stderr=PIPE, shell=shell)
|
||||
pid.wait()
|
||||
@@ -45,9 +45,9 @@ class Process(object):
|
||||
|
||||
|
||||
if Configuration.verbose > 1 and stdout is not None and stdout.strip() != '':
|
||||
Color.pe("{P} [stdout] %s{W}" % '\n [stdout] '.join(stdout.strip().split('\n')))
|
||||
Color.pe('{P} [stdout] %s{W}' % '\n [stdout] '.join(stdout.strip().split('\n')))
|
||||
if Configuration.verbose > 1 and stderr is not None and stderr.strip() != '':
|
||||
Color.pe("{P} [stderr] %s{W}" % '\n [stderr] '.join(stderr.strip().split('\n')))
|
||||
Color.pe('{P} [stderr] %s{W}' % '\n [stderr] '.join(stderr.strip().split('\n')))
|
||||
|
||||
return (stdout, stderr)
|
||||
|
||||
@@ -73,7 +73,7 @@ class Process(object):
|
||||
self.command = command
|
||||
|
||||
if Configuration.verbose > 1:
|
||||
Color.pe("\n {C}[?] {W} Executing: {B}%s{W}" % ' '.join(command))
|
||||
Color.pe('\n {C}[?] {W} Executing: {B}%s{W}' % ' '.join(command))
|
||||
|
||||
self.out = None
|
||||
self.err = None
|
||||
@@ -103,14 +103,14 @@ class Process(object):
|
||||
''' Waits for process to finish, returns stdout output '''
|
||||
self.get_output()
|
||||
if Configuration.verbose > 1 and self.out is not None and self.out.strip() != '':
|
||||
Color.pe("{P} [stdout] %s{W}" % '\n [stdout] '.join(self.out.strip().split('\n')))
|
||||
Color.pe('{P} [stdout] %s{W}' % '\n [stdout] '.join(self.out.strip().split('\n')))
|
||||
return self.out
|
||||
|
||||
def stderr(self):
|
||||
''' Waits for process to finish, returns stderr output '''
|
||||
self.get_output()
|
||||
if Configuration.verbose > 1 and self.err is not None and self.err.strip() != '':
|
||||
Color.pe("{P} [stderr] %s{W}" % '\n [stderr] '.join(self.err.strip().split('\n')))
|
||||
Color.pe('{P} [stderr] %s{W}' % '\n [stderr] '.join(self.err.strip().split('\n')))
|
||||
return self.err
|
||||
|
||||
def stdoutln(self):
|
||||
@@ -135,7 +135,7 @@ class Process(object):
|
||||
return (self.out, self.err)
|
||||
|
||||
def poll(self):
|
||||
''' Returns exit code if process is dead, otherwise "None" '''
|
||||
''' Returns exit code if process is dead, otherwise 'None' '''
|
||||
return self.pid.poll()
|
||||
|
||||
def wait(self):
|
||||
@@ -202,8 +202,8 @@ if __name__ == '__main__':
|
||||
|
||||
# Test on never-ending process
|
||||
p = Process('yes')
|
||||
print("Running yes...")
|
||||
print('Running yes...')
|
||||
time.sleep(1)
|
||||
print("yes should stop now")
|
||||
print('yes should stop now')
|
||||
# After program loses reference to instance in 'p', process dies.
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from ..tools.airodump import Airodump
|
||||
from ..util.color import Color
|
||||
from ..tools.airodump import Airodump
|
||||
from ..util.input import raw_input, xrange
|
||||
from ..model.target import Target
|
||||
from ..config import Configuration
|
||||
@@ -17,16 +17,18 @@ class Scanner(object):
|
||||
|
||||
def __init__(self):
|
||||
'''
|
||||
Starts scan, prints as it goes.
|
||||
Upon interrupt, sets 'targets'.
|
||||
Scans for targets via Airodump.
|
||||
Loops until scan is interrupted via user or config.
|
||||
Note: Sets this object's `targets` attrbute (list[Target]) upon interruption.
|
||||
'''
|
||||
self.previous_target_count = 0
|
||||
self.targets = []
|
||||
self.target = None # Specific target (based on ESSID/BSSID)
|
||||
self.target = None # Target specified by user (based on ESSID/BSSID)
|
||||
|
||||
max_scan_time = Configuration.scan_time
|
||||
|
||||
self.err_msg = None
|
||||
|
||||
Color.pl("")
|
||||
# Loads airodump with interface/channel/etc from Configuration
|
||||
try:
|
||||
with Airodump() as airodump:
|
||||
@@ -35,18 +37,15 @@ class Scanner(object):
|
||||
|
||||
while True:
|
||||
if airodump.pid.poll() is not None:
|
||||
# Airodump process died
|
||||
return
|
||||
return # Airodump process died
|
||||
|
||||
self.targets = airodump.get_targets(old_targets=self.targets)
|
||||
|
||||
if self.found_target():
|
||||
# We found the target we want
|
||||
return
|
||||
return # We found the target we want
|
||||
|
||||
if airodump.pid.poll() is not None:
|
||||
# Airodump process died
|
||||
return
|
||||
return # Airodump process died
|
||||
|
||||
for target in self.targets:
|
||||
if target.bssid in airodump.decloaked_bssids:
|
||||
@@ -55,20 +54,19 @@ class Scanner(object):
|
||||
self.print_targets()
|
||||
|
||||
target_count = len(self.targets)
|
||||
client_count = sum(
|
||||
[len(t.clients)
|
||||
for t in self.targets])
|
||||
outline = "\r{+} Scanning"
|
||||
client_count = sum([len(t.clients) for t in self.targets])
|
||||
|
||||
outline = '\r{+} Scanning'
|
||||
if airodump.decloaking:
|
||||
outline += " & decloaking"
|
||||
outline += ". Found"
|
||||
outline += " {G}%d{W} target(s)," % target_count
|
||||
outline += " {G}%d{W} client(s)." % client_count
|
||||
outline += " {O}Ctrl+C{W} when ready "
|
||||
outline += ' & decloaking'
|
||||
outline += '. Found'
|
||||
outline += ' {G}%d{W} target(s),' % target_count
|
||||
outline += ' {G}%d{W} client(s).' % client_count
|
||||
outline += ' {O}Ctrl+C{W} when ready '
|
||||
Color.clear_entire_line()
|
||||
Color.p(outline)
|
||||
|
||||
if Configuration.scan_time > 0 and time() > scan_start_time + Configuration.scan_time:
|
||||
if max_scan_time > 0 and time() > scan_start_time + max_scan_time:
|
||||
return
|
||||
|
||||
sleep(1)
|
||||
@@ -76,17 +74,18 @@ class Scanner(object):
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
|
||||
|
||||
def found_target(self):
|
||||
'''
|
||||
Check if we discovered the target AP
|
||||
Returns: the Target if found,
|
||||
Otherwise None.
|
||||
Detect if we found a target specified by the user (optional).
|
||||
Sets this object's `target` attribute if found.
|
||||
Returns: True if target was specified and found, False otherwise.
|
||||
'''
|
||||
bssid = Configuration.target_bssid
|
||||
essid = Configuration.target_essid
|
||||
|
||||
if bssid is None and essid is None:
|
||||
return False
|
||||
return False # No specific target from user.
|
||||
|
||||
for target in self.targets:
|
||||
if Configuration.wps_only and target.wps != True:
|
||||
@@ -105,10 +104,9 @@ class Scanner(object):
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def print_targets(self):
|
||||
'''
|
||||
Prints targets to console
|
||||
'''
|
||||
'''Prints targets selection menu (1 target per row).'''
|
||||
if len(self.targets) == 0:
|
||||
Color.p('\r')
|
||||
return
|
||||
@@ -168,7 +166,15 @@ class Scanner(object):
|
||||
return int(columns)
|
||||
|
||||
def select_targets(self):
|
||||
''' Asks user to select target(s) '''
|
||||
'''
|
||||
Returns list(target)
|
||||
Either a specific target if user specified -bssid or --essid.
|
||||
Otherwise, prompts user to select targets and returns the selection.
|
||||
'''
|
||||
|
||||
if self.target:
|
||||
# When user specifies a specific target
|
||||
return [self.target]
|
||||
|
||||
if len(self.targets) == 0:
|
||||
if self.err_msg is not None:
|
||||
@@ -178,13 +184,15 @@ class Scanner(object):
|
||||
# 1. Link to wireless drivers wiki,
|
||||
# 2. How to check if your device supporst monitor mode,
|
||||
# 3. Provide airodump-ng command being executed.
|
||||
raise Exception("No targets found."
|
||||
+ " You may need to wait longer,"
|
||||
+ " or you may have issues with your wifi card")
|
||||
raise Exception('No targets found.'
|
||||
+ ' You may need to wait longer,'
|
||||
+ ' or you may have issues with your wifi card')
|
||||
|
||||
# Return all targets if user specified a wait time ("pillage").
|
||||
if Configuration.scan_time > 0:
|
||||
return self.targets
|
||||
|
||||
# Ask user for targets.
|
||||
self.print_targets()
|
||||
Color.clear_entire_line()
|
||||
|
||||
@@ -211,12 +219,12 @@ class Scanner(object):
|
||||
elif choice.isdigit():
|
||||
choice = int(choice) - 1
|
||||
chosen_targets.append(self.targets[choice])
|
||||
else:
|
||||
pass
|
||||
|
||||
return chosen_targets
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Example displays targets and selects the appropriate one
|
||||
# "Test" script will display targets and selects the appropriate one
|
||||
Configuration.initialize()
|
||||
try:
|
||||
s = Scanner()
|
||||
@@ -225,6 +233,6 @@ if __name__ == '__main__':
|
||||
Color.pl('\r {!} {R}Error{W}: %s' % str(e))
|
||||
Configuration.exit_gracefully(0)
|
||||
for t in targets:
|
||||
Color.pl(" {W}Selected: %s" % t)
|
||||
Color.pl(' {W}Selected: %s' % t)
|
||||
Configuration.exit_gracefully(0)
|
||||
|
||||
|
||||
@@ -32,8 +32,8 @@ class Timer(object):
|
||||
mins = (rem % 3600) / 60
|
||||
secs = rem % 60
|
||||
if hours > 0:
|
||||
return "%dh%dm%ds" % (hours, mins, secs)
|
||||
return '%dh%dm%ds' % (hours, mins, secs)
|
||||
elif mins > 0:
|
||||
return "%dm%ds" % (mins, secs)
|
||||
return '%dm%ds' % (mins, secs)
|
||||
else:
|
||||
return "%ds" % secs
|
||||
return '%ds' % secs
|
||||
|
||||
Reference in New Issue
Block a user