Skip to content

Commit

Permalink
Use enums to describe target WPS state.
Browse files Browse the repository at this point in the history
To avoid confusion about wps = True/False/None.
Came about because of derv82#130
  • Loading branch information
derv82 committed Sep 9, 2018
1 parent 355f891 commit e190794
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 24 deletions.
17 changes: 11 additions & 6 deletions wifite/model/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

import re


class WPSState:
NONE, UNLOCKED, LOCKED, UNKNOWN = range(0, 4)


class Target(object):
'''
Holds details for a 'Target' aka Access Point (e.g. router).
Expand Down Expand Up @@ -60,8 +65,7 @@ def __init__(self, fields):
self.essid = None # '(%s)' % self.bssid
self.essid_known = False

# False=No WPS, None=Locked WPS, True=Unlocked WPS
self.wps = False
self.wps = WPSState.UNKNOWN

self.decloaked = False # If ESSID was hidden but we decloaked it.

Expand Down Expand Up @@ -133,13 +137,14 @@ def to_str(self, show_bssid=False):
color = 'R'
power = Color.s('{%s}%s' % (color, power))

wps = Color.s('{O} n/a')
if self.wps == True:
if self.wps == WPSState.UNLOCKED:
wps = Color.s('{G} yes')
elif self.wps == False:
elif self.wps == WPSState.NONE:
wps = Color.s('{O} no')
elif self.wps is None:
elif self.wps == WPSState.LOCKED:
wps = Color.s('{R}lock')
elif self.wps == WPSState.UNKNOWN:
wps = Color.s('{O} n/a')

clients = ' '
if len(self.clients) > 0:
Expand Down
7 changes: 4 additions & 3 deletions wifite/tools/airodump.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .wash import Wash
from ..util.process import Process
from ..config import Configuration
from ..model.target import Target
from ..model.target import Target, WPSState
from ..model.client import Client

import os, time
Expand All @@ -18,7 +18,8 @@ class Airodump(Dependency):
dependency_url = 'https://www.aircrack-ng.org/install.html'

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):
'''Sets up airodump arguments, doesn't start process yet.'''

Expand Down Expand Up @@ -260,7 +261,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 in [WPSState.UNLOCKED, WPSState.LOCKED]:
result.append(target)
elif skip_wps:
result.append(target)
Expand Down
3 changes: 2 additions & 1 deletion wifite/tools/bully.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ def _run(self, airodump):
return
else:
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()
return

Expand Down
2 changes: 1 addition & 1 deletion wifite/tools/reaver.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def _run(self):

# Check if locked
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)

Expand Down
13 changes: 7 additions & 6 deletions wifite/tools/tshark.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-

from .dependency import Dependency
from ..model.target import WPSState
from ..util.process import Process
import re

Expand Down Expand Up @@ -188,7 +189,6 @@ def check_for_wps_and_update_targets(capfile, targets):
if ',' not in line:
continue
bssid, locked = line.split(',')
# Ignore if WPS is locked?
if '1' not in locked:
wps_bssids.add(bssid.upper())
else:
Expand All @@ -197,11 +197,11 @@ def check_for_wps_and_update_targets(capfile, targets):
for t in targets:
target_bssid = t.bssid.upper()
if target_bssid in wps_bssids:
t.wps = True
t.wps = WPSState.UNLOCKED
elif target_bssid in locked_bssids:
t.wps = None
t.wps = WPSState.LOCKED
else:
t.wps = False
t.wps = WPSState.NONE


if __name__ == '__main__':
Expand All @@ -224,7 +224,8 @@ def check_for_wps_and_update_targets(capfile, targets):
# Should update 'wps' field of a target
Tshark.check_for_wps_and_update_targets(test_file, targets)

print('Target(BSSID={}).wps = {} (Expected: True)'.format(targets[0].bssid, targets[0].wps))
assert targets[0].wps == True
print('Target(BSSID={}).wps = {} (Expected: 1)'.format(
targets[0].bssid, targets[0].wps))
assert targets[0].wps == WPSState.UNLOCKED

print(Tshark.bssids_with_handshakes(test_file, bssid=target_bssid))
12 changes: 7 additions & 5 deletions wifite/tools/wash.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-

from .dependency import Dependency
from ..model.target import WPSState
from ..util.process import Process
import json

Expand Down Expand Up @@ -53,11 +54,11 @@ def check_for_wps_and_update_targets(capfile, targets):
for t in targets:
target_bssid = t.bssid.upper()
if target_bssid in wps_bssids:
t.wps = True
t.wps = WPSState.UNLOCKED
elif target_bssid in locked_bssids:
t.wps = None
t.wps = WPSState.LOCKED
else:
t.wps = False
t.wps = WPSState.NONE


if __name__ == '__main__':
Expand All @@ -80,7 +81,8 @@ def check_for_wps_and_update_targets(capfile, targets):
# Should update 'wps' field of a target
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

4 changes: 4 additions & 0 deletions wifite/util/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ def pexception(exception):
'''Prints an exception. Includes stack trace if necessary.'''
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
if Configuration.verbose > 0 or Configuration.print_stack_traces:
Color.pl('\n{!} {O}Full stack trace below')
Expand Down
4 changes: 2 additions & 2 deletions wifite/util/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from ..util.color import Color
from ..tools.airodump import Airodump
from ..util.input import raw_input, xrange
from ..model.target import Target
from ..model.target import Target, WPSState
from ..config import Configuration

from time import sleep, time
Expand Down Expand Up @@ -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 target.wps not in [WPSState.UNLOCKED, WPSState.LOCKED]:
continue
if bssid and target.bssid and bssid.lower() == target.bssid.lower():
self.target = target
Expand Down

0 comments on commit e190794

Please sign in to comment.