The force is with those who read the source.

Pwnable.kr: collision (3 pt)

2016-08-08

Description

Daddy told me about cool MD5 hash collision today.
I wanna do something like that too!
ssh [email protected] -p2222 (pw:guest)

Exploit

fd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#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;
}

The target program converts the argument from a 20 bytes string to an array of 5 integers and sum them up. If the sum equals to 0x21DD09EC, it will output the flag. I craft the input with 4 integers of \x01\x01\x01\x01 (just for padding) plus an integer of the difference to the target hashcode. The difference can be calculated as follows.

cal.pydownload
1
2
from pwn import *
print repr(p32(0x21DD09EC - u32('\x01\x01\x01\x01')*4))

After calculating the difference, which is \xe8\x05\xd9\x1d, we can solve the problem with the input mentioned above.

$ ./col $'\xe8\x05\xd9\x1d\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01'
daddy! I just managed to create a hash collision :)

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


Blog comments powered by Disqus