給出了一個(gè)可以連接的地址,試著連接得 讓我們輸入一字符串,長度要為15,且經(jīng)過sha384加密后,最后六位字符為'd709bb',可根據(jù)這些寫一個(gè)小小的腳本來找出符合這些條件的字符串 如下: import hashlib import string,random for i in range(100000000000000,199999999999999): temp=hashlib.sha384(str(i).encode()).hexdigest() if temp[-6:]=='d709bb': print(str(i)) break 結(jié)果如下:
輸入字符串后,又顯示
輸入B后,顯示代碼如下: def babymd5(m, n, x_head, y_head, x, y): if x.startswith(x_head) and y.startswith(y_head): for _ in range(m): xhash = md5(x.encode('utf-8')).hexdigest() x = xhash for _ in range(n): yhash = md5(y.encode('utf-8')).hexdigest() y = yhash if xhash == yhash: return True return False 輸入C后,顯示代碼如下: | (m, n, x_head, y_head) = (202, 201, 'nPz', 'dead') 輸入R后,提示讓我們輸入x 總結(jié)一下,流程大概就是已知一個(gè)函數(shù)babymd5和參數(shù)條件,即函數(shù)的參數(shù)前4個(gè)為(202,201,'nPz','dead'),讓我們輸入讓函數(shù)babymd5返回結(jié)果為True的x和y 分析下函數(shù)babymd5的大概流程: ①判斷x是否以x_head開頭,y是否以y_head開頭,若此條件不通過,則直接返回false ②將x進(jìn)行md5加密,并對(duì)每次的結(jié)果進(jìn)行循環(huán)加密,總加密次數(shù)為m次,最后加密結(jié)果為xhash ③將y進(jìn)行md5加密,并對(duì)每次的結(jié)果進(jìn)行循環(huán)加密,總加密次數(shù)為n次,最后加密結(jié)果為yhash ④若最后xhash與yhash恒相等,那么函數(shù)會(huì)返回True,否則返回False 這里難點(diǎn)就是如何找到這樣的x和y,使得它們經(jīng)過不同次數(shù)的md5加密后,值會(huì)相等,(我就被難倒了!參考了下wphttps://github.com/TalaatHarb/ctf-writeups/blob/main/asisctf2020/babymd5,寫的很詳細(xì)?。?/p> 函數(shù)中,很特殊的一個(gè)過程就是對(duì)結(jié)果反復(fù)進(jìn)行循環(huán)加密,而y_head='dead','dead'又是一個(gè)合法的十六進(jìn)制表示,且x加密循環(huán)的次數(shù)m>對(duì)y循環(huán)加密的次數(shù)n,故,我們可以把y看成x循環(huán)md5加密n次后的一個(gè)中間結(jié)果,即只要找到這樣的一個(gè)x,對(duì)它進(jìn)行循環(huán)解密n次后,它的結(jié)果temphashx恰以'dead'開頭,而這個(gè)結(jié)果temphashx也就是我們需要的y。腳本如下: import hashlib import string,random def babymd5(m, n, x_head, y_head, x, y): if x.startswith(x_head) and y.startswith(y_head): for _ in range(m): xhash = hashlib.md5(x.encode('utf-8')).hexdigest() x = xhash for _ in range(n): yhash = hashlib.md5(y.encode('utf-8')).hexdigest() y = yhash if xhash == yhash: return True return False dict=string.ascii_letters+string.digits+string.punctuation print(dict) counter=1 found=False length=32 x_head='nPz' y_head='dead' m=202 n=201 while not found: tmp=x_head+''.join(random.choice(dict) for _ in range(length)) possible_x=tmp res=tmp for _ in range(m-n): res=hashlib.md5(res.encode()).hexdigest() if res.startswith('dead'): possible_x=res x=tmp y=res print("x:",x) print("y:",y) found=babymd5(202, 201, 'nPz', 'dead',x,y) break if(counter%10000==0): print("attemp:"+str(counter)+'次') if(counter%100000==0): print("attemp:"+str(counter)+'次') counter=counter+1 得到結(jié)果:
輸入對(duì)應(yīng)的x和y后,得到flag!
|
|