用的IDA打开,然后进入的主函数_main_0
__int64 __cdecl main_0()
{
int v0;
const char *v1;
size_t v2;
int v3;
__int64 v4;
signed int j;
signed int i;
signed int v8;
char Dest[108];
char Str;
char v11;
for ( i = 0; i < 100; ++i )
{
if ( (unsigned int)i >= 0x64 )
j____report_rangecheckfailure();
Dest[i] = 0;
}
sub_41132F("please enter the flag:");
sub_411375("%20s", &Str);
v0 = j_strlen(&Str);
v1 = (const char *)sub_4110BE((int)&Str, v0, (int)&v11);
strncpy(Dest, v1, 0x28u);
v8 = j_strlen(Dest);
for ( j = 0; j < v8; ++j )
Dest[j] += j;
v2 = j_strlen(Dest);
if ( !strncmp(Dest, Str2, v2) )
sub_41132F("rigth flag!\n");
else
sub_41132F("wrong flag!\n");
HIDWORD(v4) = v3;
LODWORD(v4) = 0;
return v4;
}
因为这题是BUUCTF里比较靠前的题目,觉得应该没有什么难度的。所以就大致的看了下,觉得就是简单的字符串累加而已
for ( j = 0; j < v8; ++j )
Dest[j] += j;
所以认为,只要反着写就可以(其实并不是) Python3代码:
key = "e3nifIH9b_C@n@dH"
flag = ""
for k in range(0,len(key)):
x = ord(key[k]) - k
flag = flag + chr(x)
print(flag)
其中,里面的key值是题目里的字符串Str2的值 运行上面的代码后,看起来不像是有意义的字符串(所以认为不是真的flag) emmmmm然后到这里就卡住了。因为我虽然了解base64的基本原理,但是不知道具体的实现代码是什么样(或者说不知道怎么用代码写base64的加解密)。所以,这部分代码给我自己做的话,我可能看不出来这个是base64的加解密。只能用猜的。。。。。。
void *__cdecl sub_411AB0(char *a1, unsigned int a2, int *a3)
{
int v4;
int v5;
int v6;
int v7;
signed int i;
unsigned int v9;
int v10;
signed int v11;
void *Dst;
char *v13;
if ( !a1 || !a2 )
return 0;
v9 = a2 / 3;
if ( (signed int)(a2 / 3) % 3 )
++v9;
v10 = 4 * v9;
*a3 = v10;
Dst = malloc(v10 + 1);
if ( !Dst )
return 0;
j_memset(Dst, 0, v10 + 1);
v13 = a1;
v11 = a2;
v7 = 0;
while ( v11 > 0 )
{
byte_41A144[2] = 0;
byte_41A144[1] = 0;
byte_41A144[0] = 0;
for ( i = 0; i < 3 && v11 >= 1; ++i )
{
byte_41A144[i] = *v13;
--v11;
++v13;
}
if ( !i )
break;
switch ( i )
{
case 1:
*((_BYTE *)Dst + v7) = aAbcdefghijklmn[(signed int)(unsigned __int8)byte_41A144[0] >> 2];
v4 = v7 + 1;
*((_BYTE *)Dst + v4++) = aAbcdefghijklmn[((byte_41A144[1] & 0xF0) >> 4) | 16 * (byte_41A144[0] & 3)];
*((_BYTE *)Dst + v4++) = aAbcdefghijklmn[64];
*((_BYTE *)Dst + v4) = aAbcdefghijklmn[64];
v7 = v4 + 1;
break;
case 2:
*((_BYTE *)Dst + v7) = aAbcdefghijklmn[(signed int)(unsigned __int8)byte_41A144[0] >> 2];
v5 = v7 + 1;
*((_BYTE *)Dst + v5++) = aAbcdefghijklmn[((byte_41A144[1] & 0xF0) >> 4) | 16 * (byte_41A144[0] & 3)];
*((_BYTE *)Dst + v5++) = aAbcdefghijklmn[((byte_41A144[2] & 0xC0) >> 6) | 4 * (byte_41A144[1] & 0xF)];
*((_BYTE *)Dst + v5) = aAbcdefghijklmn[64];
v7 = v5 + 1;
break;
case 3:
*((_BYTE *)Dst + v7) = aAbcdefghijklmn[(signed int)(unsigned __int8)byte_41A144[0] >> 2];
v6 = v7 + 1;
*((_BYTE *)Dst + v6++) = aAbcdefghijklmn[((byte_41A144[1] & 0xF0) >> 4) | 16 * (byte_41A144[0] & 3)];
*((_BYTE *)Dst + v6++) = aAbcdefghijklmn[((byte_41A144[2] & 0xC0) >> 6) | 4 * (byte_41A144[1] & 0xF)];
*((_BYTE *)Dst + v6) = aAbcdefghijklmn[byte_41A144[2] & 0x3F];
v7 = v6 + 1;
break;
}
}
*((_BYTE *)Dst + v7) = 0;
return Dst;
}
最后,再把base64的解密加上去就可以得到有意义的字符串(flag):
from base64 import *
key = "e3nifIH9b_C@n@dH"
flag = ""
for k in range(0,len(key)):
x = ord(key[k]) - k
flag = flag + chr(x)
print(b64decode(flag))
|