1、單線程破解純數字密碼
注意: 不包括數字0開頭的密碼
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
import zipfile,time,sys start_time = time.time() def extract(): zfile = zipfile.ZipFile( 'IdonKnow.zip' ) #讀取壓縮包,如果用必要可以加上'r' for num in range ( 1 , 99999 , 1 ): try : pwd = str (num) zfile.extractall(path = '.' ,pwd = pwd.encode( 'utf-8' )) print ( "當前壓縮密碼為:" ,pwd) end_time = time.time() print ( '單線程破解壓縮包花了%s秒' % (end_time - start_time)) sys.exit( 0 ) except Exception as e: pass if __name__ = = "__main__" : extract() |
破解結果:
2、多線程破解純數字密碼
注意: 不包括數字0開頭的密碼
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
import zipfile,time,threading start_time = time.time() flag = True # 用于判斷線程是否需要終止,為True時程序執行 def extract(password, file ): try : password = str (password) file .extractall(path = '.' , pwd = password.encode( 'utf-8' )) print ( "當前壓縮密碼為:" ,password) end_time = time.time() print ( '多線程破解壓縮包花了%s秒' % (end_time - start_time)) global flag flag = False #成功解壓其余線程終止 except Exception as e: pass def main(): zfile = zipfile.ZipFile( "test.zip" , 'r' ) for number in range ( 1 , 99999 , 1 ): if flag: thr1 = threading.Thread(target = extract, args = (number, zfile)) thr2 = threading.Thread(target = extract, args = (number, zfile)) thr1.start() thr2.start() thr1.join() thr2.join() if __name__ = = '__main__' : main() |
破解結果:
提示: 多線程對數字型的運算沒有多大幫助
3、破解英文+數字型的密碼
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
import random,zipfile,time,sys class MyIter(): cset = 'abcdefghijklmnopqrstuvwxyz0123456789' def __init__( self , min , max ): #迭代器實現初始方法,傳入參數 if min < max : self .minlen = min self .maxlen = max else : self .ninlen = max self .maxlen = min def __iter__( self ): #直接返回slef實列對象 return self def __next__( self ): #通過不斷地輪循,生成密碼 rec = '' for i in range ( 0 ,random.randrange( self .minlen, self .maxlen + 1 )): rec + = random.choice(MyIter.cset) return rec def extract(): start_time = time.time() zfile = zipfile.ZipFile( 'test1.zip' , 'r' ) for password in MyIter( 1 , 4 ): #隨機迭代出1~4位數的密碼,在不明確位數的時候做相應的調整 if zfile: try : zfile.extractall(path = '.' ,pwd = str (password).encode( 'utf-8' )) print ( "當前壓縮密碼為:" ,password) end_time = time.time() print ( '當前破解壓縮包花了%s秒' % (end_time - start_time)) sys.exit( 0 ) except Exception as e: print ( 'pass密碼:' ,password) pass if __name__ = = "__main__" : extract() |
破解結果:
總結
以上所述是小編給大家介紹的python破解zip文件密碼的方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對服務器之家網站的支持!
如果你覺得本文對你有幫助,歡迎轉載,煩請注明出處,謝謝!
原文鏈接:https://blog.csdn.net/ayouleyang/article/details/103922756