threst's Blog

pwnable_collision

2018/12/18 Share

12.18
Daddy told me about cool MD5 hash collision today.
I wanna do something like that too!
地址:ssh col@pwnable.kr -p2222 (pw:guest)

题目源码

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

这个程序大致的流程就是:

1.用户输入20个char字符
2.然后经过check_password函数将20个字符转化为5个int型的数字(每个数字占4个字节)
3.再将5个数字相加,是否等于hashcode
4.hashcode的值为0x21DD09EC,转化为十进制就是568134124

解题思路:

1.将20个字符分为2个部分
2.前16个字符全是0x02,那么就是0x020202024
3.为了保证5个整数之和为hashcode,后4个字符为`hex(0x21DD09EC-(0x02020202
4))4.得到后4个字符为0x19d501e4`

那么我们的payload就是
python -c "print '\x02\x02\x02\x02'*4 + '\x19\xd5\x01\xe4'"
但是经过尝试,失败了,

原来是数字在内存中是按照小端序存储,所以将payload修改成这样:
python -c "print '\x02\x02\x02\x02'*4 + '\xe4\x01\xd5\x19'"

https://api.superbed.cn/pic/5c18908ac4ff9e2b4e04502a

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

CATALOG
  1. 1. 这个程序大致的流程就是:
  2. 2. 解题思路: