From 7b1a5ef9e54a140ca56db74523f869bd5a8dcf5f Mon Sep 17 00:00:00 2001 From: tiagogalvao Date: Sun, 31 Jul 2022 14:52:54 +0000 Subject: [PATCH] v2.7 preparation: code cleanup based on flake8 suggestions --- wifite/__main__.py | 3 +- wifite/args.py | 66 ++++++++++++++++++++++--------------- wifite/attack/all.py | 4 +-- wifite/attack/pmkid.py | 12 +++---- wifite/attack/wep.py | 69 +++++++++++++++++---------------------- wifite/attack/wpa.py | 12 +++---- wifite/attack/wps.py | 3 +- wifite/config.py | 31 +++++++----------- wifite/model/client.py | 3 +- wifite/model/handshake.py | 12 ++++--- wifite/model/target.py | 8 ++--- wifite/tools/aircrack.py | 9 +++-- wifite/tools/aireplay.py | 10 +++--- wifite/tools/airmon.py | 16 ++++----- wifite/tools/bully.py | 27 ++++++++------- wifite/tools/hashcat.py | 3 +- wifite/tools/john.py | 3 +- wifite/tools/reaver.py | 10 +++++- wifite/tools/tshark.py | 3 +- wifite/util/color.py | 2 +- wifite/util/crack.py | 18 +++++----- wifite/util/process.py | 6 ++-- wifite/util/scanner.py | 11 +++---- 23 files changed, 171 insertions(+), 170 deletions(-) diff --git a/wifite/__main__.py b/wifite/__main__.py index 432c4a63c..626e29693 100755 --- a/wifite/__main__.py +++ b/wifite/__main__.py @@ -17,7 +17,8 @@ class Wifite(object): def __init__(self): """ - Initializes Wifite. Checks that its running under *nix, with root permissions and ensures dependencies are installed. + Initializes Wifite. + Checks that its running under *nix, with root permissions and ensures dependencies are installed. """ self.print_banner() diff --git a/wifite/args.py b/wifite/args.py index 0557bdf98..02262ece2 100755 --- a/wifite/args.py +++ b/wifite/args.py @@ -250,8 +250,8 @@ def _add_wep_args(self, wep): dest='wep_crack_at_ivs', metavar='[ivs]', type=int, - help=self._verbose( - 'Start cracking at this many IVs (default: {G}%d ivs{W})' % self.config.wep_crack_at_ivs)) + help=self._verbose('Start cracking at this many IVs (default: {G}%d ivs{W})' + % self.config.wep_crack_at_ivs)) wep.add_argument('-wepca', help=argparse.SUPPRESS, action='store', dest='wep_crack_at_ivs', type=int) wep.add_argument('--weprs', @@ -259,8 +259,8 @@ def _add_wep_args(self, wep): dest='wep_restart_stale_ivs', metavar='[seconds]', type=int, - help=self._verbose('Restart aireplay if no new IVs appear (default: ' + - '{G}%d sec{W})' % self.config.wep_restart_stale_ivs)) + help=self._verbose('Restart aireplay if no new IVs appear (default: {G}%d sec{W})' + % self.config.wep_restart_stale_ivs)) wep.add_argument('-weprs', help=argparse.SUPPRESS, action='store', dest='wep_restart_stale_ivs', type=int) wep.add_argument('--weprc', @@ -268,8 +268,8 @@ def _add_wep_args(self, wep): dest='wep_restart_aircrack', metavar='[seconds]', type=int, - help=self._verbose('Restart aircrack after this delay (default: ' + - '{G}%d sec{W})' % self.config.wep_restart_aircrack)) + help=self._verbose('Restart aircrack after this delay (default: {G}%d sec{W})' + % self.config.wep_restart_aircrack)) wep.add_argument('-weprc', help=argparse.SUPPRESS, action='store', dest='wep_restart_aircrack', type=int) wep.add_argument('--arpreplay', @@ -327,8 +327,8 @@ def _add_wpa_args(self, wpa): wpa.add_argument('--new-hs', action='store_true', dest='ignore_old_handshakes', - help=Color.s('Captures new handshakes, ignores existing handshakes ' + - 'in {C}%s{W} (default: {G}off{W})' % self.config.wpa_handshake_dir)) + help=Color.s('Captures new handshakes, ignores existing handshakes in {C}%s{W} ' + '(default: {G}off{W})' % self.config.wpa_handshake_dir)) wpa.add_argument('--dict', action='store', @@ -343,8 +343,8 @@ def _add_wpa_args(self, wpa): dest='wpa_deauth_timeout', metavar='[seconds]', type=int, - help=self._verbose('Time to wait between sending Deauths ' + - '(default: {G}%d sec{W})' % self.config.wpa_deauth_timeout)) + help=self._verbose('Time to wait between sending Deauths (default: {G}%d sec{W})' + % self.config.wpa_deauth_timeout)) wpa.add_argument('-wpadt', help=argparse.SUPPRESS, action='store', dest='wpa_deauth_timeout', type=int) wpa.add_argument('--wpat', @@ -352,8 +352,8 @@ def _add_wpa_args(self, wpa): dest='wpa_attack_timeout', metavar='[seconds]', type=int, - help=self._verbose('Time to wait before failing WPA attack ' + - '(default: {G}%d sec{W})' % self.config.wpa_attack_timeout)) + help=self._verbose('Time to wait before failing WPA attack (default: {G}%d sec{W})' + % self.config.wpa_attack_timeout)) wpa.add_argument('-wpat', help=argparse.SUPPRESS, action='store', dest='wpa_attack_timeout', type=int) # TODO: Uncomment the --strip option once it works @@ -376,7 +376,7 @@ def _add_wps_args(self, wps): wps.add_argument('--no-wps', action='store_true', dest='no_wps', - help=self._verbose('{O}Never{W} use {O}WPS PIN{W} & {O}Pixie-Dust{W}' + + help=self._verbose('{O}Never{W} use {O}WPS PIN{W} & {O}Pixie-Dust{W} ' 'attacks on targets (default: {G}off{W})')) wps.add_argument('--wps-only', @@ -396,7 +396,7 @@ def _add_wps_args(self, wps): wps.add_argument('--bully', action='store_true', dest='use_bully', - help=Color.s('Use {G}bully{W} program for WPS PIN & Pixie-Dust attacks ' + + help=Color.s('Use {G}bully{W} program for WPS PIN & Pixie-Dust attacks ' '(default: {G}reaver{W})')) # Alias wps.add_argument('-bully', help=argparse.SUPPRESS, action='store_true', dest='use_bully') @@ -404,13 +404,15 @@ def _add_wps_args(self, wps): wps.add_argument('--reaver', action='store_true', dest='use_reaver', - help=Color.s('Use {G}reaver{W} program for WPS PIN & Pixie-Dust attacks (default: {G}reaver{W})')) + help=Color.s('Use {G}reaver{W} program for WPS PIN & Pixie-Dust attacks' + ' (default: {G}reaver{W})')) # Alias wps.add_argument('-reaver', help=argparse.SUPPRESS, action='store_true', dest='use_reaver') # Ignore lock-outs wps.add_argument('--ignore-locks', action='store_true', dest='wps_ignore_lock', - help=Color.s('Do {O}not{W} stop WPS PIN attack if AP becomes {O}locked{W} (default: {G}stop{W})')) + help=Color.s('Do {O}not{W} stop WPS PIN attack if AP becomes {O}locked{W} ' + '(default: {G}stop{W})')) # Time limit on entire attack. wps.add_argument('--wps-time', @@ -418,8 +420,8 @@ def _add_wps_args(self, wps): dest='wps_pixie_timeout', metavar='[sec]', type=int, - help=self._verbose('Total time to wait before failing PixieDust attack ' + - '(default: {G}%d sec{W})' % self.config.wps_pixie_timeout)) + help=self._verbose('Total time to wait before failing PixieDust attack (default: {G}%d sec{W})' + % self.config.wps_pixie_timeout)) # Alias wps.add_argument('-wpst', help=argparse.SUPPRESS, action='store', dest='wps_pixie_timeout', type=int) @@ -429,8 +431,8 @@ def _add_wps_args(self, wps): dest='wps_fail_threshold', metavar='[num]', type=int, - help=self._verbose('Maximum number of WPSFail/NoAssoc errors before ' + - 'failing (default: {G}%d{W})' % self.config.wps_fail_threshold)) + help=self._verbose('Maximum number of WPSFail/NoAssoc errors before failing ' + '(default: {G}%d{W})' % self.config.wps_fail_threshold)) # Alias wps.add_argument('-wpsf', help=argparse.SUPPRESS, action='store', dest='wps_fail_threshold', type=int) @@ -440,8 +442,8 @@ def _add_wps_args(self, wps): dest='wps_timeout_threshold', metavar='[num]', type=int, - help=self._verbose('Maximum number of Timeouts before failing ' + - '(default: {G}%d{W})' % self.config.wps_timeout_threshold)) + help=self._verbose('Maximum number of Timeouts before failing (default: {G}%d{W})' + % self.config.wps_timeout_threshold)) # Alias wps.add_argument('-wpsto', help=argparse.SUPPRESS, action='store', dest='wps_timeout_threshold', type=int) @@ -449,7 +451,7 @@ def _add_pmkid_args(self, pmkid): pmkid.add_argument('--pmkid', action='store_true', dest='use_pmkid_only', - help=Color.s('{O}Only{W} use {C}PMKID capture{W}, avoids other WPS & ' + + help=Color.s('{O}Only{W} use {C}PMKID capture{W}, avoids other WPS & ' 'WPA attacks (default: {G}off{W})')) pmkid.add_argument('--no-pmkid', action='store_true', @@ -464,15 +466,19 @@ def _add_pmkid_args(self, pmkid): dest='pmkid_timeout', metavar='[sec]', type=int, - help=Color.s('Time to wait for PMKID capture ' + - '(default: {G}%d{W} seconds)' % self.config.pmkid_timeout)) + help=Color.s('Time to wait for PMKID capture (default: {G}%d{W} seconds)' + % self.config.pmkid_timeout)) def _add_command_args(self, commands): commands.add_argument('--cracked', action='store_true', dest='cracked', help=Color.s('Print previously-cracked access points')) - commands.add_argument('-cracked', help=argparse.SUPPRESS, action='store_true', dest='cracked') + + commands.add_argument('-cracked', + help=argparse.SUPPRESS, + action='store_true', + dest='cracked') commands.add_argument('--check', action='store', @@ -481,7 +487,13 @@ def _add_command_args(self, commands): const='', dest='check_handshake', help=Color.s('Check a {C}.cap file{W} (or all {C}hs/*.cap{W} files) for WPA handshakes')) - commands.add_argument('-check', help=argparse.SUPPRESS, action='store', nargs='?', const='', dest='check_handshake') + + commands.add_argument('-check', + help=argparse.SUPPRESS, + action='store', + nargs='?', + const='', + dest='check_handshake') commands.add_argument('--crack', action='store_true', diff --git a/wifite/attack/all.py b/wifite/attack/all.py index 0e60797bd..63de76737 100755 --- a/wifite/attack/all.py +++ b/wifite/attack/all.py @@ -34,8 +34,8 @@ def attack_multiple(cls, targets): bssid = target.bssid essid = target.essid if target.essid_known else '{O}ESSID unknown{W}' - Color.pl('\n{+} ({G}%d{W}/{G}%d{W})' % (index, len(targets)) + - ' Starting attacks against {C}%s{W} ({C}%s{W})' % (bssid, essid)) + Color.pl('\n{+} ({G}%d{W}/{G}%d{W})' + % (index, len(targets)) + ' Starting attacks against {C}%s{W} ({C}%s{W})' % (bssid, essid)) should_continue = cls.attack_single(target, targets_remaining) if not should_continue: diff --git a/wifite/attack/pmkid.py b/wifite/attack/pmkid.py index e241cb3dc..f9c5eeaa8 100755 --- a/wifite/attack/pmkid.py +++ b/wifite/attack/pmkid.py @@ -140,7 +140,8 @@ def run_aircrack(self): # essid = airodump_target.essid if airodump_target.essid_known else None # handshake = self.load_handshake(bssid=bssid, essid=essid) # if handshake: - # Color.pattack('WPA', self.target, 'Handshake capture', 'found {G}existing handshake{W} for {C}%s{W}' % handshake.essid) + # Color.pattack('WPA', self.target, 'Handshake capture', + # 'found {G}existing handshake{W} for {C}%s{W}' % handshake.essid) # Color.pl('\n{+} Using handshake from {C}%s{W}' % handshake.capfile) # return handshake @@ -167,17 +168,14 @@ def run_aircrack(self): copy(cap_file, temp_file) # Check cap file in temp for Handshake - bssid = airodump_target.bssid - essid = airodump_target.essid if airodump_target.essid_known else None + # bssid = airodump_target.bssid + # essid = airodump_target.essid if airodump_target.essid_known else None # AttackPMKID.check_pmkid(temp_file, self.target.bssid) if self.check_pmkid(temp_file): # We got a handshake Color.clear_entire_line() - Color.pattack('WPA', - airodump_target, - 'PMKID capture', - '{G}Captured PMKID{W}') + Color.pattack('WPA', airodump_target, 'PMKID capture', '{G}Captured PMKID{W}') Color.pl('') capture = temp_file break diff --git a/wifite/attack/wep.py b/wifite/attack/wep.py index deccebc98..0e2c9d85c 100755 --- a/wifite/attack/wep.py +++ b/wifite/attack/wep.py @@ -1,17 +1,16 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +import time + +from ..config import Configuration from ..model.attack import Attack -from ..tools.airodump import Airodump -from ..tools.aireplay import Aireplay, WEPAttackType +from ..model.wep_result import CrackResultWEP from ..tools.aircrack import Aircrack +from ..tools.aireplay import Aireplay, WEPAttackType +from ..tools.airodump import Airodump from ..tools.ip import Ip -from ..config import Configuration from ..util.color import Color -from ..util.input import raw_input -from ..model.wep_result import CrackResultWEP - -import time class AttackWEP(Attack): @@ -75,8 +74,8 @@ def run(self): # Failed to fakeauth, can't use our MAC. # And there are no associated clients. Use one and tell the user. Color.pl('{!} {O}there are no associated clients{W}') - Color.pl('{!} {R}WARNING: {O}many attacks will not succeed' + - ' without fake-authentication or associated clients{W}') + Color.pl('{!} {R}WARNING: {O}many attacks will not succeed ' + 'without fake-authentication or associated clients{W}') client_mac = None else: # Fakeauth failed, but we can re-use an existing client @@ -95,7 +94,6 @@ def run(self): last_ivs_count = 0 # Loop until attack completes. - while True: airodump_target = self.wait_for_target(airodump) @@ -123,16 +121,18 @@ def run(self): # Check if we cracked it. if aircrack and aircrack.is_cracked(): (hex_key, ascii_key) = aircrack.get_key_hex_ascii() - bssid = airodump_target.bssid - if airodump_target.essid_known: - essid = airodump_target.essid - else: - essid = None + # bssid = airodump_target.bssid + # if airodump_target.essid_known: + # essid = airodump_target.essid + # else: + # essid = None Color.pl('\n{+} {C}%s{W} WEP attack {G}successful{W}\n' % attack_name) - if aireplay: aireplay.stop() - if fakeauth_proc: fakeauth_proc.stop() - self.crack_result = CrackResultWEP(self.target.bssid, - self.target.essid, hex_key, ascii_key) + if aireplay: + aireplay.stop() + if fakeauth_proc: + fakeauth_proc.stop() + + self.crack_result = CrackResultWEP(self.target.bssid, self.target.essid, hex_key, ascii_key) self.crack_result.dump() Airodump.delete_airodump_temp_files('wep') @@ -170,7 +170,6 @@ def run(self): # Some Aireplay attacks loop infinitely if attack_name == 'chopchop' or attack_name == 'fragment': # We expect these to stop once a .xor is created, or if the process failed. - replay_file = None # Check for .xor file. @@ -184,14 +183,12 @@ def run(self): break # If .xor exists, run packetforge-ng to create .cap - Color.pl('\n{+} {C}%s attack{W}' % attack_name + - ' generated a {C}.xor file{W}, {G}forging...{W}') - replay_file = Aireplay.forge_packet(xor_file, - airodump_target.bssid, - client_mac) + Color.pl( + '\n{+} {C}%s attack{W}' + % attack_name + ' generated a {C}.xor file{W}, {G}forging...{W}') + replay_file = Aireplay.forge_packet(xor_file, airodump_target.bssid, client_mac) if replay_file: - Color.pl('{+} {C}forged packet{W},' + - ' {G}replaying...{W}') + Color.pl('{+} {C}forged packet{W}, {G}replaying...{W}') wep_attack_type = WEPAttackType('forgedreplay') attack_name = 'forgedreplay' aireplay = Aireplay(self.target, @@ -220,8 +217,7 @@ def run(self): if stale_seconds > Configuration.wep_restart_stale_ivs: # No new IVs within threshold, restart aireplay aireplay.stop() - Color.pl('\n{!} restarting {C}aireplay{W} after' + - ' {C}%d{W} seconds of no new IVs' + Color.pl('\n{!} Restarting {C}aireplay{W} after {C}%d{W} seconds of no new IVs' % stale_seconds) aireplay = Aireplay(self.target, wep_attack_type, @@ -344,16 +340,11 @@ def fake_auth(self): Color.pl(' {R}failed{W}') if Configuration.require_fakeauth: # Fakeauth is required, fail - raise Exception( - 'Fake-authenticate did not complete within' + - ' %d seconds' % AttackWEP.fakeauth_wait) + raise Exception('Fake-authenticate did not complete within %d seconds' % AttackWEP.fakeauth_wait) else: # Warn that fakeauth failed - Color.pl('{!} {O}' + - 'unable to fake-authenticate with target' + - ' (%s){W}' % self.target.bssid) - Color.pl('{!} continuing attacks because' + - ' {G}--require-fakeauth{W} was not set') + Color.pl('{!} {O} unable to fake-authenticate with target (%s){W}' % self.target.bssid) + Color.pl('{!} continuing attacks because {G}--require-fakeauth{W} was not set') return fakeauth @@ -361,8 +352,8 @@ def fake_auth(self): Configuration.initialize(True) from ..model.target import Target - fields = 'A4:2B:8C:16:6B:3A, 2015-05-27 19:28:44, 2015-05-27 19:28:46, 6, 54e,WEP, WEP, , -58, 2, 0, 0. 0. 0. 0, 9, Test Router Please Ignore, '.split( - ',') + fields = 'A4:2B:8C:16:6B:3A, 2015-05-27 19:28:44, 2015-05-27 19:28:46, 6, 54e,WEP, WEP, , -58, 2' \ + ', 0, 0. 0. 0. 0, 9, Test Router Please Ignore, '.split(',') target = Target(fields) wep = AttackWEP(target) wep.run() diff --git a/wifite/attack/wpa.py b/wifite/attack/wpa.py index 265378ccd..b2755feab 100755 --- a/wifite/attack/wpa.py +++ b/wifite/attack/wpa.py @@ -29,8 +29,8 @@ def run(self): # Skip if target is not WPS if Configuration.wps_only and self.target.wps is False: - Color.pl( - '\r{!} {O}Skipping WPA-Handshake attack on {R}%s{O} because {R}--wps-only{O} is set{W}' % self.target.essid) + Color.pl('\r{!} {O}Skipping WPA-Handshake attack on {R}%s{O} because {R}--wps-only{O} is set{W}' + % self.target.essid) self.success = False return self.success @@ -68,8 +68,8 @@ def run(self): self.success = False return False - Color.pl('\n{+} {C}Cracking WPA Handshake:{W} Running {C}aircrack-ng{W} with' + - ' {C}%s{W} wordlist' % os.path.split(Configuration.wordlist)[-1]) + Color.pl('\n{+} {C}Cracking WPA Handshake:{W} Running {C}aircrack-ng{W} with ' + '{C}%s{W} wordlist' % os.path.split(Configuration.wordlist)[-1]) # Crack it key = Aircrack.crack_handshake(handshake, show_command=False) @@ -258,8 +258,8 @@ def deauth(self, target): Configuration.initialize(True) from ..model.target import Target - fields = 'A4:2B:8C:16:6B:3A, 2015-05-27 19:28:44, 2015-05-27 19:28:46, 11, 54e,WPA, WPA, , -58, 2, 0, 0. 0. 0. 0, 9, Test Router Please Ignore, '.split( - ',') + fields = 'A4:2B:8C:16:6B:3A, 2015-05-27 19:28:44, 2015-05-27 19:28:46, 11, 54e,WPA, WPA, , -58, 2' \ + ', 0, 0. 0. 0. 0, 9, Test Router Please Ignore, '.split(',') target = Target(fields) wpa = AttackWPA(target) try: diff --git a/wifite/attack/wps.py b/wifite/attack/wps.py index 7af259e89..d0e17054b 100755 --- a/wifite/attack/wps.py +++ b/wifite/attack/wps.py @@ -34,8 +34,7 @@ def run(self): return False if not Configuration.wps_pixie and self.pixie_dust: - Color.pl('\r{!} {O}--no-pixie{R} was given, ignoring WPS Pixie-Dust Attack ' + - 'on {O}%s{W}' % self.target.essid) + Color.pl('\r{!} {O}--no-pixie{R} was given, ignoring WPS Pixie-Dust Attack on {O}%s{W}' % self.target.essid) self.success = False return False diff --git a/wifite/config.py b/wifite/config.py index 0e23fcbe1..ce693e089 100755 --- a/wifite/config.py +++ b/wifite/config.py @@ -276,8 +276,7 @@ def parse_settings_args(cls, args): if args.random_mac: cls.random_mac = True - Color.pl('{+} {C}option:{W} using {G}random mac address{W} ' + - 'when scanning & attacking') + Color.pl('{+} {C}option:{W} using {G}random mac address{W} when scanning & attacking') if args.channel: chn_arg_re = re.compile("^\d+((,\d+)|(-\d+,\d+))*(-\d+)?$") @@ -285,18 +284,15 @@ def parse_settings_args(cls, args): raise ValueError("Invalid channel! The format must be 1,3-6,9") cls.target_channel = args.channel - Color.pl('{+} {C}option:{W} scanning for targets on channel ' + - '{G}%s{W}' % args.channel) + Color.pl('{+} {C}option:{W} scanning for targets on channel {G}%s{W}' % args.channel) if args.interface: cls.interface = args.interface - Color.pl('{+} {C}option:{W} using wireless interface ' + - '{G}%s{W}' % args.interface) + Color.pl('{+} {C}option:{W} using wireless interface {G}%s{W}' % args.interface) if args.target_bssid: cls.target_bssid = args.target_bssid - Color.pl('{+} {C}option:{W} targeting BSSID ' + - '{G}%s{W}' % args.target_bssid) + Color.pl('{+} {C}option:{W} targeting BSSID {G}%s{W}' % args.target_bssid) if args.all_bands: cls.all_bands = True @@ -328,8 +324,7 @@ def parse_settings_args(cls, args): if args.no_deauth: cls.no_deauth = True - Color.pl('{+} {C}option:{W} will {R}not{W} {O}deauth{W} clients ' + - 'during scans or captures') + Color.pl('{+} {C}option:{W} will {R}not{W} {O}deauth{W} clients during scans or captures') if args.daemon is True: cls.daemon = True @@ -410,8 +405,8 @@ def parse_wep_args(cls, args): if args.wep_restart_stale_ivs: cls.wep_restart_stale_ivs = args.wep_restart_stale_ivs - Color.pl( - '{+} {C}option:{W} will restart aireplay after {G}%d seconds{W} of no new IVs' % args.wep_restart_stale_ivs) + Color.pl('{+} {C}option:{W} will restart aireplay after {G}%d seconds{W} of no new IVs' + % args.wep_restart_stale_ivs) if args.wep_restart_aircrack: cls.wep_restart_aircrack = args.wep_restart_aircrack @@ -470,7 +465,7 @@ def parse_wps_args(cls, args): if args.wps_only: cls.wps_only = True cls.wps_filter = True # Also only show WPS networks - Color.pl('{+} {C}option:{W} will *only* attack WPS networks with ' + + Color.pl('{+} {C}option:{W} will *only* attack WPS networks with ' '{G}WPS attacks{W} (avoids handshake and PMKID)') if args.no_wps: @@ -568,9 +563,7 @@ def parse_encryption(cls): # Default to scan all types cls.encryption_filter = ['WEP', 'WPA', 'WPS'] else: - Color.pl('{+} {C}option:{W} ' + - 'targeting {G}%s-encrypted{W} networks' - % '/'.join(cls.encryption_filter)) + Color.pl('{+} {C}option:{W} targeting {G}%s-encrypted{W} networks' % '/'.join(cls.encryption_filter)) @classmethod def parse_wep_attacks(cls): @@ -626,7 +619,8 @@ def create_temp(): @classmethod def delete_temp(cls): """ Remove temp files and folder """ - if cls.temp_dir is None: return + if cls.temp_dir is None: + return if os.path.exists(cls.temp_dir): for f in os.listdir(cls.temp_dir): os.remove(cls.temp_dir + f) @@ -641,8 +635,7 @@ def exit_gracefully(cls, code=0): if cls.interface is not None and Airmon.base_interface is not None: if not cls.daemon: Color.pl('{!} {O}Note:{W} Leaving interface in Monitor Mode!') - Color.pl('{!} To disable Monitor Mode when finished: ' + - '{C}airmon-ng stop %s{W}' % cls.interface) + Color.pl('{!} To disable Monitor Mode when finished: {C}airmon-ng stop %s{W}' % cls.interface) else: # Stop monitor mode diff --git a/wifite/model/client.py b/wifite/model/client.py index 729630412..134743884 100755 --- a/wifite/model/client.py +++ b/wifite/model/client.py @@ -37,6 +37,7 @@ def __str__(self): if __name__ == '__main__': - fields = 'AA:BB:CC:DD:EE:FF, 2015-05-27 19:43:47, 2015-05-27 19:43:47, -67, 2, (not associated) ,HOME-ABCD'.split(',') + fields = 'AA:BB:CC:DD:EE:FF, 2015-05-27 19:43:47, 2015-05-27 19:43:47, -67, 2,' \ + ' (not associated) ,HOME-ABCD'.split(',') c = Client(fields) print(('Client', c)) diff --git a/wifite/model/handshake.py b/wifite/model/handshake.py index 1fcdb46c0..a4a2712d2 100755 --- a/wifite/model/handshake.py +++ b/wifite/model/handshake.py @@ -46,8 +46,8 @@ def divine_bssid_and_essid(self): # HACK: Just use the first one we see self.bssid = pairs[0][0] self.essid = pairs[0][1] - Color.pl('{!} {O}Warning{W}: {O}Arbitrarily selected ' + - '{R}bssid{O} {C}%s{O} and {R}essid{O} "{C}%s{O}"{W}' % (self.bssid, self.essid)) + Color.pl('{!} {O}Warning{W}: {O}Arbitrarily selected {R}bssid{O} {C}%s{O} and {R}essid{O} "{C}%s{O}"{W}' + % (self.bssid, self.essid)) elif not self.bssid: # We already know essid @@ -69,8 +69,10 @@ def has_handshake(self): if not self.bssid or not self.essid: self.divine_bssid_and_essid() - if len(self.tshark_handshakes()) > 0: return True - if len(self.pyrit_handshakes()) > 0: return True + if len(self.tshark_handshakes()) > 0: + return True + if len(self.pyrit_handshakes()) > 0: + return True # TODO: Can we trust cowpatty & aircrack? # if len(self.cowpatty_handshakes()) > 0: return True @@ -189,7 +191,7 @@ def check(): Color.pl('{+} checking all handshakes in {G}"./hs"{W} directory\n') try: capfiles = [os.path.join('hs', x) for x in os.listdir('hs') if x.endswith('.cap')] - except OSError as e: + except OSError: capfiles = [] if not capfiles: Color.pl('{!} {R}no .cap files found in {O}"./hs"{W}\n') diff --git a/wifite/model/target.py b/wifite/model/target.py index f00ecd3f4..794754b6f 100755 --- a/wifite/model/target.py +++ b/wifite/model/target.py @@ -183,8 +183,8 @@ def to_str(self, show_bssid=False, show_manufacturer=False): # Unknown ESSID essid = Color.s('{O}%s' % essid) - if self.power < self.max_power: - var = self.max_power + # if self.power < self.max_power: + # var = self.max_power # Add a '*' if we decloaked the ESSID decloaked_char = '*' if self.decloaked else ' ' @@ -250,8 +250,8 @@ def to_str(self, show_bssid=False, show_manufacturer=False): if __name__ == '__main__': - fields = 'AA:BB:CC:DD:EE:FF,2015-05-27 19:28:44,2015-05-27 19:28:46,1,54,WPA2,CCMP TKIP,PSK,-58,2,0,0.0.0.0,9,HOME-ABCD,'.split( - ',') + fields = 'AA:BB:CC:DD:EE:FF,2015-05-27 19:28:44,2015-05-27 19:28:46,1,54,WPA2,CCMP ' \ + 'TKIP,PSK,-58,2,0,0.0.0.0,9,HOME-ABCD,'.split(',') t = Target(fields) t.clients.append('asdf') t.clients.append('asdf') diff --git a/wifite/tools/aircrack.py b/wifite/tools/aircrack.py index 0d5283d29..10aa3ca69 100755 --- a/wifite/tools/aircrack.py +++ b/wifite/tools/aircrack.py @@ -1,14 +1,13 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -from .dependency import Dependency -from ..util.process import Process -from ..util.input import xrange -from ..config import Configuration - import os import re +from .dependency import Dependency +from ..config import Configuration +from ..util.process import Process + class Aircrack(Dependency): dependency_required = True diff --git a/wifite/tools/aireplay.py b/wifite/tools/aireplay.py index 1900d1fa9..6b207db1e 100755 --- a/wifite/tools/aireplay.py +++ b/wifite/tools/aireplay.py @@ -135,7 +135,10 @@ def run(self): self.status = None # Reset elif 'Got a deauthentication packet!' in line: self.status = False - elif 'Sending Authentication Request ' not in line and 'Please specify an ESSID' not in line and 'Got a deauthentication packet!' not in line and 'association successful :-)' in line.lower(): + elif 'Sending Authentication Request ' not in line \ + and 'Please specify an ESSID' not in line \ + and 'Got a deauthentication packet!' not in line \ + and 'association successful :-)' in line.lower(): self.status = True elif self.attack_type == WEPAttackType.chopchop: # Look for chopchop status. Potential output lines: @@ -207,15 +210,14 @@ def run(self): saving_re = re.compile(r'Saving keystream in (.*\.xor)') if matches := saving_re.match(line): self.status = f'saving keystream to {matches[1]}' - # XX:XX:XX Now you can build a packet with packetforge-ng out of that 1500 bytes keystream else: # Replay, forged replay, etc. # Parse Packets Sent & PacketsPerSecond. Possible output lines: # Read 55 packets (got 0 ARP requests and 0 ACKs), sent 0 packets...(0 pps) # Read 4467 packets (got 1425 ARP requests and 1417 ACKs), sent 1553 packets...(100 pps) - read_re = re.compile( - r'Read (\d+) packets \(got (\d+) ARP requests and (\d+) ACKs\), sent (\d+) packets...\((\d+) pps\)') + read_re = re.compile(r'Read (\d+) packets \(got (\d+) ARP requests ' + r'and (\d+) ACKs\), sent (\d+) packets...\((\d+) pps\)') if matches := read_re.match(line): pps = matches[5] if pps == '0': diff --git a/wifite/tools/airmon.py b/wifite/tools/airmon.py index df4337e0c..c7b7ac9b9 100755 --- a/wifite/tools/airmon.py +++ b/wifite/tools/airmon.py @@ -1,17 +1,16 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +import os +import re +import signal + from .dependency import Dependency from .ip import Ip from .iw import Iw -from ..util.process import Process -from ..util.color import Color -from ..util.input import raw_input from ..config import Configuration - -import re -import os -import signal +from ..util.color import Color +from ..util.process import Process class AirmonIface(object): @@ -45,7 +44,8 @@ def menu_header(): s += 'Driver'.ljust(AirmonIface.DRIVER_LEN) s += 'Chipset'.ljust(AirmonIface.CHIPSET_LEN) s += '\n' - s += '-' * (AirmonIface.INTERFACE_LEN + AirmonIface.PHY_LEN + AirmonIface.DRIVER_LEN + AirmonIface.CHIPSET_LEN + 3) + s += '-' * \ + (AirmonIface.INTERFACE_LEN + AirmonIface.PHY_LEN + AirmonIface.DRIVER_LEN + AirmonIface.CHIPSET_LEN + 3) return s diff --git a/wifite/tools/bully.py b/wifite/tools/bully.py index f9e06dac6..e2d8d1f73 100755 --- a/wifite/tools/bully.py +++ b/wifite/tools/bully.py @@ -242,7 +242,7 @@ def parse_crack_result(self, line): def parse_state(self, line): # sourcery no-metrics state = self.state - if got_beacon := re.search(r".*Got beacon for '(.*)' \((.*)\)", line): + if re.search(r".*Got beacon for '(.*)' \((.*)\)", line): # group(1)=ESSID, group(2)=BSSID state = 'Got beacon' @@ -300,10 +300,10 @@ def parse_state(self, line): # sourcery no-metrics sleeping = re_lockout[1] state = '{R}WPS Lock-out: {O}Waiting %s seconds...{W}' % sleeping - if re_pin_not_found := re.search(r".*\[Pixie-Dust] WPS pin not found", line): + if re.search(r".*\[Pixie-Dust] WPS pin not found", line): state = '{R}Failed: {O}Bully says "WPS pin not found"{W}' - if re_running_pixiewps := re.search(r".*Running pixiewps with the information", line): + if re.search(r".*Running pixiewps with the information", line): state = '{G}Running pixiewps...{W}' return state @@ -349,18 +349,17 @@ def get_psk_from_pin(target, pin): Configuration.interface = 'wlan0mon' from ..model.target import Target - fields = '34:21:09:01:92:7C,2015-05-27 19:28:44,2015-05-27 19:28:46,1,54,WPA2,CCMP TKIP,PSK,-58,2,0,0.0.0.0,9,AirLink89300,'.split( - ',') + fields = '34:21:09:01:92:7C,2015-05-27 19:28:44,2015-05-27 ' \ + '19:28:46,1,54,WPA2,CCMP TKIP,PSK,-58,2,0,0.0.0.0,9,AirLink89300,'.split(',') target = Target(fields) psk = Bully.get_psk_from_pin(target, '01030365') print(('psk', psk)) - ''' - stdout = " [*] Pin is '11867722', key is '9a6f7997'" - Configuration.initialize(False) - from ..model.target import Target - fields = 'AA:BB:CC:DD:EE:FF,2015-05-27 19:28:44,2015-05-27 19:28:46,1,54,WPA2,CCMP TKIP,PSK,-58,2,0,0.0.0.0,9,HOME-ABCD,'.split(',') - target = Target(fields) - b = Bully(target) - b.parse_line(stdout) - ''' + # stdout = " [*] Pin is '11867722', key is '9a6f7997'" + # Configuration.initialize(False) + # from ..model.target import Target + # fields = 'AA:BB:CC:DD:EE:FF,2015-05-27 19:28:44,2015-05-27 19:28:46,1,54,WPA2,' \ + # 'CCMP TKIP,PSK,-58,2,0,0.0.0.0,9,HOME-ABCD,'.split(',') + # target = Target(fields) + # b = Bully(target) + # b.parse_line(stdout) diff --git a/wifite/tools/hashcat.py b/wifite/tools/hashcat.py index 2add9bf6d..6ca43cefe 100755 --- a/wifite/tools/hashcat.py +++ b/wifite/tools/hashcat.py @@ -25,8 +25,7 @@ def should_use_force(): @staticmethod def crack_handshake(handshake, show_command=False): # Generate hccapx - hccapx_file = HcxPcapngTool.generate_hccapx_file( - handshake, show_command=show_command) + hccapx_file = HcxPcapngTool.generate_hccapx_file(handshake, show_command=show_command) key = None # Crack hccapx diff --git a/wifite/tools/john.py b/wifite/tools/john.py index f7268ffe8..6e5dbd2c1 100755 --- a/wifite/tools/john.py +++ b/wifite/tools/john.py @@ -31,7 +31,6 @@ def crack_handshake(handshake, show_command=False): # Crack john file command = ['john', f'--format={john_format}', '--wordlist', Configuration.wordlist, john_file] - if show_command: Color.pl('{+} {D}Running: {W}{P}%s{W}' % ' '.join(command)) process = Process(command) @@ -56,4 +55,4 @@ def crack_handshake(handshake, show_command=False): if os.path.exists(john_file): os.remove(john_file) - # return key + return key diff --git a/wifite/tools/reaver.py b/wifite/tools/reaver.py index 9121f3104..843c8c111 100755 --- a/wifite/tools/reaver.py +++ b/wifite/tools/reaver.py @@ -420,7 +420,15 @@ def get_output(self): [*] Time taken: 0 s 21 ms -executing pixiewps -e d0141b15656e96b85fcead2e8e76330d2b1ac1576bb026e7a328c0e1baf8cf91664371174c08ee12ec92b0519c54879f21255be5a8770e1fa1880470ef423c90e34d7847a6fcb4924563d1af1db0c481ead9852c519bf1dd429c163951cf69181b132aea2a3684caf35bc54aca1b20c88bb3b7339ff7d56e09139d77f0ac58079097938251dbbe75e86715cc6b7c0ca945fa8dd8d661beb73b414032798dadee32b5dd61bf105f18d89217760b75c5d966a5a490472ceba9e3b4224f3d89fb2b -s 5a67001334e3e4cb236f4e134a4d3b48d625a648e991f978d9aca879469d5da5 -z c8a2ccc5fb6dc4f4d69b245091022dc7e998e42ec1d548d57c35a312ff63ef20 -a 60b59c0c587c6c44007f7081c3372489febbe810a97483f5cc5cd8463c3920de -n 04d48dc20ec785762ce1a21a50bc46c2 -r 7a191e22a7b519f40d3af21b93a21d4f837718b45063a8a69ac6d16c6e5203477c18036ca01e9e56d0322e70c2e1baa66518f1b46d01acc577d1dfa34efd2e9ee36e2b7e68819cddacceb596a8895243e33cb48c570458a539dcb523a4d4c4360e158c29b882f7f385821ea043705eb56538b45daa445157c84e60fc94ef48136eb4e9725b134902b96c90b1ae54cbd42b29b52611903fdae5aa88bfc320f173d2bbe31df4996ebdb51342c6b8bd4e82ae5aa80b2a09a8bf8faa9a8332dc9819 +executing pixiewps -e d0141b15656e96b85fcead2e8e76330d2b1ac1576bb026e7a328c0e1baf8cf91664371174c08ee12ec92b0519c548 +79f21255be5a8770e1fa1880470ef423c90e34d7847a6fcb4924563d1af1db0c481ead9852c519bf1dd429c163951cf69181b132aea2a3684ca +f35bc54aca1b20c88bb3b7339ff7d56e09139d77f0ac58079097938251dbbe75e86715cc6b7c0ca945fa8dd8d661beb73b414032798dadee32b +5dd61bf105f18d89217760b75c5d966a5a490472ceba9e3b4224f3d89fb2b -s 5a67001334e3e4cb236f4e134a4d3b48d625a648e991f978d9 +aca879469d5da5 -z c8a2ccc5fb6dc4f4d69b245091022dc7e998e42ec1d548d57c35a312ff63ef20 -a 60b59c0c587c6c44007f7081c3372 +489febbe810a97483f5cc5cd8463c3920de -n 04d48dc20ec785762ce1a21a50bc46c2 -r 7a191e22a7b519f40d3af21b93a21d4f837718b4 +5063a8a69ac6d16c6e5203477c18036ca01e9e56d0322e70c2e1baa66518f1b46d01acc577d1dfa34efd2e9ee36e2b7e68819cddacceb596a88 +95243e33cb48c570458a539dcb523a4d4c4360e158c29b882f7f385821ea043705eb56538b45daa445157c84e60fc94ef48136eb4e9725b1349 +02b96c90b1ae54cbd42b29b52611903fdae5aa88bfc320f173d2bbe31df4996ebdb51342c6b8bd4e82ae5aa80b2a09a8bf8faa9a8332dc9819 ''' pin_attack_stdout = ''' [+] Pin cracked in 16 seconds diff --git a/wifite/tools/tshark.py b/wifite/tools/tshark.py index 4458f3bd3..65d8881e8 100755 --- a/wifite/tools/tshark.py +++ b/wifite/tools/tshark.py @@ -67,7 +67,8 @@ def _build_target_client_handshake_map(output, bssid=None): if index == 1: target_client_msg_nums[target_client_key] = 1 # First message - elif target_client_key not in target_client_msg_nums or index - 1 != target_client_msg_nums[target_client_key]: + elif target_client_key not in target_client_msg_nums \ + or index - 1 != target_client_msg_nums[target_client_key]: continue # Not first message. We haven't gotten the first message yet. Skip. else: diff --git a/wifite/util/color.py b/wifite/util/color.py index cb3c31701..fb564f586 100755 --- a/wifite/util/color.py +++ b/wifite/util/color.py @@ -39,7 +39,7 @@ def p(text): sys.stdout.write(Color.s(text)) sys.stdout.flush() if '\r' in text: - text = text[text.rfind('\r')+1:] + text = text[text.rfind('\r') + 1:] Color.last_sameline_length = len(text) else: Color.last_sameline_length += len(text) diff --git a/wifite/util/crack.py b/wifite/util/crack.py index 928af73e4..bfcece482 100755 --- a/wifite/util/crack.py +++ b/wifite/util/crack.py @@ -1,21 +1,19 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +import os +from json import loads + from ..config import Configuration from ..model.handshake import Handshake -from ..model.wpa_result import CrackResultWPA from ..model.pmkid_result import CrackResultPMKID -from ..util.process import Process -from ..util.color import Color -from ..util.input import raw_input +from ..model.wpa_result import CrackResultWPA from ..tools.aircrack import Aircrack from ..tools.cowpatty import Cowpatty from ..tools.hashcat import Hashcat, HcxPcapngTool from ..tools.john import John - -from json import loads - -import os +from ..util.color import Color +from ..util.process import Process # TODO: Bring back the 'print' option, for easy copy/pasting. Just one-liners people can paste into terminal. @@ -214,8 +212,8 @@ def get_user_selection(cls, handshakes): cls.print_handshakes(handshakes) Color.p( - '{+} Select handshake(s) to crack ({G}%d{W}-{G}%d{W}, select multiple with {C},{W} or {C}-{W} or {C}all{W}): {G}' % ( - 1, len(handshakes))) + '{+} Select handshake(s) to crack ({G}%d{W}-{G}%d{W}, select multiple with ' + '{C},{W} or {C}-{W} or {C}all{W}): {G}' % (1, len(handshakes))) choices = input() Color.p('{W}') diff --git a/wifite/util/process.py b/wifite/util/process.py index 3b7b2a080..58bf2faea 100755 --- a/wifite/util/process.py +++ b/wifite/util/process.py @@ -40,8 +40,10 @@ def call(command, cwd=None, shell=False): (stdout, stderr) = pid.communicate() # Python 3 compatibility - if type(stdout) is bytes: stdout = stdout.decode('utf-8') - if type(stderr) is bytes: stderr = stderr.decode('utf-8') + if type(stdout) is bytes: + stdout = stdout.decode('utf-8') + if type(stderr) is bytes: + stderr = stderr.decode('utf-8') 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'))) diff --git a/wifite/util/scanner.py b/wifite/util/scanner.py index 0250367b8..330ac8f6f 100755 --- a/wifite/util/scanner.py +++ b/wifite/util/scanner.py @@ -1,13 +1,12 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -from ..util.color import Color -from ..tools.airodump import Airodump -from ..util.input import raw_input, xrange -from ..config import Configuration - from time import sleep, time +from ..config import Configuration +from ..tools.airodump import Airodump +from ..util.color import Color + class Scanner(object): """ Scans wifi networks & provides menu for selecting targets """ @@ -74,8 +73,6 @@ def find_targets(self): if not Configuration.infinite_mode: return True - from ..util.input import raw_input - options = '({G}s{W}{D}, {W}{R}e{W})' prompt = '{+} Do you want to {G}start attacking{W} or {R}exit{W}%s?' % options