XCTF 攻防世界 Reverse新手题(open-source)
日期: 2020-12-12 分类: 跨站数据测试 398次阅读
XCTF 攻防世界 Reverse新手题(open-source)
这道题主要是分析代码,因为源代码已经直接给出了:
#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) {
printf("you are wrong, sorry.\n");
exit(2);
}
unsigned int second = atoi(argv[2]);
if (second % 5 == 3 || second % 17 != 8) {
printf("ha, you won't get it!\n");
exit(3);
}
if (strcmp("h4cky0u", argv[3])) {
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;
}
首先,看第一个first,通过first != 0xcafe,可以直接让first=0xcafe
再看第二个second,second % 5 == 3 || second % 17 != 8,可以直接尝试让second=8,满足判断条件即可
最后,看strcmp(“h4cky0u”, argv[3]),这个函数是用来判断是否相等的,没思路的可以接着往下看,可以看到strlen(argv[3]),也就是说只要字符串的长度即可,设为7
最后将上面的值直接带入hash里面计算即可:
#include <stdio.h>
#include <string.h>
int main() {
unsigned int hash = 0xcafe * 31337 + (8 % 17) * 11 + 7 - 1615810207;
printf("%x\n", hash);
return 0;
}
输出的结果即为flag
除特别声明,本站所有文章均为原创,如需转载请以超级链接形式注明出处:SmartCat's Blog
精华推荐