Pwnable-collision

一样的连接ssh,输入密码,查看文件

看看col.c的源码

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

要使hashcode等于check_password函数的返回值res才能有flag,即hashcode==0x21DD09EC==res,看看check_password函数,强转成int,且分五次输出累加到res,同时下面的main函数的第二个if限制长度为20,一个int为4个字节,分五组刚好20个字节

我们将0x21DD09EC转成十进制568134124,为了方便计算就加一再除以5,获得113626825‬‬,扣除之前的加一,就是1136268254,即(113,626,825‬‬*4+113,626,8254=568134124)

再将他们转成十六进制0x6c5cec9*4+0x6c5cec8=0x21dd09ec

知道了要输入的值就可以进行输入了  这里用python进行小端输入

./col $(python -c 'print "\xc9\xce\xc5\x06"*4+"\xc8\xce\xc5\x06"')

 daddy! I just managed to create a hash collision :)

猜你喜欢

转载自www.cnblogs.com/gaonuoqi/p/11745438.html
今日推荐