XCTF-攻防世界-新手训练-12-maze

Alikas-0x0B

题目:XCTF-攻防世界-新手训练-12-maze

File一下

maze: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/l, for GNU/Linux 2.6.32, BuildID[sha1]=eda1df76eec45447cd0e1ad208a7eff914e86758, stripped

拖进IDA里看,main()函数如下:

v9 = 0LL;
  puts("Input flag:");
  scanf("%s", &s1, 0LL);
  if ( strlen(&s1) != 24 || strncmp(&s1, "nctf{", 5uLL) || *(&byte_6010BF + 24) != 125 )
  {
LABEL_22:
    puts("Wrong flag!");
    exit(-1);
  }
  v3 = 5LL;
  if ( strlen(&s1) - 1 > 5 )
  {
    while ( 1 )
    {
      v4 = *(&s1 + v3);
      v5 = 0;
      if ( v4 > 78 )
      {
        v4 = (unsigned __int8)v4;
        if ( (unsigned __int8)v4 == 'O' )      
        {
          v6 = sub_400650((_DWORD *)&v9 + 1);
          goto LABEL_14;
        }
        if ( v4 == 'o' )
        {
          v6 = sub_400660((int *)&v9 + 1);
          goto LABEL_14;
        }
      }
      else
      {
        v4 = (unsigned __int8)v4;
        if ( (unsigned __int8)v4 == '.' )
        {
          v6 = sub_400670(&v9);
          goto LABEL_14;
        }
        if ( v4 == '0' )
        {
          v6 = sub_400680((int *)&v9);
LABEL_14:
          v5 = v6;
          goto LABEL_15;
        }
      }
LABEL_15:
      if ( !(unsigned __int8)sub_400690(asc_601060, HIDWORD(v9), (unsigned int)v9) )
        goto LABEL_22;
      if ( ++v3 >= strlen(&s1) - 1 )
      {
        if ( v5 )
          break;
LABEL_20:
        v7 = "Wrong flag!";
        goto LABEL_21;
      }
    }
  }
  if ( asc_601060[8 * (signed int)v9 + SHIDWORD(v9)] != 35 )
    goto LABEL_20;
  v7 = "Congratulations!";
LABEL_21:
  puts(v7);
  return 0LL;
}

根据题意“迷宫”,(以及之前实验吧做的分道扬镳)用字符转换可知,我们输入的应该是’.’,‘0’,‘o’,'O,并以此来确定上下左右移动。

进入判断后的各个函数如下:

bool __fastcall sub_400650(_DWORD *a1)//(_DWORD *)&v9 + 1
{
//为'O' 
  int v1; // eax
    
  v1 = (*a1)--;
  return v1 > 0;
}

bool __fastcall sub_400660(int *a1)//(int *)&v9 + 1
{
//为'o'
  int v1; // eax
    
  v1 = *a1 + 1;
  *a1 = v1;
  return v1 < 8;
}

bool __fastcall sub_400670(_DWORD *a1)//&v9
{
//为'.'
  int v1; // eax

  v1 = (*a1)--;
  return v1 > 0;
}

bool __fastcall sub_400680(int *a1)//(int *)&v9
{
//为'0'
  int v1; // eax
    
  v1 = *a1 + 1;
  *a1 = v1;
  return v1 < 8;
}

则由此可知,v9应该是个存放迷宫内坐标的二维数组。

'.’代表向上 '0’代表向下 'o’代表向右 'O’代表向左

每次执行后都判断是否越界 or 撞墙

分析后,就开始找迷宫的样子

结果发现在这

.data:0000000000601060 asc_601060      db '  *******   *  **** * ****  * ***  *#  *** *** ***     *********',0

猜测是个 8 * 8的迷宫,作图如下:

  ******
*   *  *
*** * **
**  * **
**  * **
*  *#  *
** *** *
**     *
********

则flag:nctf{o0oo00O000oooo…OO}

你可能感兴趣的:(逆向)