Phantom Thread a self-decrypting section behind an unreachable gate

rev
flag RxR{s1l3nt_gr0ve_sp3ctr3_5420b0}

A 43 KB statically-linked, stripped x86-64 ELF. Banner, a whisper: prompt, one line of input, one of two outcomes. No symbols, but readelf -S immediately shows two suspicious executable sections:

output
[ 5] rxcode    PROGBITS  0x407020   AX
[ 6] rxguard   PROGBITS  0x4070b0   AX

rxcode disassembles to garbage - it isn't real code on disk. rxguard is a tidy little self-decrypting routine: hashes its own bytes, mixes the result into its argument, XORs 0x88 bytes starting at 0x407020 with an LCG keystream, then mprotects the page RWX then R-X. rxcode is the real checker, unpacked only at runtime.

The branch in main

Before reading input, main installs SIGSEGV/SIGILL/SIGBUS/ handlers (anti-tamper noise) and parses /proc/self/status for TracerPid:, turning the result into a marker that later perturbs rxguard's decryption seed under a debugger. Then the fork in the road:

asm
14011d4: cmp  eax, 0xede6c641
24011d9: je   0x401243          ; self-check "OK" -> path A: 0x4013d0
34011db: call rxguard           ; otherwise      -> path B: decrypted rxcode

Pitfall

The naive read is "the self-check passes, so 0x4013d0 is the real checker, and the blob at 0x4081a0 is the target." Hashing the shipped 16 bytes by hand gives 0x0bdfa5f4, not 0xede6c641 - the self-check never passes on the real binary. Path A is a decoy with its own decryptable flag, and it's unreachable.

Path B - the real check

Decrypting rxcode with seed = TracerPid_marker ^ FNV1a(rxguard) (0x33c020a7 for an untraced run):

rxcode (decrypted) asm
1407020: mov    r9, rdi                 ; r9 = input
2407023: movzx  edi, byte [0x40a030]    ; n = 0x20 (also = flag length)
3407031: xor    edi, esi                ; edi = n ^ len
4...
5407050: (loop over edx = 0..n-1)
6          b   = byte [0x40a028 + (i&7)]
7          c   = byte [0x40a031 + i]
8          w   = (0x4d5d6cb302b56f62 >> 8*(i&7)) & 0xff
9          eax = (b ^ input[i] ^ w) + (0x1f*i - c)     ; mod 256
10          edi |= eax
11407095: test edi, edi ; sete al        ; success == (edi stayed 0)

The initial edi = n ^ len forces the flag to be exactly 32 characters, and every accumulated term must independently be zero:

output
flag[i] = b[i&7] ^ w[i&7] ^ ((c[i] - 0x1f*i) & 0xff)
session
$echo 'RxR{s1l3nt_gr0ve_sp3ctr3_5420b0}' | ./phantom_thread
[+] The phantom pulls the thread back. That's your flag.

Note

Path A's dead-code cipher is invertible too, just for completeness: a two-word Feistel over the 0x9e3779b9 key schedule, run backwards on the target blob. It decodes to RxR{d00m_m00n_b0g_a47648} - never accepted by the binary, since path A can't be reached.

Flag

output
RxR{s1l3nt_gr0ve_sp3ctr3_5420b0}