首先先看一下文件类型
然后拉入IDA
看到程序有一个关键函数Decry:
unsigned __int64 Decry()
{
char v1; // [rsp+Fh] [rbp-51h]
int v2; // [rsp+10h] [rbp-50h]
int v3; // [rsp+14h] [rbp-4Ch]
int i; // [rsp+18h] [rbp-48h]
int v5; // [rsp+1Ch] [rbp-44h]
char src[8]; // [rsp+20h] [rbp-40h]
__int64 v7; // [rsp+28h] [rbp-38h]
int v8; // [rsp+30h] [rbp-30h]
__int64 v9; // [rsp+40h] [rbp-20h]
__int64 v10; // [rsp+48h] [rbp-18h]
int v11; // [rsp+50h] [rbp-10h]
unsigned __int64 v12; // [rsp+58h] [rbp-8h]
v12 = __readfsqword(0x28u);
*(_QWORD *)src = 'SLCDN';
v7 = 0LL;
v8 = 0;
v9 = 'wodah';
v10 = 0LL;
v11 = 0;
text = join(key3, (const char *)&v9); // key3 --> kills
strcpy(key, key1); // key1 --> ADSFK
strcat(key, src); // key --> ADSFKNDCLS (now)
v2 = 0;
v3 = 0;
getchar();
v5 = strlen(key);
for ( i = 0; i < v5; ++i ) // v5=10
{
if ( key[v3 % v5] > 64 && key[v3 % v5] <= 90 )
key[i] = key[v3 % v5] + 32;
++v3;
} // key --> adsfkndcls
printf("Please input your flag:");
while ( 1 )
{
v1 = getchar();
if ( v1 == 10 )
break;
if ( v1 == 32 )
{
++v2;
}
else
{
if ( v1 <= '`' || v1 > 'z' )
{
if ( v1 > '@' && v1 <= 'Z' ) // 大写字母
str2[v2] = (v1 - 39 - key[v3++ % v5] + 97) % 26 + 97;
}
else
{ // 小写字母
str2[v2] = (v1 - 39 - key[v3++ % v5] + 97) % 26 + 97;
}
if ( !(v3 % v5) )
putchar(' ');
++v2;
}
}
if ( !strcmp(text, str2) )
puts("Congratulation!\n");
else
puts("Try again!\n");
return __readfsqword(0x28u) ^ v12;
}
其中要注意两个地方由于小段序储存的关系,在实际当中应该反过来写:
*(_QWORD *)src = 'SLCDN';
v9 = 'wodah';
在其中还有一个自定义函数join:
char *__fastcall join(const char *a1, const char *a2)
{
size_t v2; // rbx
size_t v3; // rax
char *dest; // [rsp+18h] [rbp-18h]
v2 = strlen(a1);
v3 = strlen(a2);
dest = (char *)malloc(v2 + v3 + 1);
if ( !dest )
exit(1);
strcpy(dest, a1);
strcat(dest, a2);
return dest;
}
功能主要是将后两个字符串拼接起来
所以这题的思路就很清晰了,知道str2应该等于什么,直接写逆向脚本
#include<stdio.h>
#include<string.h>
int main() {
char key[] = "ADSFKNDCLS";
char text[] = "killshadow";
int v3 = 0, v5 = 0;
int i, j;
char str2[11] = {0};
v5 = strlen(key);
for (i = 0; i < v5; ++i){
if (key[v3 % v5] > 64 && key[v3 % v5] <= 90)
key[i] = key[v3 % v5] + 32;
++v3;
}
for (i = 0;i < v5 ;i++)
for (j = 0;;j++){
str2[i] = text[i] - 97 + 26 * j + 39 - 97 + key[i];
if (str2[i] > 64 && str2[i] < 91)
break;
}
puts(str2);
}
运行结果:
注:这题大小写都可行,因为程序中也做了小写的处理,本人只做了大写的,小写其实同理