Hello, CTF

0x01

拿到题目后查壳,发现什么也没有,32位vc++

0x02

放到IDA里,F5反编译,得到下图

很容易我们就看到了比较的函数,以及出现wrong和success的字符串,所以接下来就是仔细分析一下这段代码

char v4; // al
  int result; // eax
  int v6; // [esp+0h] [ebp-70h]
  int v7; // [esp+0h] [ebp-70h]
  char v8; // [esp+12h] [ebp-5Eh]
  char v9[20]; // [esp+14h] [ebp-5Ch]
  char v10; // [esp+28h] [ebp-48h]
  __int16 v11; // [esp+48h] [ebp-28h]
  char v12; // [esp+4Ah] [ebp-26h]
  char v13; // [esp+4Ch] [ebp-24h]

  strcpy(&v13, "437261636b4d654a757374466f7246756e");
  while ( 1 )
  {
    memset(&v10, 0, 0x20u);
    v11 = 0;
    v12 = 0;
    sub_40134B((int)aPleaseInputYou, v6);
    scanf(aS, v9);
    if ( strlen(v9) > 0x11 )
      break;
    v3 = 0;
    do
    {
      v4 = v9[v3];
      if ( !v4 )
        break;
      sprintf(&v8, asc_408044, v4);
      strcat(&v10, &v8);
      ++v3;
    }
    while ( v3 < 17 );
    if ( !strcmp(&v10, &v13) )
      sub_40134B((int)aSuccess, v7);
    else
      sub_40134B((int)aWrong, v7);
  }
  sub_40134B((int)aWrong, v7);
  result = stru_408090._cnt-- - 1;
  if ( stru_408090._cnt < 0 )
    return _filbuf(&stru_408090);
  ++stru_408090._ptr;
  return result;
}

0x03

一、

 strcpy(&v13, "437261636b4d654a757374466f7246756e");

这段代码的意思就是赋值,将这段字符串赋值给v13

二、

 while ( v3 < 17 );
    if ( !strcmp(&v10, &v13) )
      sub_40134B((int)aSuccess, v7);
    else
      sub_40134B((int)aWrong, v7);
  }

这段代码的意思就是比较字符串,如果一样就success,否则wrong,所以现在我们已经知道了关键字符串是437261636b4d654a757374466f7246756e,但是显然这不是字符串,所以我们首先得明白,函数对我们输入的东西做了什么

三、

if ( strlen(v9) > 0x11 )
      break;
    v3 = 0;
    do
    {
      v4 = v9[v3];
      if ( !v4 )
        break;
      sprintf(&v8, asc_408044, v4);
      strcat(&v10, &v8);
      ++v3;
    }

这段代码就是讲我们输入的东西转换为十六进制,然后才与v13进行比较,所以现在我们知道了要得到flag就得把v13由十六进制转换为字符串

v4代表我们输入的每一个字符

asc_408044代表%x

四、

转换字符串的,得到flag

posted @ 2020-05-31 09:10  怪味巧克力  阅读(167)  评论(0编辑  收藏  举报