Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions wifite/model/handshake.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ def hcxpcapngtool_handshakes(self):
import tempfile

# Create a temporary hash file to test if hcxpcapngtool can extract data
hash_file = None
try:
with tempfile.NamedTemporaryFile(mode='w', suffix='.22000', delete=False) as tmp:
hash_file = tmp.name
Expand Down
12 changes: 8 additions & 4 deletions wifite/tools/aircrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def _hex_and_ascii_key(hex_raw):
return hex_key, ascii_key

def __del__(self):
if os.path.exists(self.cracked_file):
if hasattr(self, 'cracked_file') and os.path.exists(self.cracked_file):
os.remove(self.cracked_file)

@staticmethod
Expand Down Expand Up @@ -107,14 +107,18 @@ def crack_handshake(handshake, show_command=False):
eta_str = 'unknown'
current_key = ''
while crack_proc.poll() is None:
if not crack_proc.pid or not crack_proc.pid.stdout:
break
line = crack_proc.pid.stdout.readline().decode('utf-8')
match_nums = aircrack_nums_re.search(line)
match_keys = aircrack_key_re.search(line)
if match_nums:
num_tried, num_total, num_kps = int(match_nums[1]), int(match_nums[2]), float(match_nums[3])
eta_seconds = (num_total - num_tried) / num_kps
eta_str = Timer.secs_to_str(eta_seconds)
percent = 100.0 * num_tried / num_total
if num_kps > 0:
eta_seconds = (num_total - num_tried) / num_kps
eta_str = Timer.secs_to_str(eta_seconds)
if num_total > 0:
percent = 100.0 * num_tried / num_total
elif match_keys:
current_key = match_keys[1]
else:
Expand Down
5 changes: 4 additions & 1 deletion wifite/tools/aireplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ def __init__(self, target, attack_type, client_mac=None, replay_file=None):
attack_type,
client_mac=client_mac,
replay_file=replay_file)
self.output_fh = open(self.output_file, 'a')
self.pid = Process(self.cmd,
stdout=open(self.output_file, 'a'),
stdout=self.output_fh,
stderr=Process.devnull(),
cwd=Configuration.temp())
self.start()
Expand All @@ -110,6 +111,8 @@ def stop(self):
""" Stops aireplay process """
if hasattr(self, 'pid') and self.pid and self.pid.poll() is None:
self.pid.interrupt()
if hasattr(self, 'output_fh') and self.output_fh and not self.output_fh.closed:
self.output_fh.close()

def get_output(self):
""" Returns stdout from aireplay process """
Expand Down
15 changes: 12 additions & 3 deletions wifite/tools/airodump.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,19 +140,28 @@ def delete_airodump_temp_files(cls, output_file_prefix):
"""
# Remove all temp files
for fil in cls.find_files_by_output_prefix(output_file_prefix):
os.remove(fil)
try:
os.remove(fil)
except FileNotFoundError:
pass # File already removed

# Remove .cap and .xor files from pwd
cwd = os.getcwd()
for fil in os.listdir(cwd):
if fil.startswith('replay_') and (fil.endswith('.cap') or fil.endswith('.xor')):
os.remove(os.path.join(cwd, fil))
try:
os.remove(os.path.join(cwd, fil))
except FileNotFoundError:
pass # File already removed

# Remove replay/cap/xor files from temp
temp_dir = Configuration.temp()
for fil in os.listdir(temp_dir):
if fil.startswith('replay_') and (fil.endswith('.cap') or fil.endswith('.xor')):
os.remove(os.path.join(temp_dir, fil))
try:
os.remove(os.path.join(temp_dir, fil))
except FileNotFoundError:
pass # File already removed

def get_targets(self, old_targets=None, apply_filter=True, target_archives=None):
""" Parses airodump's CSV file, returns list of Targets """
Expand Down
2 changes: 1 addition & 1 deletion wifite/tools/hashcat.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Hashcat(Dependency):
def should_use_force():
command = ['hashcat', '-I']
stderr = Process(command).stderr()
return 'No devices found/left' or 'Unstable OpenCL driver detected!' in stderr
return 'No devices found/left' in stderr or 'Unstable OpenCL driver detected!' in stderr

@staticmethod
def crack_handshake(handshake_obj, target_is_wpa3_sae, show_command=False):
Expand Down
30 changes: 22 additions & 8 deletions wifite/tools/hcxdumptool.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __init__(self, interface=None, channel=None, target_bssid=None,

# Generate output file if not provided
if output_file is None:
self.output_file = Configuration.temp() + 'hcxdumptool_capture.pcapng'
self.output_file = os.path.join(Configuration.temp(), 'hcxdumptool_capture.pcapng')
else:
self.output_file = output_file

Expand Down Expand Up @@ -122,7 +122,11 @@ def __enter__(self):

# Start the process
self.proc = Process(command, devnull=False)
self.pid = self.proc.pid.pid # Get the actual PID from the Popen object
# Get the actual PID safely from the Popen object
if self.proc and hasattr(self.proc, 'pid') and self.proc.pid and hasattr(self.proc.pid, 'pid'):
self.pid = self.proc.pid.pid
else:
self.pid = None

# Give it a moment to start
time.sleep(1)
Expand All @@ -141,8 +145,11 @@ def __exit__(self, exc_type, exc_val, exc_tb):
time.sleep(0.5)

# Force kill if still running
if self.proc.poll() is None:
os.kill(self.pid, signal.SIGKILL)
if self.proc.poll() is None and self.pid is not None:
try:
os.kill(self.pid, signal.SIGKILL)
except ProcessLookupError:
pass # Process already exited
except Exception as e:
from ..util.logger import log_debug
log_debug('HcxDumpTool', f'Kill process error: {e}')
Expand Down Expand Up @@ -239,7 +246,7 @@ def __init__(self, interface=None, output_file=None):

# Generate output file if not provided
if output_file is None:
self.output_file = Configuration.temp() + 'passive_pmkid.pcapng'
self.output_file = os.path.join(Configuration.temp(), 'passive_pmkid.pcapng')
else:
self.output_file = output_file

Expand All @@ -262,7 +269,11 @@ def __enter__(self):

# Start the process
self.proc = Process(command, devnull=False)
self.pid = self.proc.pid.pid # Get the actual PID from the Popen object
# Get the actual PID safely from the Popen object
if self.proc and hasattr(self.proc, 'pid') and self.proc.pid and hasattr(self.proc.pid, 'pid'):
self.pid = self.proc.pid.pid
else:
self.pid = None

# Give it a moment to start
time.sleep(1)
Expand All @@ -281,8 +292,11 @@ def __exit__(self, exc_type, exc_val, exc_tb):
time.sleep(0.5)

# Force kill if still running
if self.proc.poll() is None:
os.kill(self.pid, signal.SIGKILL)
if self.proc.poll() is None and self.pid is not None:
try:
os.kill(self.pid, signal.SIGKILL)
except ProcessLookupError:
pass # Process already exited
except Exception as e:
from ..util.logger import log_debug
log_debug('HcxDumpToolPassive', f'Kill process error: {e}')
Expand Down
8 changes: 7 additions & 1 deletion wifite/tools/reaver.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def __init__(self, target, pixie_dust=True, null_pin=False):
os.remove(self.output_filename)

self.output_write = open(self.output_filename, 'a')
self._output_write_closed = False

self.reaver_cmd = [
'reaver',
Expand All @@ -64,6 +65,11 @@ def __init__(self, target, pixie_dust=True, null_pin=False):

self.reaver_proc = None

def __del__(self):
"""Ensure file handle is closed on garbage collection."""
if hasattr(self, 'output_write') and self.output_write and not self.output_write.closed:
self.output_write.close()

@staticmethod
def is_pixiedust_supported():
""" Checks if 'reaver' supports WPS Pixie-Dust attack """
Expand Down Expand Up @@ -96,7 +102,7 @@ def run(self):
pass # Ignore errors during cleanup

# Clean up open file handle
if self.output_write:
if self.output_write and not self.output_write.closed:
try:
self.output_write.close()
except Exception:
Expand Down
Loading