pwnable.kr —— collision

question#

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

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

题目需要我们使用ssh登录到服务器上查看ssh col@pwnable.kr -p2222,密码是guest,有的时候可能有身份的校验,这个时候需要加上参数-o StrictHostKeyChecking=no进行登录

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

analyse#

可以看到,要求输入一个20个字符组成的串,然后在check_password函数中,以int的方式读取这20个字符的值,如果加起来的值等于0x21DD09EC的话,那么就可以通过hashcode==check_password(argv[1])的判断,读取flag的内容。

get flag#

随便凑五个数,比如有0x05050505*4+0xdc8f5d8,那么可以写出以下命令

1
2
col@ubuntu:~$ ./col `python -c 'print("\x05"*16+"\xd8\xf5\xc8\x0d")'`
daddy! I just managed to create a hash collision :)

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

评论