question
Daddy told me about cool MD5 hash collision today.
I wanna do something like that too!
ssh col@pwnable.kr -p2222 (pw:guest)
solution
连上ssh后,查看根目录文件发现存在col.c
,col
,flag
三个文件,显然flag
是需要获取的内容
通过ls -la
查看文件权限
发现当前用户没有权限查看flag文件
分析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;
}
要使hashcode等于check_password函数的返回值res才能有flag,即hashcode == 0x21DD09EC == res,看看check_password函数,强转成int,且分五次输出累加到res,同时下面的main函数的第二个if限制长度为20,一个int为4个字节,分五组刚好20个字节
将0x21DD09EC转成十进制568134124,为了方便计算就加一再除以5,获得113626825,扣除之前的加一,就是1136268254,即(113626825*4+1136268254=568134124)
再转成十六进制0x6c5cec9*4+0x6c5cec8=0x21dd09ec
pwn
知道了要输入的值就可以进行输入了 这里用python进行小端输入
$是unix的命令行的提示符,-c 是命令执行
./col $(python -c 'print "\xc9\xce\xc5\x06"*4+"\xc8\xce\xc5\x06"')