pwn的学习2 coliision

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_35396598/article/details/85288331

pwnable.kr  第二题  collision

还是 先看代码。

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

根据代码,可以得知,首先要保证输入一个字符串长度为20的字符串
又由代码可得,
因为 int类型是4个字节
char 数组一个为1个字节,长度20即20个字节
for循环又是5次,刚好5*4=20
也就是说函数返回的结果应该等于long hashcode = 0x21DD09EC;  
那么就得构造了。。
0x21DD09EC=568134124
所以,
如图
4个0x06c5cec9和一个0x06c5cec8  即可  //感谢 来自https://www.jianshu.com/p/2f9b08bb48a8的数据

猜你喜欢

转载自blog.csdn.net/qq_35396598/article/details/85288331