collision - 3 pt

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

ssh col@pwnable.kr -p2222 (pw:guest)

파일 목록을 보았다.

col@pwnable:~$ ls
col  col.c  flag

col.c 파일 내용을 보았다.

col@pwnable:~$ cat 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;
}

check_password() 는 입력 값을 4 byte 씩 잘라서 더한 후 그 결과 값을 반환한다.

이 값이 hashcode 인 0x21DD09EC와 같으면 문제가 풀린다.

0x21DD09EC는 dec으로 568134124이다.

568134124=113,626,8244+113626828568134124 = 113,626,824‬ * 4 + 113626828

113626824는 hex로 0x6C5CEC8이고, 113626828은 hex로 0x6C5CECC‬이다.

리틀 엔디안을 따르므로 반대로 적어 넣어주면 아래와 같다.

col@pwnable:~$ ./col `python -c 'print("\xC8\xCE\xC5\x06" * 4 + "\xCC\xCE\xC5\x06")'`
daddy! I just managed to create a hash collision :)

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

Last updated