Skip to content

Commit b73dc83

Browse files
committed
fix: resolve all high-severity issues from scan report
color.py / scanner.py — replace deprecated os.popen('stty size') with shutil.get_terminal_size(fallback=...) which is safe in non-TTY contexts (piped/redirected output) and does not raise ValueError on empty output. scanner.py — replace os.system() with subprocess.run([cmd]) for the clear-screen call, eliminating the shell spawn and making the intent explicit. dependency.py — replace shell=True subprocess.run() with shell=False plus shlex.split() on the install command string, removing the shell injection vector in the package installer. logger.py — extend _sanitize_message() to mask WPA/WEP credentials that may appear in logged output: - aircrack "KEY FOUND! [ <key> ]" lines - aircrack live "Current passphrase: <value>" progress lines - hashcat cracked hash:password output - generic password/passphrase/psk keyword-value pairs - consolidate duplicate `import re` into a single import
1 parent 60f137a commit b73dc83

File tree

4 files changed

+57
-16
lines changed

4 files changed

+57
-16
lines changed

wifite/tools/dependency.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# -*- coding: utf-8 -*-
33

44
import os
5+
import shlex
56
import shutil
67
import subprocess
78

@@ -79,7 +80,7 @@ def install(cls, package_name):
7980
return False, 'No supported package manager found'
8081
try:
8182
result = subprocess.run(
82-
cmd, shell=True, capture_output=True, text=True, timeout=300
83+
shlex.split(cmd), shell=False, capture_output=True, text=True, timeout=300
8384
)
8485
output = (result.stdout + '\n' + result.stderr).strip()
8586
return result.returncode == 0, output

wifite/util/color.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ def clear_line():
7878

7979
@staticmethod
8080
def clear_entire_line():
81-
import os
82-
(rows, columns) = os.popen('stty size', 'r').read().split()
83-
Color.p('\r' + (' ' * int(columns)) + '\r')
81+
import shutil
82+
columns = shutil.get_terminal_size(fallback=(80, 24)).columns
83+
Color.p('\r' + (' ' * columns) + '\r')
8484

8585
@staticmethod
8686
def pattack(attack_type, target, attack_name, progress):

wifite/util/logger.py

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ def _sanitize_message(cls, message: str) -> str:
101101
- Known wpa-sec API key from Configuration.wpasec_api_key
102102
- Command-line API key arguments like "-k <value>" and "--key <value>"
103103
- MAC addresses in standard hex notation (aa:bb:cc:dd:ee:ff)
104+
- WPA/WEP keys from aircrack "KEY FOUND! [ <key> ]" output
105+
- Live passphrase progress "Current passphrase: <value>"
106+
- Hashcat cracked output "hash*bssid*station*essid:<password>"
107+
- Generic PSK/passphrase/password keyword-value pairs
104108
"""
105109
try:
106110
# Import lazily to avoid circular imports during module initialization
@@ -121,10 +125,10 @@ def _sanitize_message(cls, message: str) -> str:
121125
# Never let sanitization break logging
122126
pass
123127

128+
import re
129+
124130
# Mask common CLI key patterns: "-k <value>" and "--key <value>"
125131
try:
126-
import re
127-
128132
def _mask_cli_key(match):
129133
flag = match.group(1)
130134
return f"{flag} ****"
@@ -136,8 +140,6 @@ def _mask_cli_key(match):
136140

137141
# Mask MAC addresses: aa:bb:cc:dd:ee:ff -> aa:bb:cc:**:**:**
138142
try:
139-
import re
140-
141143
def _mask_mac(match):
142144
full = match.group(0)
143145
parts = full.split(":")
@@ -149,6 +151,46 @@ def _mask_mac(match):
149151
except Exception:
150152
pass
151153

154+
# Mask aircrack "KEY FOUND! [ <key> ]" output
155+
try:
156+
sanitized = re.sub(r"(KEY FOUND!\s*\[)\s*\S.*?\s*(\])", r"\1 **** \2", sanitized)
157+
except Exception:
158+
pass
159+
160+
# Mask aircrack live progress "Current passphrase: <value>"
161+
try:
162+
sanitized = re.sub(
163+
r"(Current\s+passphrase\s*:)\s*\S.*",
164+
r"\1 ****",
165+
sanitized,
166+
flags=re.IGNORECASE,
167+
)
168+
except Exception:
169+
pass
170+
171+
# Mask hashcat cracked output: trailing :<password> after PMKID/hash lines
172+
# Format: hash*bssid*station*essid:password or hash:password
173+
try:
174+
sanitized = re.sub(
175+
r"([0-9a-fA-F\*]{20,}:[^:\n]{0,64}):[^\n]+$",
176+
r"\1:****",
177+
sanitized,
178+
flags=re.MULTILINE,
179+
)
180+
except Exception:
181+
pass
182+
183+
# Mask generic keyword-value pairs: password/passphrase/psk followed by
184+
# a delimiter (=, :, space) and a value
185+
try:
186+
sanitized = re.sub(
187+
r"(?i)(password|passphrase|psk|wpa_psk|wpa_passphrase)\s*[=:]\s*\S+",
188+
r"\1=****",
189+
sanitized,
190+
)
191+
except Exception:
192+
pass
193+
152194
return sanitized
153195

154196
@classmethod

wifite/util/scanner.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,10 @@ def found_target(self):
218218
@staticmethod
219219
def clr_scr():
220220
import platform
221-
import os
221+
import subprocess
222222

223223
cmdtorun = 'cls' if platform.system().lower() == "windows" else 'clear'
224-
os.system(shlex_quote(cmdtorun))
224+
subprocess.run([cmdtorun], check=False)
225225

226226
def print_targets(self):
227227
"""Prints targets selection menu (1 target per row)."""
@@ -290,15 +290,13 @@ def print_targets(self):
290290

291291
@staticmethod
292292
def get_terminal_height():
293-
import os
294-
(rows, columns) = os.popen('stty size', 'r').read().split()
295-
return int(rows)
293+
import shutil
294+
return shutil.get_terminal_size(fallback=(24, 80)).lines
296295

297296
@staticmethod
298297
def get_terminal_width():
299-
import os
300-
(rows, columns) = os.popen('stty size', 'r').read().split()
301-
return int(columns)
298+
import shutil
299+
return shutil.get_terminal_size(fallback=(24, 80)).columns
302300

303301
def select_targets(self):
304302
"""

0 commit comments

Comments
 (0)