Use enums to describe target WPS state.
To avoid confusion about wps = True/False/None. Came about because of #130
This commit is contained in:
@@ -5,6 +5,11 @@ from ..util.color import Color
|
|||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
class WPSState:
|
||||||
|
NONE, UNLOCKED, LOCKED, UNKNOWN = range(0, 4)
|
||||||
|
|
||||||
|
|
||||||
class Target(object):
|
class Target(object):
|
||||||
'''
|
'''
|
||||||
Holds details for a 'Target' aka Access Point (e.g. router).
|
Holds details for a 'Target' aka Access Point (e.g. router).
|
||||||
@@ -60,8 +65,7 @@ class Target(object):
|
|||||||
self.essid = None # '(%s)' % self.bssid
|
self.essid = None # '(%s)' % self.bssid
|
||||||
self.essid_known = False
|
self.essid_known = False
|
||||||
|
|
||||||
# False=No WPS, None=Locked WPS, True=Unlocked WPS
|
self.wps = WPSState.UNKNOWN
|
||||||
self.wps = False
|
|
||||||
|
|
||||||
self.decloaked = False # If ESSID was hidden but we decloaked it.
|
self.decloaked = False # If ESSID was hidden but we decloaked it.
|
||||||
|
|
||||||
@@ -133,13 +137,14 @@ class Target(object):
|
|||||||
color = 'R'
|
color = 'R'
|
||||||
power = Color.s('{%s}%s' % (color, power))
|
power = Color.s('{%s}%s' % (color, power))
|
||||||
|
|
||||||
wps = Color.s('{O} n/a')
|
if self.wps == WPSState.UNLOCKED:
|
||||||
if self.wps == True:
|
|
||||||
wps = Color.s('{G} yes')
|
wps = Color.s('{G} yes')
|
||||||
elif self.wps == False:
|
elif self.wps == WPSState.NONE:
|
||||||
wps = Color.s('{O} no')
|
wps = Color.s('{O} no')
|
||||||
elif self.wps is None:
|
elif self.wps == WPSState.LOCKED:
|
||||||
wps = Color.s('{R}lock')
|
wps = Color.s('{R}lock')
|
||||||
|
elif self.wps == WPSState.UNKNOWN:
|
||||||
|
wps = Color.s('{O} n/a')
|
||||||
|
|
||||||
clients = ' '
|
clients = ' '
|
||||||
if len(self.clients) > 0:
|
if len(self.clients) > 0:
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from .tshark import Tshark
|
|||||||
from .wash import Wash
|
from .wash import Wash
|
||||||
from ..util.process import Process
|
from ..util.process import Process
|
||||||
from ..config import Configuration
|
from ..config import Configuration
|
||||||
from ..model.target import Target
|
from ..model.target import Target, WPSState
|
||||||
from ..model.client import Client
|
from ..model.client import Client
|
||||||
|
|
||||||
import os, time
|
import os, time
|
||||||
@@ -18,7 +18,8 @@ class Airodump(Dependency):
|
|||||||
dependency_url = 'https://www.aircrack-ng.org/install.html'
|
dependency_url = 'https://www.aircrack-ng.org/install.html'
|
||||||
|
|
||||||
def __init__(self, interface=None, channel=None, encryption=None,\
|
def __init__(self, interface=None, channel=None, encryption=None,\
|
||||||
wps=False, target_bssid=None, output_file_prefix='airodump',\
|
wps=WPSState.UNKNOWN, target_bssid=None,
|
||||||
|
output_file_prefix='airodump',\
|
||||||
ivs_only=False, skip_wps=False, delete_existing_files=True):
|
ivs_only=False, skip_wps=False, delete_existing_files=True):
|
||||||
'''Sets up airodump arguments, doesn't start process yet.'''
|
'''Sets up airodump arguments, doesn't start process yet.'''
|
||||||
|
|
||||||
@@ -260,7 +261,7 @@ class Airodump(Dependency):
|
|||||||
result.append(target)
|
result.append(target)
|
||||||
elif 'WPA' in Configuration.encryption_filter and 'WPA' in target.encryption:
|
elif 'WPA' in Configuration.encryption_filter and 'WPA' in target.encryption:
|
||||||
result.append(target)
|
result.append(target)
|
||||||
elif 'WPS' in Configuration.encryption_filter and target.wps != False:
|
elif 'WPS' in Configuration.encryption_filter and target.wps in [WPSState.UNLOCKED, WPSState.LOCKED]:
|
||||||
result.append(target)
|
result.append(target)
|
||||||
elif skip_wps:
|
elif skip_wps:
|
||||||
result.append(target)
|
result.append(target)
|
||||||
|
|||||||
@@ -134,7 +134,8 @@ class Bully(Attack, Dependency):
|
|||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
if self.locked and not Configuration.wps_ignore_lock:
|
if self.locked and not Configuration.wps_ignore_lock:
|
||||||
self.pattack('{R}Failed: {O}AP became {R}Locked{O}', newline=True)
|
self.pattack('{R}Failed: {O}Access point is {R}Locked{O}',
|
||||||
|
newline=True)
|
||||||
self.stop()
|
self.stop()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ class Reaver(Attack, Dependency):
|
|||||||
|
|
||||||
# Check if locked
|
# Check if locked
|
||||||
if self.locked and not Configuration.wps_ignore_lock:
|
if self.locked and not Configuration.wps_ignore_lock:
|
||||||
raise Exception('{O}Because access point is {R}Locked{W}')
|
raise Exception('{O}Access point is {R}Locked{W}')
|
||||||
|
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from .dependency import Dependency
|
from .dependency import Dependency
|
||||||
|
from ..model.target import WPSState
|
||||||
from ..util.process import Process
|
from ..util.process import Process
|
||||||
import re
|
import re
|
||||||
|
|
||||||
@@ -188,7 +189,6 @@ class Tshark(Dependency):
|
|||||||
if ',' not in line:
|
if ',' not in line:
|
||||||
continue
|
continue
|
||||||
bssid, locked = line.split(',')
|
bssid, locked = line.split(',')
|
||||||
# Ignore if WPS is locked?
|
|
||||||
if '1' not in locked:
|
if '1' not in locked:
|
||||||
wps_bssids.add(bssid.upper())
|
wps_bssids.add(bssid.upper())
|
||||||
else:
|
else:
|
||||||
@@ -197,11 +197,11 @@ class Tshark(Dependency):
|
|||||||
for t in targets:
|
for t in targets:
|
||||||
target_bssid = t.bssid.upper()
|
target_bssid = t.bssid.upper()
|
||||||
if target_bssid in wps_bssids:
|
if target_bssid in wps_bssids:
|
||||||
t.wps = True
|
t.wps = WPSState.UNLOCKED
|
||||||
elif target_bssid in locked_bssids:
|
elif target_bssid in locked_bssids:
|
||||||
t.wps = None
|
t.wps = WPSState.LOCKED
|
||||||
else:
|
else:
|
||||||
t.wps = False
|
t.wps = WPSState.NONE
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
@@ -224,7 +224,8 @@ if __name__ == '__main__':
|
|||||||
# Should update 'wps' field of a target
|
# Should update 'wps' field of a target
|
||||||
Tshark.check_for_wps_and_update_targets(test_file, targets)
|
Tshark.check_for_wps_and_update_targets(test_file, targets)
|
||||||
|
|
||||||
print('Target(BSSID={}).wps = {} (Expected: True)'.format(targets[0].bssid, targets[0].wps))
|
print('Target(BSSID={}).wps = {} (Expected: 1)'.format(
|
||||||
assert targets[0].wps == True
|
targets[0].bssid, targets[0].wps))
|
||||||
|
assert targets[0].wps == WPSState.UNLOCKED
|
||||||
|
|
||||||
print(Tshark.bssids_with_handshakes(test_file, bssid=target_bssid))
|
print(Tshark.bssids_with_handshakes(test_file, bssid=target_bssid))
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from .dependency import Dependency
|
from .dependency import Dependency
|
||||||
|
from ..model.target import WPSState
|
||||||
from ..util.process import Process
|
from ..util.process import Process
|
||||||
import json
|
import json
|
||||||
|
|
||||||
@@ -53,11 +54,11 @@ class Wash(Dependency):
|
|||||||
for t in targets:
|
for t in targets:
|
||||||
target_bssid = t.bssid.upper()
|
target_bssid = t.bssid.upper()
|
||||||
if target_bssid in wps_bssids:
|
if target_bssid in wps_bssids:
|
||||||
t.wps = True
|
t.wps = WPSState.UNLOCKED
|
||||||
elif target_bssid in locked_bssids:
|
elif target_bssid in locked_bssids:
|
||||||
t.wps = None
|
t.wps = WPSState.LOCKED
|
||||||
else:
|
else:
|
||||||
t.wps = False
|
t.wps = WPSState.NONE
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
@@ -80,7 +81,8 @@ if __name__ == '__main__':
|
|||||||
# Should update 'wps' field of a target
|
# Should update 'wps' field of a target
|
||||||
Wash.check_for_wps_and_update_targets(test_file, targets)
|
Wash.check_for_wps_and_update_targets(test_file, targets)
|
||||||
|
|
||||||
print('Target(BSSID={}).wps = {} (Expected: True)'.format(targets[0].bssid, targets[0].wps))
|
print('Target(BSSID={}).wps = {} (Expected: 1)'.format(
|
||||||
|
targets[0].bssid, targets[0].wps))
|
||||||
|
|
||||||
assert targets[0].wps == True
|
assert targets[0].wps == WPSState.UNLOCKED
|
||||||
|
|
||||||
|
|||||||
@@ -97,6 +97,10 @@ class Color(object):
|
|||||||
'''Prints an exception. Includes stack trace if necessary.'''
|
'''Prints an exception. Includes stack trace if necessary.'''
|
||||||
Color.pl('\n{!} {R}Error: {O}%s' % str(exception))
|
Color.pl('\n{!} {R}Error: {O}%s' % str(exception))
|
||||||
|
|
||||||
|
# Don't dump trace for the "no targets found" case.
|
||||||
|
if 'No targets found' in str(exception):
|
||||||
|
return
|
||||||
|
|
||||||
from ..config import Configuration
|
from ..config import Configuration
|
||||||
if Configuration.verbose > 0 or Configuration.print_stack_traces:
|
if Configuration.verbose > 0 or Configuration.print_stack_traces:
|
||||||
Color.pl('\n{!} {O}Full stack trace below')
|
Color.pl('\n{!} {O}Full stack trace below')
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
from ..util.color import Color
|
from ..util.color import Color
|
||||||
from ..tools.airodump import Airodump
|
from ..tools.airodump import Airodump
|
||||||
from ..util.input import raw_input, xrange
|
from ..util.input import raw_input, xrange
|
||||||
from ..model.target import Target
|
from ..model.target import Target, WPSState
|
||||||
from ..config import Configuration
|
from ..config import Configuration
|
||||||
|
|
||||||
from time import sleep, time
|
from time import sleep, time
|
||||||
@@ -88,7 +88,7 @@ class Scanner(object):
|
|||||||
return False # No specific target from user.
|
return False # No specific target from user.
|
||||||
|
|
||||||
for target in self.targets:
|
for target in self.targets:
|
||||||
if Configuration.wps_only and target.wps == False:
|
if Configuration.wps_only and target.wps not in [WPSState.UNLOCKED, WPSState.LOCKED]:
|
||||||
continue
|
continue
|
||||||
if bssid and target.bssid and bssid.lower() == target.bssid.lower():
|
if bssid and target.bssid and bssid.lower() == target.bssid.lower():
|
||||||
self.target = target
|
self.target = target
|
||||||
|
|||||||
Reference in New Issue
Block a user