开发思路
1、通过 string模块 自动生成字典;
2、使用permutations()函数,对字典进行全排列;
3、使用 md5模块 对全排列的字典进行转换;
4、使用了多线程,分别对5~18位字符串进行md5碰撞,以防止时间太长(虽然现在也要很久)。
md5碰撞函数
1
2
3
4
5
6
7
8
9
10
11
12
13
|
def md5_poj( self , md5_value, k): if len (md5_value) ! = 32 : print ( "error" ) return md5_value = md5_value.lower() # permutations() 全排列 for item in permutations(all_letters, k): item = "".join(item) if item = = "hongrisec@2019" : print (item) if md5(item.encode()).hexdigest() = = md5_value: print ( '\n success: ' + md5_value + ' ==> ' + item) self .__mdfive = 1 |
其中 if len(md5_value) != 32 判断所输入的md5是否为32位的
主函数
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
def main( self ): NT_md5 = input ( "请填写MD5:" ) start_time = time() t_list = [] print ( "正在查询..." ) # 添加线程 t_first = threading.Thread(target = self .md5_first, args = (NT_md5,)) t_first.daemon = 1 t_first.start() for k in range ( 5 , 18 ): t = Process(target = self .md5_poj, args = (NT_md5, k)) # t = threading.Thread(target=self.md5_poj, args=(NT_md5, k)) t.daemon = 1 # 守护程序 t_list.append(t) # 启动所有线程 for i in t_list: i.start() # 当 __mdfive == 1 时结束所有线程 while 1 : if self .__mdfive: break print ( "\n查询结束!" ) print ( '使用了 %f 秒' % (time() - start_time)) |
完整代码脚本
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
import threading from multiprocessing import Process from hashlib import md5 from itertools import permutations from string import ascii_letters, digits, ascii_lowercase, ascii_uppercase from time import time all_letters = ascii_lowercase + '.,;@' + digits class MDfive: def __init__( self ): self .__mdfive = 0 def md5_poj( self , md5_value, k): if len (md5_value) ! = 32 : print ( "error" ) return md5_value = md5_value.lower() # permutations() 全排列 for item in permutations(all_letters, k): item = "".join(item) if item = = "hongrisec@2019" : print (item) if md5(item.encode()).hexdigest() = = md5_value: print ( '\n success: ' + md5_value + ' ==> ' + item) self .__mdfive = 1 # 判断 md5 是否与空匹配 def md5_first( self , md5_firstvalue): if len (md5_firstvalue) ! = 32 : elif md5_firstvalue = = "31d6cfe0d16ae931b73c59d7e0c089c0" : print ( "\n密码为空!" ) self .__mdfive = 1 def main( self ): NT_md5 = input ( "请输入MD5:" ) start_time = time() t_list = [] print ( "正在查询..." ) # 添加线程 t_first = threading.Thread(target = self .md5_first, args = (NT_md5,)) t_first.daemon = 1 t_first.start() for k in range ( 5 , 18 ): t = Process(target = self .md5_poj, args = (NT_md5, k)) # t = threading.Thread(target=self.md5_poj, args=(NT_md5, k)) t.daemon = 1 # 守护程序 t_list.append(t) # 启动所有线程 for i in t_list: i.start() # 当 __mdfive == 1 时结束所有线程 while 1 : if self .__mdfive: break print ( "\n查询结束!" ) print ( '使用了 %f 秒' % (time() - start_time)) if __name__ = = '__main__' : MDfive().main() |
到此这篇关于基于python的MD5脚本的文章就介绍到这了,更多相关python MD5脚本内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!
原文链接:https://www.cnblogs.com/spmonkey/p/16067719.html