Skip to content

Commit 28b2d83

Browse files
committed
--keep-ivs option to retain .ivs files across attacks on the same target
For #27
1 parent 9f95f55 commit 28b2d83

File tree

3 files changed

+55
-20
lines changed

3 files changed

+55
-20
lines changed

wifite/args.py

+6
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ def _add_wep_args(self, wep):
159159
wep.add_argument('--nofakeauth', help=argparse.SUPPRESS, action='store_true', dest='require_fakeauth')
160160
wep.add_argument('-nofakeauth', help=argparse.SUPPRESS, action='store_true', dest='require_fakeauth')
161161

162+
wep.add_argument('--keep-ivs',
163+
action='store_true',
164+
dest='wep_keep_ivs',
165+
default=False,
166+
help=Color.s('Retain .IVS files and reuse when cracking (default: {G}off{W})'))
167+
162168
wep.add_argument('--pps',
163169
action='store',
164170
dest='wep_pps',

wifite/attack/wep.py

+45-20
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ def run(self):
3737
replay_file = None
3838
airodump_target = None
3939

40+
previous_ivs = 0
41+
current_ivs = 0
42+
total_ivs = 0
43+
keep_ivs = Configuration.wep_keep_ivs
44+
45+
# Clean up previous WEP sessions
46+
if keep_ivs:
47+
Airodump.delete_airodump_temp_files('wep')
48+
4049
attacks_remaining = list(Configuration.wep_attacks)
4150
while len(attacks_remaining) > 0:
4251
attack_name = attacks_remaining.pop(0)
@@ -47,7 +56,8 @@ def run(self):
4756
target_bssid=self.target.bssid,
4857
ivs_only=True, # Only capture IVs packets
4958
skip_wps=True, # Don't check for WPS-compatibility
50-
output_file_prefix='wep') as airodump:
59+
output_file_prefix='wep',
60+
delete_existing_files=not keep_ivs) as airodump:
5161

5262
Color.clear_line()
5363
Color.p('\r{+} {O}waiting{W} for target to appear...')
@@ -81,7 +91,7 @@ def run(self):
8191
replay_file=replay_file)
8292

8393
time_unchanged_ivs = time.time() # Timestamp when IVs last changed
84-
previous_ivs = 0
94+
last_ivs_count = 0
8595

8696
# Loop until attack completes.
8797

@@ -91,7 +101,12 @@ def run(self):
91101
if client_mac is None and len(airodump_target.clients) > 0:
92102
client_mac = airodump_target.clients[0].station
93103

94-
total_ivs = airodump_target.ivs
104+
if keep_ivs and current_ivs > airodump_target.ivs:
105+
# We now have less IVS than before; A new attack must have started.
106+
# Track how many we have in-total.
107+
previous_ivs += total_ivs
108+
current_ivs = airodump_target.ivs
109+
total_ivs = previous_ivs + current_ivs
95110

96111
status = "%d/{C}%d{W} IVs" % (total_ivs, Configuration.wep_crack_at_ivs)
97112
if fakeauth_proc:
@@ -118,6 +133,9 @@ def run(self):
118133
self.crack_result = CrackResultWEP(self.target.bssid,
119134
self.target.essid, hex_key, ascii_key)
120135
self.crack_result.dump()
136+
137+
Airodump.delete_airodump_temp_files('wep')
138+
121139
self.success = True
122140
return self.success
123141

@@ -127,31 +145,26 @@ def run(self):
127145

128146
# Check number of IVs, crack if necessary
129147
if total_ivs > Configuration.wep_crack_at_ivs:
130-
if not aircrack:
148+
if not aircrack or not aircrack.is_running():
131149
# Aircrack hasn't started yet. Start it.
132150
ivs_files = airodump.find_files(endswith='.ivs')
151+
ivs_files.sort()
133152
if len(ivs_files) > 0:
134-
aircrack = Aircrack(ivs_files[-1])
135-
136-
elif not aircrack.is_running():
137-
# Aircrack stopped running.
138-
#Color.pl('\n{+} {C}aircrack{W} stopped, restarting...')
139-
ivs_files = airodump.find_files(endswith='ivs')
140-
if len(ivs_files) > 0:
141-
aircrack = Aircrack(ivs_files[-1])
142-
# TODO: Why do we need fakeauth when aircrack stops?
143-
#self.fake_auth()
153+
if not keep_ivs:
154+
ivs_files = ivs_files[-1] # Use most-recent .ivs file
155+
aircrack = Aircrack(ivs_files)
144156

145-
'''
146157
elif Configuration.wep_restart_aircrack > 0 and \
147158
aircrack.pid.running_time() > Configuration.wep_restart_aircrack:
148159
# Restart aircrack after X seconds
160+
#Color.pl('\n{+} {C}aircrack{W} ran for more than {C}%d{W} seconds, restarting' % Configuration.wep_restart_aircrack)
149161
aircrack.stop()
150162
ivs_files = airodump.find_files(endswith='.ivs')
151-
Color.pl('\n{+} {C}aircrack{W} ran for more than {C}%d{W} seconds, restarting' % Configuration.wep_restart_aircrack)
163+
ivs_files.sort()
152164
if len(ivs_files) > 0:
153-
aircrack = Aircrack(ivs_files[-1])
154-
'''
165+
if not keep_ivs:
166+
ivs_files = ivs_files[-1] # Use most-recent .ivs file
167+
aircrack = Aircrack(ivs_files)
155168

156169

157170
if not aireplay.is_running():
@@ -186,6 +199,7 @@ def run(self):
186199
'forgedreplay',
187200
client_mac=client_mac,
188201
replay_file=replay_file)
202+
time_unchanged_ivs = time.time() # Reset unchanged IVs time (it may have taken a while to forge the packet)
189203
continue
190204
else:
191205
# Failed to forge packet. drop out
@@ -197,7 +211,7 @@ def run(self):
197211
break # Continue to other attacks
198212

199213
# Check if IVs stopped flowing (same for > N seconds)
200-
if airodump_target.ivs > previous_ivs:
214+
if airodump_target.ivs > last_ivs_count:
201215
time_unchanged_ivs = time.time()
202216
elif Configuration.wep_restart_stale_ivs > 0 and \
203217
attack_name != 'chopchop' and \
@@ -214,7 +228,7 @@ def run(self):
214228
client_mac=client_mac, \
215229
replay_file=replay_file)
216230
time_unchanged_ivs = time.time()
217-
previous_ivs = airodump_target.ivs
231+
last_ivs_count = airodump_target.ivs
218232

219233
time.sleep(1)
220234
continue
@@ -223,11 +237,19 @@ def run(self):
223237
except KeyboardInterrupt:
224238
if fakeauth_proc: fakeauth_proc.stop()
225239
if len(attacks_remaining) == 0:
240+
if keep_ivs:
241+
Airodump.delete_airodump_temp_files('wep')
242+
226243
self.success = False
227244
return self.success
245+
228246
if self.user_wants_to_stop(attack_name, attacks_remaining, airodump_target):
247+
if keep_ivs:
248+
Airodump.delete_airodump_temp_files('wep')
249+
229250
self.success = False
230251
return self.success
252+
231253
except Exception as e:
232254
Color.pl("\n{!} {R}Error: {O}%s" % str(e))
233255
if Configuration.verbose > 0 or Configuration.print_stack_traces:
@@ -243,6 +265,9 @@ def run(self):
243265
# End of big try-catch
244266
# End of for-each-attack-type loop
245267

268+
if keep_ivs:
269+
Airodump.delete_airodump_temp_files('wep')
270+
246271
self.success = False
247272
return self.success
248273

wifite/config.py

+4
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def initialize(load_interface=True):
6262
Configuration.wep_restart_aircrack = 30 # Seconds to give aircrack to crack
6363
# before restarting the process.
6464
Configuration.wep_crack_at_ivs = 10000 # Number of IVS to start cracking
65+
Configuration.wep_keep_ivs = False # Retain .ivs files across multiple attacks.
6566

6667
# WPA variables
6768
Configuration.wpa_filter = False # Only attack WPA networks
@@ -187,6 +188,9 @@ def load_from_arguments():
187188
if args.wep_restart_aircrack:
188189
Configuration.wep_restart_aircrack = args.wep_restart_aircrack
189190
Color.pl('{+} {C}option:{W} will restart aircrack every {G}%d seconds{W}' % args.wep_restart_aircrack)
191+
if args.wep_keep_ivs:
192+
Configuration.wep_keep_ivs = args.wep_keep_ivs
193+
Color.pl('{+} {C}option:{W} keep .ivs files across multiple WEP attacks')
190194

191195
# WPA
192196
if args.wpa_filter:

0 commit comments

Comments
 (0)