题目来源:
HackYou CTF
题目描述:
菜鸡学逆向学得头皮发麻,终于它拿到了一段源代码
题目附件:
8b6405c25fe447fa804c6833a0d72808.c
题目思路:
对源码分析
解题过程:
查看源码,结合注释
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[]) {
if (argc != 4) {
printf("what?\n");
exit(1);
}
unsigned int first = atoi(argv[1]);
if (first != 0xcafe) {//得出first=0xcafe转换成10进值为51966
printf("you are wrong, sorry.\n");
exit(2);
}
unsigned int second = atoi(argv[2]);
if (second % 5 == 3 || second % 17 != 8) {//second=25
printf("ha, you won't get it!\n");
exit(3);
}
if (strcmp("h4cky0u", argv[3])) {//argv[3]=’h4cky0u’
printf("so close, dude!\n");
exit(4);
}
printf("Brr wrrr grr\n");
unsigned int hash = first * 31337 + (second % 17) * 11 + strlen(argv[3]) - 1615810207;
printf("Get your key: ");
printf("%x\n", hash);
return 0;
}
可以看到需要添三个参数,第一个是0xcafe,第二个是满足or的一个数字,第三个是h4cky0u,最后会输出key
#include <stdio.h>
#include <string.h>
int main () {
unsigned int first = 51966;
unsigned int second=25;
unsigned int hash = first * 31337 + (second % 17) * 11 + strlen("h4cky0u") - 1615810207;
printf("Get your key: ");
printf("%x\n", hash);
return 0;
}
在网站运行一下 上面的c脚本,或者下面的python脚本
first=int('cafe',16)
argv3='h4cky0u'
for second in range(100):
if((second%5!=3)and(second%17==8)):
break
hash=int(first *31337+(second%17)*11+len(argv3)-1615810207)
print(hex(hash))
c0ffee