Daddy told me about cool MD5 hash collision today.
I wanna do something like that too!
ssh col@pwnable.kr -p2222 (pw:guest)
簡(jiǎn)單的hash練習(xí),源代碼如下:
#include <stdio.h>
#include <string.h>
unsigned long hashcode = 0x21DD09EC;
unsigned long check_password(const char* p){
int* ip = (int*)p;
int i;
int res=0;
for(i=0; i<5; i++){
res += ip[i];
}
return res;
}
int main(int argc, char* argv[]){
if(argc<2){
printf("usage : %s [passcode]\n", argv[0]);
return 0;
}
if(strlen(argv[1]) != 20){
printf("passcode length should be 20 bytes\n");
return 0;
}
if(hashcode == check_password( argv[1] )){
system("/bin/cat flag");
return 0;
}
else
printf("wrong passcode.\n");
return 0;
}
要求傳遞一個(gè)參數(shù),長(zhǎng)度為20byte,由于int為32bit沿量,4byte為一個(gè)int,20byte的數(shù)據(jù)即int[5]叽讳。5個(gè)整數(shù)相加結(jié)果為0x21DD09EC即可快压。
另外糙俗,strlen取長(zhǎng)度绷杜,參數(shù)中間不可加雜\x00 (null)直秆。
可以構(gòu)造為 "\x01"*16+"\xE8\x05\xD9\x1D" ,注意小端序鞭盟。
用python傳入:
col@ubuntu:~$ ./col $(python -c 'print "\x01"*16+"\xE8\x05\xD9\x1D"')
daddy! I just managed to create a hash collision :)