代码如下
#include <stdio.h>#include <string.h>unsignedlonghashcode=0x21DD09EC;unsignedlongcheck_password(constchar*p){int*ip=(int*)p;inti;intres=0;for(i=0;i<5;i++){res+=ip[i];}returnres;}intmain(intargc,char*argv[]){if(argc<2){printf("usage : %s [passcode]\n",argv[0]);return0;}if(strlen(argv[1])!=20){printf("passcode length should be 20 bytes\n");return0;}if(hashcode==check_password(argv[1])){system("/bin/cat flag");return0;}elseprintf("wrong passcode.\n");return0;}
从题意来看,输入5个int共20bytes,其和要求为0x21DD09EC
。于是可以让前4个数为0xffffffff=-1
,最后一个数为0x21dd09ec+4=0x21dd09f0
具体在输入时,用的是perl
。一开始没有用双引号,由于0x09
是\t
,被shell认为是参数分隔了。于是用双引号括起来:
$ ./col "$(perl -e 'print "\xff"x16 . "\xf0\x09\xdd\x21"')"