Skip to content

Commit

Permalink
--keep-ivs option to retain .ivs files across attacks on the same target
Browse files Browse the repository at this point in the history
For #27
  • Loading branch information
derv82 committed Apr 20, 2018
1 parent 9f95f55 commit 28b2d83
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 20 deletions.
6 changes: 6 additions & 0 deletions wifite/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ def _add_wep_args(self, wep):
wep.add_argument('--nofakeauth', help=argparse.SUPPRESS, action='store_true', dest='require_fakeauth')
wep.add_argument('-nofakeauth', help=argparse.SUPPRESS, action='store_true', dest='require_fakeauth')

wep.add_argument('--keep-ivs',
action='store_true',
dest='wep_keep_ivs',
default=False,
help=Color.s('Retain .IVS files and reuse when cracking (default: {G}off{W})'))

wep.add_argument('--pps',
action='store',
dest='wep_pps',
Expand Down
65 changes: 45 additions & 20 deletions wifite/attack/wep.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ def run(self):
replay_file = None
airodump_target = None

previous_ivs = 0
current_ivs = 0
total_ivs = 0
keep_ivs = Configuration.wep_keep_ivs

# Clean up previous WEP sessions
if keep_ivs:
Airodump.delete_airodump_temp_files('wep')

attacks_remaining = list(Configuration.wep_attacks)
while len(attacks_remaining) > 0:
attack_name = attacks_remaining.pop(0)
Expand All @@ -47,7 +56,8 @@ def run(self):
target_bssid=self.target.bssid,
ivs_only=True, # Only capture IVs packets
skip_wps=True, # Don't check for WPS-compatibility
output_file_prefix='wep') as airodump:
output_file_prefix='wep',
delete_existing_files=not keep_ivs) as airodump:

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

time_unchanged_ivs = time.time() # Timestamp when IVs last changed
previous_ivs = 0
last_ivs_count = 0

# Loop until attack completes.

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

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

status = "%d/{C}%d{W} IVs" % (total_ivs, Configuration.wep_crack_at_ivs)
if fakeauth_proc:
Expand All @@ -118,6 +133,9 @@ def run(self):
self.crack_result = CrackResultWEP(self.target.bssid,
self.target.essid, hex_key, ascii_key)
self.crack_result.dump()

Airodump.delete_airodump_temp_files('wep')

self.success = True
return self.success

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

# Check number of IVs, crack if necessary
if total_ivs > Configuration.wep_crack_at_ivs:
if not aircrack:
if not aircrack or not aircrack.is_running():
# Aircrack hasn't started yet. Start it.
ivs_files = airodump.find_files(endswith='.ivs')
ivs_files.sort()
if len(ivs_files) > 0:
aircrack = Aircrack(ivs_files[-1])

elif not aircrack.is_running():
# Aircrack stopped running.
#Color.pl('\n{+} {C}aircrack{W} stopped, restarting...')
ivs_files = airodump.find_files(endswith='ivs')
if len(ivs_files) > 0:
aircrack = Aircrack(ivs_files[-1])
# TODO: Why do we need fakeauth when aircrack stops?
#self.fake_auth()
if not keep_ivs:
ivs_files = ivs_files[-1] # Use most-recent .ivs file
aircrack = Aircrack(ivs_files)

'''
elif Configuration.wep_restart_aircrack > 0 and \
aircrack.pid.running_time() > Configuration.wep_restart_aircrack:
# Restart aircrack after X seconds
#Color.pl('\n{+} {C}aircrack{W} ran for more than {C}%d{W} seconds, restarting' % Configuration.wep_restart_aircrack)
aircrack.stop()
ivs_files = airodump.find_files(endswith='.ivs')
Color.pl('\n{+} {C}aircrack{W} ran for more than {C}%d{W} seconds, restarting' % Configuration.wep_restart_aircrack)
ivs_files.sort()
if len(ivs_files) > 0:
aircrack = Aircrack(ivs_files[-1])
'''
if not keep_ivs:
ivs_files = ivs_files[-1] # Use most-recent .ivs file
aircrack = Aircrack(ivs_files)


if not aireplay.is_running():
Expand Down Expand Up @@ -186,6 +199,7 @@ def run(self):
'forgedreplay',
client_mac=client_mac,
replay_file=replay_file)
time_unchanged_ivs = time.time() # Reset unchanged IVs time (it may have taken a while to forge the packet)
continue
else:
# Failed to forge packet. drop out
Expand All @@ -197,7 +211,7 @@ def run(self):
break # Continue to other attacks

# Check if IVs stopped flowing (same for > N seconds)
if airodump_target.ivs > previous_ivs:
if airodump_target.ivs > last_ivs_count:
time_unchanged_ivs = time.time()
elif Configuration.wep_restart_stale_ivs > 0 and \
attack_name != 'chopchop' and \
Expand All @@ -214,7 +228,7 @@ def run(self):
client_mac=client_mac, \
replay_file=replay_file)
time_unchanged_ivs = time.time()
previous_ivs = airodump_target.ivs
last_ivs_count = airodump_target.ivs

time.sleep(1)
continue
Expand All @@ -223,11 +237,19 @@ def run(self):
except KeyboardInterrupt:
if fakeauth_proc: fakeauth_proc.stop()
if len(attacks_remaining) == 0:
if keep_ivs:
Airodump.delete_airodump_temp_files('wep')

self.success = False
return self.success

if self.user_wants_to_stop(attack_name, attacks_remaining, airodump_target):
if keep_ivs:
Airodump.delete_airodump_temp_files('wep')

self.success = False
return self.success

except Exception as e:
Color.pl("\n{!} {R}Error: {O}%s" % str(e))
if Configuration.verbose > 0 or Configuration.print_stack_traces:
Expand All @@ -243,6 +265,9 @@ def run(self):
# End of big try-catch
# End of for-each-attack-type loop

if keep_ivs:
Airodump.delete_airodump_temp_files('wep')

self.success = False
return self.success

Expand Down
4 changes: 4 additions & 0 deletions wifite/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def initialize(load_interface=True):
Configuration.wep_restart_aircrack = 30 # Seconds to give aircrack to crack
# before restarting the process.
Configuration.wep_crack_at_ivs = 10000 # Number of IVS to start cracking
Configuration.wep_keep_ivs = False # Retain .ivs files across multiple attacks.

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

# WPA
if args.wpa_filter:
Expand Down

0 comments on commit 28b2d83

Please sign in to comment.