Introc

Reverse Engineering

Given an ELF file immediately decompile using ida and got this function:

main

int __fastcall main(int argc, const char **argv, const char **envp)
{
  __int64 i; // rax
  char v5[40]; // [rsp+0h] [rbp-38h] BYREF
  unsigned __int64 v6; // [rsp+28h] [rbp-10h]

  v6 = __readfsqword(0x28u);
  sub_4015C0();
  if ( qword_4034A8 < 0 )
    return 1;
  __printf_chk(2, &unk_4020A0);
  if ( fgets(v5, 28, stdin) )
  {
    for ( i = 0; i != 27; ++i )
    {
      if ( (*((_BYTE *)off_4034C8 + i) ^ (unsigned __int8)v5[i]) != *((_BYTE *)off_4034B0 + i) )
      {
        puts(aUhh);
        exit(-1);
      }
    }
    puts(s);
  }
  else
  {
    puts("Error reading input.");
  }
  return 0;
}

In short, what it does:

  • fgets(v5, 28, stdin), which means the length that the program checks is 27 byte

  • Loop if A[i] ^ v5[i] != B[i] => fail

  • Therefore the correct input is v5[i] = A[i] ^ B[i], with v5 is user input

Then in the pseudo code we can see that off_4034C8 points to array A, and off_4034B0 points to array B. So to extract the key, I used an LD=PRELOAD hook that overrides fgets, dereferences off_4034C8 and off_4034B0, computes A ^ B , writes it into the input buffer, and prints the 27-byte result.

Hook.c:

When we run it, we get the flag:

Flag: WRECKIT60{i'm_sooo_1ntr0vert_;(;(;(;(}

Last updated