Bone Machine ptrace-gated stack VM, two decrypted programs

rev
flag RxR{p4ss1ng_k1ll_m00n_283852}

"An old machine rattles in the ossuary." A 26 KB statically linked, stripped x86-64 ELF, non-PIE. One line of input, format RxR{...}.

session
$./bone_machine
== BONE MACHINE ==
feed it the right words: Denied.

Insight

strings shows almost none of the usual libc error table, which is the first sign that most of the interesting bytes are obfuscated rather than literal.

The anti-debug and the two encrypted programs

The prologue hashes 16 bytes at .data:0x407040 with and compares to 0xede6c641. On match, two globals - a length and a pointer, shipped as 0x17 / 0x4051f0 - get overwritten with 0x126 / 0x4050c0. So there are two byte programs in .rodata, and the hash picks which one the machine runs.

Right after that, before reading anything:

asm
14010dd: call   0x40183a          # -> syscall(101,0,0,0,0) == ptrace(PTRACE_TRACEME)
24010e2: cmp    rax, -1
34010e6: jne    0x4010f2
44010e8: xor    DWORD PTR [0x407024], 0xb0e000

If PTRACE_TRACEME fails - which it does under any tracer - a salt dword gets XORed. That salt feeds the stack-VM's opcode decryption, so a debugged run decrypts a different program. Static analysis only from here.

A stack VM, and its decryption key

The VM fetch function (0x401560) decrypts each opcode as mix(pc) ^ prog[pc], where mix mixes the untraced salt 0x5eed0b0e through a multiply-shift chain. With the salt known, both programs decode cleanly in Python into a small ISA (PUSH_LEN, PUSH_IMM, LOAD_IN, XOR, ADD/SUB/MUL/AND, NEQ, PUSH_R12/INC_R12/JLT_R12, ORACC, HALT). Success is "the accumulator is still zero at HALT."

The decoy branch

main points at the 294-byte program (0x4050c0, len 0x126) first. It decodes to 32 copies of input[i] == A ^ B, and inverting it gives immediately:

output
RxR{p4ss1ng_h4unt_sh4d0w_d0f690}

Pitfall

Correct prefix, correct brace, plausible leet phrase - I nearly stopped there. Two checks saved me. First, recomputing the FNV hash by hand over the shipped 16 bytes gives 0x2e947566, not 0xede6c641 - the gate's jne is always taken on the real binary, so this 294-byte program never loads; it's dead code. Second, running the string against the unmodified binary just prints Denied. A tidy decrypted program with a tidy output is not the same thing as a reachable one.

The real check

The program actually resident at boot (0x4051f0, 23 bytes) pins the length to 29 (byte[0x407050] == 0x1d) and runs an OR-accumulator loop:

output
acc |= ((input[r12] ^ ks(r12)) + 0x19*r12 - T51[r12]) & 0xff

with ks(i) = seed[8+(i&7)] ^ k64[(i&7)] for the 8-byte table at 0x407048 XORed against 0x2369302c2ea705a2, and T51 the 29 bytes at 0x407051. Every term depends on one byte alone, so it inverts in a single pass:

output
input[i] = ((T51[i] - 0x19*i) & 0xff) ^ ks(i & 7)
output
RxR{p4ss1ng_k1ll_m00n_283852}

Verification

session
$printf 'RxR{p4ss1ng_k1ll_m00n_283852}\n' | ./bone_machine
== BONE MACHINE ==
feed it the right words: The machine rattles and opens. That is your flag.
 
$printf 'RxR{p4ss1ng_h4unt_sh4d0w_d0f690}\n' | ./bone_machine     # dead-branch bait
feed it the right words: Denied.

Under strace, PTRACE_TRACEME returns -1 EPERM, the salt flips, and the correct flag stops working - solve it traced and you get a different, self-consistent string that only the traced build accepts.

Note

Two other reverse challenges in this event (Grave Digger, Puppeteer) ship the same skeleton: a 16-byte .data blob hashed FNV-1a style against 0xede6c641 to pick between a tidy decoy checker and the one that really runs, with ptrace/TracerPid flipping the answer under a debugger. In both, the gated branch is the trap, and the shipped bytes never actually match the constant - worth checking the gate by hand before inverting anything.

Flag

output
RxR{p4ss1ng_k1ll_m00n_283852}