BUUCTF reverse 3

qixunxunuxunxun發表於2024-05-27

一、32位ida載入,shift+f12檢索程式裡的字串,得到了有關flag的提示,而且看到了ABCDE……78這種字串,猜測存在base64位的加密
.rdata:00417B30 00000042 C ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=
猜測是由base64加密
二、F5得到虛擬碼

點選檢視程式碼
int __cdecl main_0(int argc, const char **argv, const char **envp)
{
  size_t v3; // eax
  const char *v4; // eax
  size_t v5; // eax
  char v7; // [esp+0h] [ebp-188h]
  char v8; // [esp+0h] [ebp-188h]
  signed int j; // [esp+DCh] [ebp-ACh]
  int i; // [esp+E8h] [ebp-A0h]
  signed int v11; // [esp+E8h] [ebp-A0h]
  char Destination[108]; // [esp+F4h] [ebp-94h] BYREF
  char Str[28]; // [esp+160h] [ebp-28h] BYREF
  char v14[8]; // [esp+17Ch] [ebp-Ch] BYREF

  for ( i = 0; i < 100; ++i )
  {
    if ( (unsigned int)i >= 0x64 )
      j____report_rangecheckfailure();
    Destination[i] = 0;
  }
  sub_41132F("please enter the flag:", v7);
  sub_411375("%20s", (char)Str);
  v3 = j_strlen(Str);
  v4 = (const char *)sub_4110BE(Str, v3, v14);
  strncpy(Destination, v4, 0x28u);
  v11 = j_strlen(Destination);
  for ( j = 0; j < v11; ++j )
    Destination[j] += j;
  v5 = j_strlen(Destination);
  if ( !strncmp(Destination, Str2, v5) ) //可以看出正確的flag是Str2
    sub_41132F("rigth flag!\n", v8);
  else
    sub_41132F("wrong flag!\n", v8);
  return 0;
}
flag加密後得到Str2,Str2為e3nifIH9b_C@n@dH

三、寫指令碼,得flag

點選檢視程式碼
import base64

str="e3nifIH9b_C@n@dH"
flag=""

for i in range(len(str)):
    flag+=chr(ord(str[i])-i)

print(base64.b64decode(flag))

flag為flag{i_l0ve_you}.