題目名稱:open-source
題目地址:open-source
解題思路
首先
下載附件=-=
發現是.c文件??
陷入沉思hhh
這不就是源碼嗎?
DEV-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) {
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;
}
其次
分析一下
輸出hash即可
嘗試刪除四個if發現不行
因爲second沒有值了
細看一次代碼
更改如下
#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);
}*/
//跳出語句就令first爲該值
/*unsigned int second = atoi(argv[2]);
if (second % 5 == 3 || second % 17 != 8) {
printf("ha, you won't get it!\n");
exit(3);
}*/
//讓second的值等於8就跳出去了
/*if (strcmp("h4cky0u", argv[3])) {
printf("so close, dude!\n");
exit(4);
}
printf("Brr wrrr grr\n");*/
//讓aygv[3]爲 "h4cky0u"跳出
//unsigned int hash = first * 31337 + (second % 17) * 11 + strlen(argv[3]) - 1615810207;
unsigned int hash = 0xcafe * 31337 + (8 % 17) * 11 + strlen("h4cky0u") - 1615810207;
printf("Get your key: ");
printf("%x\n", hash);
return 0;
}
最後
運行源碼,得到flag:c0ffee