题目代码如下,要求是碰撞出一个20字节长度的字符串转换为4个int类型相加之后的值等于题目给定的hashcode
#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;
}
就直接来碰撞吧。。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define LEN 4
unsigned char buf[LEN] = "\x00\x00\x00\x00";
int main(void)
{
div_t div_val;
unsigned long hashcode = 0x21DD09EC;
div_val = div(hashcode,5);
//printf("%d,%d\n",x.quot,x.rem);
int *tmp;
int j;
for(j=LEN-1;j>=0;j--){
unsigned char i = 0x01;
for(;i<=0xff;i++){
buf[j] = i;
tmp = (int *)&buf;
if(*tmp == div_val.quot){
printf("playload is:\t");
printf("\\x%x\\x%x\\x%x\\x%x",buf[0],buf[1],buf[2],buf[3]);
printf("\\x%x\\x%x\\x%x\\x%x",buf[0],buf[1],buf[2],buf[3]);
printf("\\x%x\\x%x\\x%x\\x%x",buf[0],buf[1],buf[2],buf[3]);
printf("\\x%x\\x%x\\x%x\\x%x",buf[0],buf[1],buf[2],buf[3]);
printf("\\x%x\\x%x\\x%x\\x%x\n",buf[0]+div_val.rem,buf[1],buf[2],buf[3]);
}
if(*tmp < div_val.quot) {
continue;
}else{
buf[j] = i-0x01;
break;
}
}
}
exit(0);
}