MD5截断爆破脚本
最开始自己写的时候忘了多线程了...
import multiprocessing
import hashlib
import random
import string
import sys
CHARS = string.ascii_letters + string.digits
def cmp_md5(substr, stop_event, str_len, start=0, size=20):
global CHARS
while not stop_event.is_set():
rnds = ''.join(random.choice(CHARS) for _ in range(size))
md5 = hashlib.md5(rnds.encode('utf-8'))
if md5.hexdigest()[start: start+str_len] == substr:
print (rnds)
stop_event.set()
if __name__ == '__main__':
substr = "c4d038"
str_len = len(substr)
cpus = multiprocessing.cpu_count()
stop_event = multiprocessing.Event()
processes = [multiprocessing.Process(target=cmp_md5, args=(substr,
stop_event, str_len, 0))
for i in range(cpus)]
for p in processes:
p.start()
for p in processes:
p.join()