题目
#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;
}
WP:
题目的逻辑也很简单,要求输入20个字符,每四个字符为一组成为一个字节的数据,一共5组相加结果得到的值为hashcode就得到了flag.这个碰撞的概率很大,所以先尝试取一个字节的字符让他乘4,再用已知的hashcode减去得到最后4个字节数据,检查是否每个字节为可见字符。如果不满足重新尝试。我选的字符程序如下:
#include<stdio.h>
int main(){
int a=0x31283030;
int hashcode=0x21dd09ec;
int res = a+a+a+a;
int t=0x5d3c492c;
printf("0x%x\n",hashcode-res);
printf("0x%x\n",t+res);
return 0;
}
最后得到的字符串为:”00(100(100(100(1,I<]”
输入这个即可得到flag