BUUCTF—Re—reverse3

主函数代码:

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);//这里是base64加密,把v4加密,
  strncpy(Destination, v4, 0x28u);//然后把v4复制给Dest数组 
  v11 = j_strlen(Destination);
  for ( j = 0; j < v11; ++j )//Dest数组的每个字符加自身(ASCII码相加) 
    Destination[j] += j;
  v5 = j_strlen(Destination);
  if ( !strncmp(Destination, Str2, v5) )//如果Dest和Str2相等,那么flag就是对的 
    sub_41132F("rigth flag!\n", v8);
  else
    sub_41132F("wrong flag!\n", v8);
  return 0;
}

Str2可以追踪路径到:

 

注意:这里要加上0

大概意思就是,先把输入的字符串base64加密,然后再向前位移,最后和Str2比

这里有个例子,对于‘Destination[j] += j;’这个的解释,

代码:

#include<stdio.h>
#include<string.h>
int main()
{
    char z[10];
    gets(z);
    for(int i=0; i<strlen(z); i++)
    {
        z[i]+=i;
    }
    for(int j=0; j<strlen(z); j++)
    {
        printf("%c",z[j]);
    }
    return 0;
}

运行结果:

 

 

 可以看到输入的字符向后位移了数组下标位,那么脚本思路就是先把Str2减回去,再base64解密:

先是c语言版,因为没有base64解密函数,所以就只解到了base64加密这步,然后再base64解密就可以得到flag。

#include<stdio.h>
#include<string.h>
int main()
{
    char z[]={'e','3','n','i','f','I','H','9','b','_','C','@','n','@','d','H','0'};
    for(int i=0; i; i--)
    {
        z[i]-=i;
    }
    for(int j=0; j<strlen(z); j++)
    {
        printf("%c",z[j]);
    }
    return 0;
} 

Python就可以直接出:

import base64
list=['e','3','n','i','f','I','H','9','b','_','C','@','n','@','d','H','0']
for i in range(len(list)):
    list[i]=chr(ord(list[i])-i)
a=''.join(list)
print(base64.b64decode(a))

flag{i_l0ve_you}

 

posted @ 2022-01-06 12:12  Luccky  阅读(195)  评论(0编辑  收藏  举报