BUUCTF Reverse/SimpleRev

BUUCTF Reverse/SimpleRev

BUUCTF Reverse/SimpleRev

先查看下文件的信息

BUUCTF Reverse/SimpleRev

用IDA64位打开,分析代码

int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
  int v3; // eax
  char v4; // [rsp+Fh] [rbp-1h]

  while ( 1 )
  {
    while ( 1 )
    {
      printf("Welcome to CTF game!\nPlease input d/D to start or input q/Q to quit this program: ", argv, envp);
      v4 = getchar();
      if ( v4 != 'd' && v4 != 'D' )
        break;
      Decry();
    }
    if ( v4 == 'q' || v4 == 'Q' )
      Exit();
    puts("Input fault format!");
    v3 = getchar();
    putchar(v3);
  }
}

这是一个ELF文件,要在Linux环境下运行,不过还是可以分析

跟随跳转 Decry()

unsigned __int64 Decry()
{
  char v1; // [rsp+Fh] [rbp-51h]
  int v2; // [rsp+10h] [rbp-50h]
  int v3; // [rsp+14h] [rbp-4Ch]
  int i; // [rsp+18h] [rbp-48h]
  int v5; // [rsp+1Ch] [rbp-44h]
  char src[8]; // [rsp+20h] [rbp-40h]
  __int64 v7; // [rsp+28h] [rbp-38h]
  int v8; // [rsp+30h] [rbp-30h]
  __int64 v9; // [rsp+40h] [rbp-20h]
  __int64 v10; // [rsp+48h] [rbp-18h]
  int v11; // [rsp+50h] [rbp-10h]
  unsigned __int64 v12; // [rsp+58h] [rbp-8h]

  v12 = __readfsqword(0x28u);
  *(_QWORD *)src = 'SLCDN';
  v7 = 0LL;
  v8 = 0;
  v9 = 'wodah';
  v10 = 0LL;
  v11 = 0;
  text = (char *)join(key3, &v9);
  strcpy(key, key1);
  strcat(key, src);
  v2 = 0;
  v3 = 0;
  getchar();
  v5 = strlen(key);
  for ( i = 0; i < v5; ++i )
  {
    if ( key[v3 % v5] > 64 && key[v3 % v5] <= 90 )
      key[i] = key[v3 % v5] + ' ';
    ++v3;
  }
  printf("Please input your flag:", src);
  while ( 1 )
  {
    v1 = getchar();
    if ( v1 == 10 )
      break;
    if ( v1 == 32 )
    {
      ++v2;
    }
    else
    {
      if ( v1 <= 96 || v1 > 122 )
      {
        if ( v1 > 64 && v1 <= 90 )
          str2[v2] = (v1 - 39 - key[v3++ % v5] + 97) % 26 + 97;
      }
      else
      {
        str2[v2] = (v1 - 39 - key[v3++ % v5] + 97) % 26 + 97;
      }
      if ( !(v3 % v5) )
        putchar(' ');
      ++v2;
    }
  }
  if ( !strcmp(text, str2) )
    puts("Congratulation!\n");
  else
    puts("Try again!\n");
  return __readfsqword(0x28u) ^ v12;
}

分析代码可知,flag长度为10位,flag经过加密变换后要等于text

BUUCTF Reverse/SimpleRev
BUUCTF Reverse/SimpleRev

根据代码写出脚本

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main()
{
    char text[] = "killshadow";
    char key[] = "ADSFKNDCLS";
    char flag[11] = {0};
    int v3 = 0;
    int v5 = strlen(key);
    int i,j;
    int v2 = 0;
    for(i = 0 ; i < v5 ; i ++)
    {
        key[i] += 32;   //大写变小写
    }
    for(i = 0 ; i < strlen(text) ; i ++)
    {
        flag[i] = text[i] - 97 - 58 + key[v3 ++ % v5];
        while(flag[i] <= 64 )
        {
            flag[i] += 26;
        }
    }
    flag[10] = '\0';
    printf("flag{%s}",flag);
    return 0;

}

注意字符串在汇编代码里是小端序存储的,所以要倒过来

运行得到结果

BUUCTF Reverse/SimpleRev

上一篇:白话内存管理(一):从开国大典说起


下一篇:汇编看指针