pwnable.kr之collision(3)
1、查看文件,flag无访问权限
2、查看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; }
3、测试,随便输入参数提示错误
4、分析check_password()源码
- int* ip = (int*)p; //将输入的char类型的字符转换为int类型指针的,也就是十六进制转十进制(四字节)
- for(i=0; i<5; i++){res += ip[i];} //将输入的数值分为五组,并把每组的值相加赋值给int型的res变量
据此得知4字节分为5组,总共20个字节,且返回res == hashcode==0x21DD0EC
5、构造参数payload:
0x01010101*4+0x1DD905E8 = 021DD0EC
使用python输出参数
python -c “print ‘\xe8\x05\xd9\x1d’+’\x01’*16″|xargs ./col //注意小端序排列