Skip to content

Commit 9bcd4ee

Browse files
authored
Merge pull request #445 from kimocoder/claude/scan-repo-analysis-7Cx4F
Claude/scan repo analysis 7 cx4 f
2 parents ce0cebf + 54e8160 commit 9bcd4ee

File tree

7 files changed

+55
-18
lines changed

7 files changed

+55
-18
lines changed

wifite/model/handshake.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ def hcxpcapngtool_handshakes(self):
151151
import tempfile
152152

153153
# Create a temporary hash file to test if hcxpcapngtool can extract data
154+
hash_file = None
154155
try:
155156
with tempfile.NamedTemporaryFile(mode='w', suffix='.22000', delete=False) as tmp:
156157
hash_file = tmp.name

wifite/tools/aircrack.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def _hex_and_ascii_key(hex_raw):
7777
return hex_key, ascii_key
7878

7979
def __del__(self):
80-
if os.path.exists(self.cracked_file):
80+
if hasattr(self, 'cracked_file') and os.path.exists(self.cracked_file):
8181
os.remove(self.cracked_file)
8282

8383
@staticmethod
@@ -107,14 +107,18 @@ def crack_handshake(handshake, show_command=False):
107107
eta_str = 'unknown'
108108
current_key = ''
109109
while crack_proc.poll() is None:
110+
if not crack_proc.pid or not crack_proc.pid.stdout:
111+
break
110112
line = crack_proc.pid.stdout.readline().decode('utf-8')
111113
match_nums = aircrack_nums_re.search(line)
112114
match_keys = aircrack_key_re.search(line)
113115
if match_nums:
114116
num_tried, num_total, num_kps = int(match_nums[1]), int(match_nums[2]), float(match_nums[3])
115-
eta_seconds = (num_total - num_tried) / num_kps
116-
eta_str = Timer.secs_to_str(eta_seconds)
117-
percent = 100.0 * num_tried / num_total
117+
if num_kps > 0:
118+
eta_seconds = (num_total - num_tried) / num_kps
119+
eta_str = Timer.secs_to_str(eta_seconds)
120+
if num_total > 0:
121+
percent = 100.0 * num_tried / num_total
118122
elif match_keys:
119123
current_key = match_keys[1]
120124
else:

wifite/tools/aireplay.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,9 @@ def __init__(self, target, attack_type, client_mac=None, replay_file=None):
9797
attack_type,
9898
client_mac=client_mac,
9999
replay_file=replay_file)
100+
self.output_fh = open(self.output_file, 'a')
100101
self.pid = Process(self.cmd,
101-
stdout=open(self.output_file, 'a'),
102+
stdout=self.output_fh,
102103
stderr=Process.devnull(),
103104
cwd=Configuration.temp())
104105
self.start()
@@ -110,6 +111,8 @@ def stop(self):
110111
""" Stops aireplay process """
111112
if hasattr(self, 'pid') and self.pid and self.pid.poll() is None:
112113
self.pid.interrupt()
114+
if hasattr(self, 'output_fh') and self.output_fh and not self.output_fh.closed:
115+
self.output_fh.close()
113116

114117
def get_output(self):
115118
""" Returns stdout from aireplay process """

wifite/tools/airodump.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,19 +140,28 @@ def delete_airodump_temp_files(cls, output_file_prefix):
140140
"""
141141
# Remove all temp files
142142
for fil in cls.find_files_by_output_prefix(output_file_prefix):
143-
os.remove(fil)
143+
try:
144+
os.remove(fil)
145+
except FileNotFoundError:
146+
pass # File already removed
144147

145148
# Remove .cap and .xor files from pwd
146149
cwd = os.getcwd()
147150
for fil in os.listdir(cwd):
148151
if fil.startswith('replay_') and (fil.endswith('.cap') or fil.endswith('.xor')):
149-
os.remove(os.path.join(cwd, fil))
152+
try:
153+
os.remove(os.path.join(cwd, fil))
154+
except FileNotFoundError:
155+
pass # File already removed
150156

151157
# Remove replay/cap/xor files from temp
152158
temp_dir = Configuration.temp()
153159
for fil in os.listdir(temp_dir):
154160
if fil.startswith('replay_') and (fil.endswith('.cap') or fil.endswith('.xor')):
155-
os.remove(os.path.join(temp_dir, fil))
161+
try:
162+
os.remove(os.path.join(temp_dir, fil))
163+
except FileNotFoundError:
164+
pass # File already removed
156165

157166
def get_targets(self, old_targets=None, apply_filter=True, target_archives=None):
158167
""" Parses airodump's CSV file, returns list of Targets """

wifite/tools/hashcat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Hashcat(Dependency):
2020
def should_use_force():
2121
command = ['hashcat', '-I']
2222
stderr = Process(command).stderr()
23-
return 'No devices found/left' or 'Unstable OpenCL driver detected!' in stderr
23+
return 'No devices found/left' in stderr or 'Unstable OpenCL driver detected!' in stderr
2424

2525
@staticmethod
2626
def crack_handshake(handshake_obj, target_is_wpa3_sae, show_command=False):

wifite/tools/hcxdumptool.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def __init__(self, interface=None, channel=None, target_bssid=None,
6666

6767
# Generate output file if not provided
6868
if output_file is None:
69-
self.output_file = Configuration.temp() + 'hcxdumptool_capture.pcapng'
69+
self.output_file = os.path.join(Configuration.temp(), 'hcxdumptool_capture.pcapng')
7070
else:
7171
self.output_file = output_file
7272

@@ -122,7 +122,11 @@ def __enter__(self):
122122

123123
# Start the process
124124
self.proc = Process(command, devnull=False)
125-
self.pid = self.proc.pid.pid # Get the actual PID from the Popen object
125+
# Get the actual PID safely from the Popen object
126+
if self.proc and hasattr(self.proc, 'pid') and self.proc.pid and hasattr(self.proc.pid, 'pid'):
127+
self.pid = self.proc.pid.pid
128+
else:
129+
self.pid = None
126130

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

143147
# Force kill if still running
144-
if self.proc.poll() is None:
145-
os.kill(self.pid, signal.SIGKILL)
148+
if self.proc.poll() is None and self.pid is not None:
149+
try:
150+
os.kill(self.pid, signal.SIGKILL)
151+
except ProcessLookupError:
152+
pass # Process already exited
146153
except Exception as e:
147154
from ..util.logger import log_debug
148155
log_debug('HcxDumpTool', f'Kill process error: {e}')
@@ -239,7 +246,7 @@ def __init__(self, interface=None, output_file=None):
239246

240247
# Generate output file if not provided
241248
if output_file is None:
242-
self.output_file = Configuration.temp() + 'passive_pmkid.pcapng'
249+
self.output_file = os.path.join(Configuration.temp(), 'passive_pmkid.pcapng')
243250
else:
244251
self.output_file = output_file
245252

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

263270
# Start the process
264271
self.proc = Process(command, devnull=False)
265-
self.pid = self.proc.pid.pid # Get the actual PID from the Popen object
272+
# Get the actual PID safely from the Popen object
273+
if self.proc and hasattr(self.proc, 'pid') and self.proc.pid and hasattr(self.proc.pid, 'pid'):
274+
self.pid = self.proc.pid.pid
275+
else:
276+
self.pid = None
266277

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

283294
# Force kill if still running
284-
if self.proc.poll() is None:
285-
os.kill(self.pid, signal.SIGKILL)
295+
if self.proc.poll() is None and self.pid is not None:
296+
try:
297+
os.kill(self.pid, signal.SIGKILL)
298+
except ProcessLookupError:
299+
pass # Process already exited
286300
except Exception as e:
287301
from ..util.logger import log_debug
288302
log_debug('HcxDumpToolPassive', f'Kill process error: {e}')

wifite/tools/reaver.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def __init__(self, target, pixie_dust=True, null_pin=False):
4646
os.remove(self.output_filename)
4747

4848
self.output_write = open(self.output_filename, 'a')
49+
self._output_write_closed = False
4950

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

6566
self.reaver_proc = None
6667

68+
def __del__(self):
69+
"""Ensure file handle is closed on garbage collection."""
70+
if hasattr(self, 'output_write') and self.output_write and not self.output_write.closed:
71+
self.output_write.close()
72+
6773
@staticmethod
6874
def is_pixiedust_supported():
6975
""" Checks if 'reaver' supports WPS Pixie-Dust attack """
@@ -96,7 +102,7 @@ def run(self):
96102
pass # Ignore errors during cleanup
97103

98104
# Clean up open file handle
99-
if self.output_write:
105+
if self.output_write and not self.output_write.closed:
100106
try:
101107
self.output_write.close()
102108
except Exception:

0 commit comments

Comments
 (0)