Skip to content

Commit a488cf8

Browse files
committed
Bugfix: Don't infinitely loop while calculating Hex & ASCII key from WEP attack.
* Simplified HEX/ASCII conversion. Avoids infinite loop 🤔 * Added integration test: python -m wifite.tools.aircrack Should resolve "hanging" issues during WEP attacks such as #27.
1 parent 34d6b69 commit a488cf8

File tree

2 files changed

+48
-41
lines changed

2 files changed

+48
-41
lines changed

wifite/attack/wep.py

+3-11
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,7 @@ def run(self):
9494
if aireplay.status is not None:
9595
status += ", %s" % aireplay.status
9696
Color.clear_entire_line()
97-
Color.pattack("WEP",
98-
airodump_target,
99-
"%s" % attack_name,
100-
status)
101-
102-
#self.aircrack_check()
97+
Color.pattack("WEP", airodump_target, "%s" % attack_name, status)
10398

10499
# Check if we cracked it.
105100
if aircrack and aircrack.is_cracked():
@@ -109,8 +104,7 @@ def run(self):
109104
essid = airodump_target.essid
110105
else:
111106
essid = None
112-
Color.pl('\n{+} {C}%s{W} WEP attack {G}successful{W}\n'
113-
% attack_name)
107+
Color.pl('\n{+} {C}%s{W} WEP attack {G}successful{W}\n' % attack_name)
114108
if aireplay: aireplay.stop()
115109
if fakeauth_proc: fakeauth_proc.stop()
116110
self.crack_result = CrackResultWEP(self.target.bssid,
@@ -143,9 +137,7 @@ def run(self):
143137
# Restart aircrack after X seconds
144138
aircrack.stop()
145139
ivs_file = airodump.find_files(endswith='.ivs')[0]
146-
Color.pl('\n{+} {C}aircrack{W} ran for more than' +
147-
' {C}%d{W} seconds, restarting'
148-
% Configuration.wep_restart_aircrack)
140+
Color.pl('\n{+} {C}aircrack{W} ran for more than {C}%d{W} seconds, restarting' % Configuration.wep_restart_aircrack)
149141
aircrack = Aircrack(ivs_file)
150142

151143

wifite/tools/aircrack.py

+45-30
Original file line numberDiff line numberDiff line change
@@ -39,44 +39,59 @@ def stop(self):
3939
def get_key_hex_ascii(self):
4040
if not self.is_cracked():
4141
raise Exception('Cracked file not found')
42+
4243
with open(self.cracked_file, 'r') as fid:
4344
hex_raw = fid.read()
44-
hex_key = ''
45+
46+
return self._hex_and_ascii_key(hex_raw)
47+
48+
@staticmethod
49+
def _hex_and_ascii_key(hex_raw):
50+
hex_chars = []
4551
ascii_key = ''
46-
while len(hex_raw) > 0:
47-
# HEX
48-
if hex_key != '':
49-
hex_key += ':'
50-
hex_key += hex_raw[0:2]
51-
52-
# ASCII
53-
# Convert hex to decimal
54-
code = int(hex_raw[0:2], 16)
55-
if code < 32 or code > 127:
56-
# Hex key is non-printable in ascii
57-
ascii_key = None
58-
continue
59-
elif ascii_key is None:
60-
# We can't generate an Ascii key
61-
continue
62-
# Convert decimal to char
63-
ascii_key += chr(code)
64-
65-
# Trim first two characters
66-
hex_raw = hex_raw[2:]
67-
continue
52+
for index in xrange(0, len(hex_raw), 2):
53+
byt = hex_raw[index:index+2]
54+
hex_chars.append(byt)
55+
byt_int = int(byt, 16)
56+
if byt_int < 32 or byt_int > 127 or ascii_key is None:
57+
ascii_key = None # Not printable
58+
else:
59+
ascii_key += chr(byt_int)
60+
61+
hex_key = ':'.join(hex_chars)
6862

6963
return (hex_key, ascii_key)
7064

65+
def __del__(self):
66+
if os.path.exists(self.cracked_file):
67+
os.remove(self.cracked_file)
68+
7169
if __name__ == '__main__':
70+
(hexkey, asciikey) = Aircrack._hex_and_ascii_key('A1B1C1D1E1')
71+
assert hexkey == 'A1:B1:C1:D1:E1', 'hexkey was "%s", expected "A1:B1:C1:D1:E1"' % hexkey
72+
assert asciikey is None, 'asciikey was "%s", expected None' % asciikey
73+
74+
(hexkey, asciikey) = Aircrack._hex_and_ascii_key('6162636465')
75+
assert hexkey == '61:62:63:64:65', 'hexkey was "%s", expected "61:62:63:64:65"' % hexkey
76+
assert asciikey == 'abcde', 'asciikey was "%s", expected "abcde"' % asciikey
77+
7278
from time import sleep
79+
7380
Configuration.initialize(False)
74-
a = Aircrack('tests/files/wep-crackable.ivs')
75-
while a.is_running():
81+
82+
ivs_file = 'tests/files/wep-crackable.ivs'
83+
print "Running aircrack on %s ..." % ivs_file
84+
85+
aircrack = Aircrack(ivs_file)
86+
while aircrack.is_running():
7687
sleep(1)
77-
if a.is_cracked():
78-
print "cracked!"
79-
print '(hex, ascii) =', a.get_key_hex_ascii()
80-
else:
81-
print "Not cracked"
88+
89+
assert aircrack.is_cracked(), "Aircrack should have cracked %s" % ivs_file
90+
print "aircrack process completed."
91+
92+
(hexkey, asciikey) = aircrack.get_key_hex_ascii()
93+
print "aircrack found HEX key: (%s) and ASCII key: (%s)" % (hexkey, asciikey)
94+
assert hexkey == '75:6E:63:6C:65', 'hexkey was "%s", expected "75:6E:63:6C:65"' % hexkey
95+
assert asciikey == 'uncle', 'asciikey was "%s", expected "uncle"' % asciikey
96+
8297
Configuration.exit_gracefully(0)

0 commit comments

Comments
 (0)