Obfuscated Logic

Reverse Engineering

Given an ELF file, we can see from the challenge description that we have to do dynamic analysis. But before that, we do static analysis first to see the program's algorithm to encrypt/decrypt the flag.

check_password:

__int64 __fastcall check_password(const char *a1)
{
  unsigned __int8 v2; // [rsp+1Fh] [rbp-11h] BYREF
  int v3; // [rsp+20h] [rbp-10h] BYREF
  int i; // [rsp+24h] [rbp-Ch]
  unsigned __int64 v5; // [rsp+28h] [rbp-8h]

  v5 = __readfsqword(0x28u);
  if ( strlen(a1) != 40 )
    return 0;
  v3 = 0;
  for ( i = 0; i < 40; ++i )
  {
    v2 = a1[i];
    if ( !(unsigned __int8)transform_char(&v2, i) )
      return 0;
    junk_operations(&v3);
    if ( !validate_char(v2, i) )
      return 0;
  }
  return 1;
}

transform_char:

junk_operations:

validate_char:

from these functions we get the check flag algorithm:

then we proceed to analyze using gdb:

from here we found some interesting functions, check_password and validate_char. But we can't set breakpoint cause PIE is on. so we use start command to put a temporary breakpoint on main.

after we hit the breakpoint, now we can put breakpoints on check_password and validate_char

then we continue until we hit validate_char

after we stop on validate_char, we see the RIP-relative disassembly

here, we got the key address and the encoded_flag. Then we just dump the key and the encoded flag

solver.py:

if we run it, we get the flag:

Flag: RTRTNI25{Deobfuscation_Is_My_Superpower}

Last updated