Fork me on GitHub

pwnable.kr-collision

分析

查看源码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;
}

check_password函数对传入的字符串指针强制转换为int类型,然后将前5个整数相加返回。
最后判断hashcode是否与返回结果相等。
源码还是比较简单的,只要构造好程序的传入参数就行了,payload有很多,但要注意一些会影响传入和运算的特殊字符如\x00,\x09等。
我的做法是将前16个字节置为1最后算出一个整数,payload为

1
./col `python -c "print '\x01'*16+'\xE8\x05\xD9\x1D'"`

1
2
3
col@ubuntu:~$ ./col `python -c "print '\x01'*16+'\xE8\x05\xD9\x1D'"`
daddy! I just managed to create a hash collision :)
col@ubuntu:~$
-------------本文结束感谢您的阅读-------------

本文标题:pwnable.kr-collision

文章作者:r00tnb

发布时间:2017年12月08日 - 12:12

最后更新:2018年08月04日 - 22:08

原始链接:https://r00tnb.github.io/2017/12/08/pwnable.kr-collision/

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。

坚持原创,您的鼓励是我最大的动力!