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 58 59 60 61 62
| ''' 使用方法:python md5Crack.py "你要碰撞的字符串" 字符串的起始位置 例如:python md5Crack.py “0e" 0 将产生MD5值为0e开头的字符串。
''' import multiprocessing import hashlib import random import string import sys CHARS = string.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)) md51 = hashlib.md5(rnds) value1 = md51.hexdigest() if value1[start: start+str_len] == substr:
''' #碰撞单MD5 print rnds stop_event.set() '''
''' #碰撞双md5 md52 = hashlib.md5(value1) if md52.hexdigest()[start: start+str_len] == substr: print rnds+ "=>" + value1+"=>"+ md52.hexdigest() + "\n" stop_event.set() '''
md52 = hashlib.md5(value1) value2 = md52.hexdigest() if value2[start: start + str_len] == substr: md53 = hashlib.md5(value2) if md53.hexdigest()[start: start + str_len] == substr: print rnds + "=>" + value1 + "=>" +value2+"=>"+ md53.hexdigest() + "\n" stop_event.set()
if __name__ == '__main__': substr = sys.argv[1].strip() start_pos = int(sys.argv[2]) if len(sys.argv) > 1 else 0 str_len = len(substr) cpus = multiprocessing.cpu_count() stop_event = multiprocessing.Event() processes = [multiprocessing.Process(target=cmp_md5, args=(substr, stop_event, str_len, start_pos)) for i in range(cpus)] for p in processes: p.start() for p in processes: p.join()
|