0%

open-source

题目描述:菜鸡学逆向学得头皮发麻,终于它拿到了一段源代码

C源代码

image-20200708105330069

编译完后,开始分析代码

第一个判断条件

1
2
3
4
5
int main(int argc, char *argv[]) {
if (argc != 4) {
printf("what?\n");
exit(1);
}

判读输入的参数是否满足4个,文件名本身也算一个所以输入文件名加三个参数即可,程序就会继续执行

CMD:文件名 1 2 3

第二个判断条件

1
2
3
4
5
unsigned int first = atoi(argv[1]);
if (first != 0xcafe) {
printf("you are wrong, sorry.\n");
exit(2);
}

判断第一个参数是否等于0xcafe转化为十进制等于51966,等于程序就继续执行

atoi函数是将字符串转化为数字

CMD:文件名 51966 2 3

第三个判断条件

1
2
3
4
5
unsigned int second = atoi(argv[2]);
if (second % 5 == 3 || second % 17 != 8) {
printf("ha, you won't get it!\n");
exit(3);
}

当参数对5取余等于3,并且对17取余不等于8时就会退出程序

编写代码,25,42,59,76都能满足条件

1
2
3
4
5
6
7
i = 0
while(i<100):
if i%5==3 or i%17!=8:
pass
else:
print i
i = i+1

image-20200708113343415

CMD:文件名 51966 25 3

第三个参数

strcmp函数比较两个字符串如果相等,返回值就是0,为0就不会进入if条件中的代码

CMD:文件名 51966 25 h4cky0u

1
2
3
4
if (strcmp("h4cky0u", argv[3])) {
printf("so close, dude!\n");
exit(4);
}

最终结果

image-20200708105314341

方法二:

直接把三个参数的值固定,带入到hash函数中直接运算出结果

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <stdio.h>
#include <string.h>

int main()
{

int first = 0xcafe;
int second = 25;
char *argv = "h4cky0u";
unsigned int hash = first * 31337 + (second % 17) * 11 + strlen(argv) - 1615810207;
printf("Get your key: ");
printf("%x\n", hash);
return 0;
}

输出结果:
Get your key: c0ffe