这题先看题目源码
#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分成五份,每份都要在转化成16进制之后是一个长度为20的字符串,但是这里需要注意的是,1、注意内存中的小端存储,这个需要运用pwn库中的p32()来转换;2、每个子字符串中都不能出现字符串结束的标记:\x00。
接下来就是写python的脚本了,小弟认为,刚刚接触pwn的初学者来说,感觉脚本是一道很难