pwnable.kr [Toddler's Bottle] - collision

Daddy told me about cool MD5 hash collision today.
I wanna do something like that too!

ssh [email protected] -p2222 (pw:guest)

简单的hash练习,源代码如下:

#include 
#include 
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;
}

要求传递一个参数,长度为20byte,由于int为32bit,4byte为一个int,20byte的数据即int[5]。5个整数相加结果为0x21DD09EC即可。
另外,strlen取长度,参数中间不可加杂\x00 (null)。
可以构造为 "\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 :)

你可能感兴趣的:(pwnable.kr [Toddler's Bottle] - collision)