From 86fb6fba623b40fce5e30e6f7d82b685e9a084cb Mon Sep 17 00:00:00 2001 From: Michal Date: Sat, 25 Aug 2018 19:47:46 +0200 Subject: [PATCH 1/2] Another "Generator Expressions" improvements The is no need to create the lists for the functions, iterator is still enough --- wifite/model/result.py | 2 +- wifite/tools/airmon.py | 6 ++---- wifite/tools/dependency.py | 2 +- wifite/util/crack.py | 4 ++-- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/wifite/model/result.py b/wifite/model/result.py index 7dd6084f2..feac984c9 100755 --- a/wifite/model/result.py +++ b/wifite/model/result.py @@ -84,7 +84,7 @@ def display(cls): len(cracked_targets), name)) results = sorted([cls.load(item) for item in cracked_targets], key=lambda x: x.date, reverse=True) - longest_essid = max([len(result.essid or 'ESSID') for result in results]) + longest_essid = max(len(result.essid or 'ESSID') for result in results) # Header Color.p('{D} ') diff --git a/wifite/tools/airmon.py b/wifite/tools/airmon.py index 99f5b68ef..719fb3e67 100755 --- a/wifite/tools/airmon.py +++ b/wifite/tools/airmon.py @@ -344,10 +344,8 @@ def terminate_conflicting_processes(): if not Configuration.kill_conflicting_processes: # Don't kill processes, warn user - names_and_pids = ', '.join([ - '{R}%s{O} (PID {R}%s{O})' % (pname, pid) - for pid, pname in pid_pnames - ]) + names_and_pids = ', '.join('{R}%s{O} (PID {R}%s{O})' % (pname, pid) + for pid, pname in pid_pnames) Color.pl('{!} {O}Conflicting processes: %s' % names_and_pids) Color.pl('{!} {O}If you have problems: {R}kill -9 PID{O} or re-run wifite with {R}--kill{O}){W}') return diff --git a/wifite/tools/dependency.py b/wifite/tools/dependency.py index 556a10939..9b08be577 100755 --- a/wifite/tools/dependency.py +++ b/wifite/tools/dependency.py @@ -47,7 +47,7 @@ def run_dependency_check(cls): Macchanger ] - missing_required = any([app.fails_dependency_check() for app in apps]) + missing_required = any(app.fails_dependency_check() for app in apps) if missing_required: Color.pl('{!} {O}At least 1 Required app is missing. Wifite needs Required apps to run{W}') diff --git a/wifite/util/crack.py b/wifite/util/crack.py index 5a5b6a0fa..759b4fee5 100755 --- a/wifite/util/crack.py +++ b/wifite/util/crack.py @@ -53,7 +53,7 @@ def run(cls): return hs_to_crack = cls.get_user_selection(handshakes) - any_pmkid = any([hs['type'] == 'PMKID' for hs in hs_to_crack]) + any_pmkid = any(hs['type'] == 'PMKID' for hs in hs_to_crack) # Tools for cracking & their dependencies. available_tools = { @@ -76,7 +76,7 @@ def run(cls): if len(missing_tools) > 0: Color.pl('\n{!} {O}Unavailable tools (install to enable):{W}') for tool, deps in missing_tools: - dep_list = ', '.join([dep.dependency_name for dep in deps]) + dep_list = ', '.join(dep.dependency_name for dep in deps) Color.pl(' {R}* {R}%s {W}({O}%s{W})' % (tool, dep_list)) Color.p('\n{+} Enter the {C}cracking tool{W} to use ({C}%s{W}): {G}' % ( From 5f905109ba9a97dae1f8b039c068897f74952d62 Mon Sep 17 00:00:00 2001 From: Michal Date: Sat, 25 Aug 2018 21:20:19 +0200 Subject: [PATCH 2/2] Don't compare boolean values to True or False using == According to: https://www.python.org/dev/peps/pep-0008/ Don't compare boolean values to True or False using ==. Yes: if greeting: No: if greeting == True: Worse: if greeting is True: --- wifite/attack/all.py | 2 +- wifite/attack/pmkid.py | 4 ++-- wifite/attack/wpa.py | 4 ++-- wifite/config.py | 8 ++++---- wifite/model/target.py | 4 ++-- wifite/tools/airodump.py | 2 +- wifite/tools/wash.py | 2 +- wifite/util/scanner.py | 2 +- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/wifite/attack/all.py b/wifite/attack/all.py index 6fab55a03..5a274ad5e 100755 --- a/wifite/attack/all.py +++ b/wifite/attack/all.py @@ -54,7 +54,7 @@ def attack_single(cls, target, targets_remaining): # WPA can have multiple attack vectors: # WPS - if target.wps != False: + if target.wps: if Configuration.wps_pixie: attacks.append(AttackWPS(target, pixie_dust=True)) if Configuration.wps_pin: diff --git a/wifite/attack/pmkid.py b/wifite/attack/pmkid.py index 1cc75c138..7926001ff 100755 --- a/wifite/attack/pmkid.py +++ b/wifite/attack/pmkid.py @@ -63,7 +63,7 @@ def run(self): True if handshake is captured. False otherwise. ''' # Skip if user only wants to attack WPS targets - if Configuration.wps_only and self.target.wps == False: + if Configuration.wps_only and not self.target.wps: Color.pl('\r{!} {O}Skipping PMKID attack on {R}%s{O} because {R}--wps-only{O} is set{W}' % self.target.essid) self.success = False return False @@ -82,7 +82,7 @@ def run(self): pmkid_file = None - if Configuration.ignore_old_handshakes == False: + if not Configuration.ignore_old_handshakes: # Load exisitng PMKID hash from filesystem pmkid_file = self.get_existing_pmkid_file(self.target.bssid) if pmkid_file is not None: diff --git a/wifite/attack/wpa.py b/wifite/attack/wpa.py index 199965bbd..36bb260f5 100755 --- a/wifite/attack/wpa.py +++ b/wifite/attack/wpa.py @@ -28,7 +28,7 @@ def run(self): '''Initiates full WPA handshake capture attack.''' # Skip if target is not WPS - if Configuration.wps_only and self.target.wps == False: + if Configuration.wps_only and not self.target.wps: 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 @@ -96,7 +96,7 @@ def capture_handshake(self): self.clients = [] # Try to load existing handshake - if Configuration.ignore_old_handshakes == False: + if not Configuration.ignore_old_handshakes: bssid = airodump_target.bssid essid = airodump_target.essid if airodump_target.essid_known else None handshake = self.load_handshake(bssid=bssid, essid=essid) diff --git a/wifite/config.py b/wifite/config.py index 463e36142..368616be4 100755 --- a/wifite/config.py +++ b/wifite/config.py @@ -180,15 +180,15 @@ def parse_settings_args(cls, args): Color.pl('{+} {C}option:{W} targeting BSSID ' + '{G}%s{W}' % args.target_bssid) - if args.five_ghz == True: + if args.five_ghz: cls.five_ghz = True Color.pl('{+} {C}option:{W} including {G}5Ghz networks{W} in scans') - if args.show_bssids == True: + if args.show_bssidS: cls.show_bssids = True Color.pl('{+} {C}option:{W} showing {G}bssids{W} of targets during scan') - if args.no_deauth == True: + 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') @@ -207,7 +207,7 @@ def parse_settings_args(cls, args): Color.pl('{+} {C}option:{W} {O}ignoring ESSIDs that include {R}%s{W}' % ( args.ignore_essid)) - if args.clients_only == True: + if args.clients_only: cls.clients_only = True Color.pl('{+} {C}option:{W} {O}ignoring targets that do not have ' + 'associated clients') diff --git a/wifite/model/target.py b/wifite/model/target.py index 26e792506..0f5482157 100755 --- a/wifite/model/target.py +++ b/wifite/model/target.py @@ -134,9 +134,9 @@ def to_str(self, show_bssid=False): power = Color.s('{%s}%s' % (color, power)) wps = Color.s('{O} n/a') - if self.wps == True: + if self.wps: wps = Color.s('{G} yes') - elif self.wps == False: + elif not self.wps: wps = Color.s('{O} no') elif self.wps is None: wps = Color.s('{R}lock') diff --git a/wifite/tools/airodump.py b/wifite/tools/airodump.py index f85015e65..1ba18cda5 100755 --- a/wifite/tools/airodump.py +++ b/wifite/tools/airodump.py @@ -260,7 +260,7 @@ def filter_targets(targets, skip_wps=False): result.append(target) elif 'WPA' in Configuration.encryption_filter and 'WPA' in target.encryption: result.append(target) - elif 'WPS' in Configuration.encryption_filter and target.wps != False: + elif 'WPS' in Configuration.encryption_filter and target.wps: result.append(target) elif skip_wps: result.append(target) diff --git a/wifite/tools/wash.py b/wifite/tools/wash.py index 743e85eaf..e8c7a954d 100755 --- a/wifite/tools/wash.py +++ b/wifite/tools/wash.py @@ -45,7 +45,7 @@ def check_for_wps_and_update_targets(capfile, targets): obj = json.loads(line) bssid = obj['bssid'] locked = obj['wps_locked'] - if locked != True: + if not locked: wps_bssids.add(bssid) else: locked_bssids.add(bssid) diff --git a/wifite/util/scanner.py b/wifite/util/scanner.py index bdaf3b582..b602cf7ef 100755 --- a/wifite/util/scanner.py +++ b/wifite/util/scanner.py @@ -88,7 +88,7 @@ def found_target(self): return False # No specific target from user. for target in self.targets: - if Configuration.wps_only and target.wps == False: + if Configuration.wps_only and not target.wps: continue if bssid and target.bssid and bssid.lower() == target.bssid.lower(): self.target = target