下载出来是个C语言编辑文件,添加注释如下所示:
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h> //linux的线程库,所以要在linux中才可运行 #define FLAG_LEN 20void * checking(void *arg) { //这道题的关键函数 char *result = malloc(sizeof(char));char *argument = (char *)arg;*result = (argument[0]+argument[1]) ^ argument[2]; //返回值等于0,因为a^a=0,所以 argument[0]+argument[1]=argument[2]//随机数+密钥=flag return result;
}int highly_optimized_parallel_comparsion(char *user_string)
{int initialization_number;int i;char generated_string[FLAG_LEN + 1];generated_string[FLAG_LEN] = '\0';while ((initialization_number = random()) >= 64); //initialization_number随机产生的数大于等于64 //这里用了random()随机数,我们可以发现代码中并没有随机数种子,所以他这个随机数每次都是固定的,我们可以运行一下会发现每次都是41,//windows系统下是41,Linux下就是37,这道题要放到Linux系统下来看int first_letter;first_letter = (initialization_number % 26) + 97; //initialization_number的值对26求余+ascii(a)=97,最后first_letter的值范围//在'a'-'z' pthread_t thread[FLAG_LEN]; //创建一个线程 char differences[FLAG_LEN] = {0, 9, -9, -1, 13, -13, -4, -11, -9, -1, -7, 6, -13, 13, 3, 9, -13, -11, 6, -7};char *arguments[20];//指针数组 for (i = 0; i < FLAG_LEN; i++) {arguments[i] = (char *)malloc(3*sizeof(char));//一个大小为3的数组,然后分别进行赋值 arguments[i][0] = first_letter; //随机数 arguments[i][1] = differences[i];//key arguments[i][2] = user_string[i];//键盘输入没有加密的flag pthread_create((pthread_t*)(thread+i), NULL, checking, arguments[i]);//多线程//将arguments[i]他传到了checking函数中,然后调用checking函数,这个函数返回的id后面就保存在(pthread_t*)(thread+i) }void *result;int just_a_string[FLAG_LEN] = {115, 116, 114, 97, 110, 103, 101, 95, 115, 116, 114, 105, 110, 103, 95, 105, 116, 95, 105, 115};for (i = 0; i < FLAG_LEN; i++) {pthread_join(*(thread+i), &result);generated_string[i] = *(char *)result + just_a_string[i];free(result);free(arguments[i]);}int is_ok = 1;for (i = 0; i < FLAG_LEN; i++) {if (generated_string[i] != just_a_string[i])return 0;} //因为generated_string[i] = *(char *)result + just_a_string[i]//并且 generated_string[i] = just_a_string[i] 说明 返回值*(char *)result=0return 1;
}int main()
{char *user_string = (char *)calloc(FLAG_LEN+1, sizeof(char)); //开辟一片内存,赋值给user_string fgets(user_string, FLAG_LEN+1, stdin);//对输入的值user_string进行输入 int is_ok = highly_optimized_parallel_comparsion(user_string);//函数运算输入的值user_string,并将结果给is_ok if (is_ok)printf("You win!\n");elseprintf("Wrong!\n");return 0;
}
关键代码:
因为generated_string[i] = *(char *)result + just_a_string[i]
并且 generated_string[i] = just_a_string[i] 说明 返回值*(char *)result=0——→*result = (argument[0]+argument[1]) ^ argument[2] 因为a^a=0
——→argument[0]+argument[1]=argument[2]
——→随机数+密钥=flag
编写脚本:
#include<stdio.h>
int main(){char differences[20] = {0, 9, -9, -1, 13, -13, -4, -11, -9, -1, -7, 6, -13, 13, 3, 9, -13, -11, 6, -7};int aa=97;for(int i=0;i<=26;i++){for(int j=0;j<20;j++){printf("%c",differences[j]+aa+i);}printf("\n");}
}
//lucky_hacker_you_are