제리의 블로그

picoCTF 2018 quackme Reversing 본문

CTF

picoCTF 2018 quackme Reversing

j3rrry 2018. 9. 30. 12:43

program


void *read_input()
{
  void *result; // eax@2
  int v1; // edx@4
  void *v2; // [sp+0h] [bp-18h]@1
  char v3; // [sp+4h] [bp-14h]@1
  int v4; // [sp+8h] [bp-10h]@1
  int v5; // [sp+Ch] [bp-Ch]@1

  v5 = *MK_FP(__GS__, 20);
  v2 = 0;
  v4 = getline(&v2, &v3, stdin);
  if ( v4 == -1 )
  {
    puts("No line read...");
    result = &unk_8048882;
  }
  else
  {
    result = v2;
  }
  v1 = *MK_FP(__GS__, 20) ^ v5;
  return result;
}

int do_magic()
{
  int result; // eax@8
  int v1; // [sp+Ch] [bp-1Ch]@4
  int i; // [sp+10h] [bp-18h]@4
  char *s; // [sp+14h] [bp-14h]@1
  signed __int32 v4; // [sp+18h] [bp-10h]@1
  void *v5; // [sp+1Ch] [bp-Ch]@1

  s = (char *)read_input();
  v4 = strlen(s);
  v5 = malloc(v4 + 1);
  if ( !v5 )
  {
    puts("malloc() returned NULL. Out of Memory\n");
    exit(-1);
  }
  memset(v5, 0, v4 + 1);
  v1 = 0;
  for ( i = 0; ; ++i )
  {
    result = i;
    if ( i >= v4 )
      break;
    if ( greetingMessage[i] == (*(_BYTE *)(i + 0x8048858) ^ (unsigned __int8)s[i]) )
      ++v1;
    if ( v1 == 25 )
      return puts("You are winner!");
  }
  return result;
}

int __cdecl main(int argc, const char **argv, const char **envp)
{
  setvbuf(stdout, 0, 2, 0);
  puts("You have now entered the Duck Web, and you're in for a honkin' good time.\nCan you figure out my trick?");
  do_magic();
  puts("That's all folks.");
  return 0;
}
위는 main을 디컴파일한 모습입니다.

50번째 줄을 보면
XOR 연산을 하고 있다는 것을 알 수 있고

52번째 줄은 길이가 25라는 것을 알 수 있습니다.

flag = ''
for i in range(25):
    flag += chr(get_byte(i + 0x8048858) ^ get_byte(i + 0x80487F0))
print(flag)

위의 코드를 돌리면 키값이 나온다.


picoCTF{qu4ckm3_7ed36e4b}

'CTF' 카테고리의 다른 글

picoCTF 2018 A Simple Question Web Exploitation  (0) 2018.10.12
Comments