Skip to content

Commit 1c1e04a

Browse files
committed
Add support for ICNSS2 monitor mode
1 parent f0127b1 commit 1c1e04a

3 files changed

Lines changed: 47 additions & 606 deletions

File tree

wifite/model/target_backup.py

Lines changed: 0 additions & 306 deletions
This file was deleted.

wifite/tools/airmon.py

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import re
66
import signal
7+
import subprocess
78
import time
89

910
from .dependency import Dependency
@@ -175,11 +176,46 @@ def start(cls, interface):
175176
driver = interface.driver
176177
else:
177178
iface_name = interface
178-
driver = None
179+
driver = None # We'll try to fetch this if needed
179180

180181
# Remember this as the 'base' interface.
181182
Airmon.base_interface = iface_name
182183

184+
# Try ICNSS2-specific activation first
185+
if iface_name == 'wlan0':
186+
# Try to get driver info if not already available
187+
if driver is None:
188+
iface_obj = Airmon.get_iface_info(iface_name)
189+
if iface_obj:
190+
driver = iface_obj.driver
191+
192+
if driver == 'icnss2':
193+
Color.p('{+} Attempting {G}ICNSS2 monitor mode{W} on {C}%s{W}... ' % iface_name)
194+
con_mode_path = '/sys/module/wlan/parameters/con_mode'
195+
if os.path.exists(con_mode_path):
196+
try:
197+
# Ensure interface is down before changing mode
198+
Ip.down(iface_name)
199+
subprocess.run(['echo', '4', '>', con_mode_path], shell=True, check=True, capture_output=True)
200+
# Bring interface up
201+
Ip.up(iface_name)
202+
# Verify it's in monitor mode
203+
if Iw.is_monitor(iface_name):
204+
Color.pl('{G}enabled (ICNSS2 specific)!{W}')
205+
# TODO: Consider if we need to set cls.use_ipiw or other flags here
206+
return iface_name
207+
else:
208+
Color.pl('{O}failed (ICNSS2 specific, could not verify monitor mode). Trying other methods...{W}')
209+
# Attempt to revert if possible, or let subsequent methods handle it
210+
# Process(['echo', '0', '>', con_mode_path], shell=True) # Optional: revert
211+
except subprocess.CalledProcessError as e:
212+
Color.pl('{R}failed (ICNSS2 specific command error: %s). Trying other methods...{W}' % e.stderr.decode().strip())
213+
except Exception as e:
214+
Color.pl('{R}failed (ICNSS2 specific error: %s). Trying other methods...{W}' % str(e))
215+
else:
216+
Color.pl('{O}con_mode path not found for ICNSS2. Trying other methods...{W}')
217+
218+
183219
# If driver is deprecated then skip airmon-ng
184220
if driver not in Airmon.DEPRECATED_DRIVERS:
185221
# Try to enable using Airmon-ng first (for better compatibility)
@@ -200,16 +236,19 @@ def start(cls, interface):
200236
if not Airmon.isdeprecated:
201237
# if that also fails, just give up
202238
if enabled_interface is None:
239+
Color.pl('{R}failed to enable monitor mode using standard methods.{W}')
203240
raise Exception('Failed to enable monitor mode')
204241

205242
# Assert that there is an interface in monitor mode
206-
interfaces = Iw.get_interfaces(mode='monitor')
207-
if len(interfaces) == 0:
208-
raise Exception('No interfaces in monitor mode')
243+
# interfaces = Iw.get_interfaces(mode='monitor') # This might be too early if mon iface has a new name
244+
# We rely on Iw.is_monitor(enabled_interface) or similar check later.
245+
if not Iw.is_monitor(enabled_interface):
246+
# Airmon-ng sometimes creates a new interface (e.g. wlan0mon)
247+
# We need to check if *any* monitor interface was created if enabled_interface itself is not in mon mode.
248+
# However, our _parse_airmon_start should return the *new* monitor interface name.
249+
Color.pl('{R}interface %s not in monitor mode after airmon-ng/iw.{W}' % enabled_interface)
250+
raise Exception(f'Interface {enabled_interface} not in monitor mode after airmon-ng/iw')
209251

210-
# Assert that the interface enabled by airmon-ng is in monitor mode
211-
if enabled_interface not in interfaces:
212-
raise Exception('Enabled interface not in monitor mode')
213252

214253
# No errors found; the device 'enabled_iface' was put into Mode:Monitor.
215254
Color.pl('{G}enabled{W}!')
@@ -447,4 +486,4 @@ def start_network_manager():
447486
print('Running yes...')
448487
time.sleep(1)
449488
print('yes should stop now')
450-
p.interrupt()
489+
p.interrupt()

0 commit comments

Comments
 (0)