# -*- coding: utf-8 -*- import multiprocessing import hashlib import random import string import sys CHARS = string.digits defcmp_md5(substr, stop_event, str_len, start=0, size=10): global CHARS whilenot stop_event.is_set(): rnds = '0e' rnds += ''.join(random.choice(CHARS) for _ in range(size)) md4 = hashlib.new('md4', rnds) value = md4.hexdigest() if value[start: start+str_len] == substr and if_havechar(value[start+str_len:]): print rnds #stop_event.set() #print rnds + "=>" + value + "\n" #碰撞双md5 #md4 = hashlib.new('md4',value) # if md4.hexdigest()[start: start+str_len] == substr and if_havechar(md4.hexdigest()[start+str_len:]): # print rnds+ '=>' + value+'=>'+ md4.hexdigest() + '\n' # stop_event.set() defif_havechar(str_list): for i in range(len(str_list)): if (str_list[i] >= 'a'and str_list[i] <= 'z') or (str_list[i] >='A'and str_list[i] <='Z'): returnFalse returnTrue
if __name__ == '__main__': substr = sys.argv[1].strip() start_pos = int(sys.argv[2]) if len(sys.argv) > 1else0 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()
第三关:第3关依然考察hash加密并且加入了sql注入的知识点,SELECT * FROM flag WHERE password = 'md5($_GET["hash4"],true)',从查询使用的SQL语句可以看出,md5函数的第二个参数是True,这意味着加密后的MD5结果是以二进制的形式输出,那么就可以爆破一个md5结果是可以绕过判断的字符串。如果像绕过判断就需要构造一个MD5值是'or'真,这里参考一下http://mslc.ctf.su/wp/leet-more-2010-oh-those-admins-writeup/,payload` ffifdyop`