open-source Write Up

Catalogue
  1. 1. open-source Write Up

open-source Write Up

难度:☆☆☆

这道题提供了一个c语言源代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#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;
}

很显然我们需要让这段代码跑起来并且跑到最后让程序自己算出来flag,

所以我们我们需要把main函数需要的参数值删掉并且放到main函数内去定义,修改如下:

1
2
3
int main() {
int argc = 4;
char * argv[] = {"1","51966","25","h4cky0u"};

这里的atoi()函数的功能是从前往后取字符串整数部分,所以我们把argv[1]所需要的整数的十六进制转换成十进制0xcafe,即51996,即可

然后点击调试,程序即可顺利运行到最后