Writeup · 31 Nights of Root

Nexus

reversinghardsolvedFlag: r00t{REDACTED}

Overview

Nexus ships three files: two stripped ELF PIE binaries (validator, check) and a data blob (nexus.bin). The challenge description spins an elaborate yarn about a “custom hash chain processor”, “nibble-decomposition block ordering”, SHA256-transformed init states, and decoy headers. Almost none of it is real.

The actual verification logic is a small XOR cipher embedded in .rodata of each binary. validator uses one set of tables and prints a string containing the literal word DECOY. check uses a different set and is the real scorer. nexus.bin is never opened by either binary.

Prerequisites / Setup

  • objdump, readelf, strings, Python 3
  • validator, check, nexus.bin in the working directory

Recon

Step 1 — Inspect file types

Goal: Confirm the binaries are stripped PIE ELFs and that nexus.bin is data.

file check validator nexus.bin
check:     ELF 64-bit LSB pie executable, x86-64, dynamically linked, stripped
validator: ELF 64-bit LSB pie executable, x86-64, dynamically linked, stripped
nexus.bin: data

Both ELFs are stripped — no symbol table — so main must be located via __libc_start_main or by reading _start.

Step 2 — String reconnaissance

Goal: Read the user-facing strings in each binary.

strings validator

Relevant hits:

VALID
Formula verified: %s
r00t{
Submit to ./check for official scoring.
INVALID - formula mismatch. Recheck your implementation.
INVALID - unrecognised format.
strings check
CORRECT
Flag: %s
WRONG

Already suspicious: validator literally tells you to run ./check, and the accepted formula it produces contains DECOY.

Step 3 — Inspect nexus.bin

Goal: Confirm the blob layout and check whether anything reads it.

stat -c '%s' nexus.bin   # 688
xxd -g1 -c16 nexus.bin
Offset Size Content
0x000 44 NEXS01234567NEXUS v1.0 hash chain processor\0
0x02c 64 scrambled state (looks like init)
0x06c 512 8 × 64-byte blocks
0x26c 40 ciphertext tail

Note: the description claims a 72-byte decoy header and a 64-byte scrambled state, but the null terminator of the ASCII header is at 0x02c (44 bytes). The “72” is either counting padding or is just part of the red herring.

Check whether anything reads nexus.bin:

strace -f -e trace=openat,read ./check < /dev/null 2>&1 | grep -i nexus
strace -f -e trace=openat,read ./validator < /dev/null 2>&1 | grep -i nexus

Both produce no output — neither binary opens nexus.bin. All data needed for verification is embedded in .rodata.

Exploitation

Step 4 — Locate main in the stripped binary

Goal: Find main to read the verification logic.

Because the binary is stripped, locate main from _start:

objdump -d -M intel validator | sed -n '/<\.text>:/,$p' | head -300

The entry point at 0x12f0 loads rdi = 0x10a0 before calling __libc_start_main. So main is at file offset 0x10a0.

Alternatively, in GDB:

b __libc_start_main
run < /tmp/in.txt
p/x $rdi        # main address (PIE base + 0x10a0)
b *$rdi
c

Step 5 — Read the main structure

Goal: Understand how the expected string is built and compared.

10a0: push rbp
10a1: pxor xmm0, xmm0
10a5: mov esi, 0xff
10ab: sub rsp, 0x208
...
1123: call fgets@plt             ; read input line
1128: test rax, rax
112b: je 12dd                     ; exit on EOF
...
1134: call strlen@plt             ; strip \n and \r
...
; --- build the expected string ---
1179: pxor xmm0, xmm0
117d: lea rdx, [rsp+0x101]        ; dst pointer
1185: lea r8,  [rsp+0x12a]        ; end pointer
118d: mov eax, 0x1                ; i = 1
119a: lea rdi, [rip+0xf1f]        ; tableA @ 0x20c0
11a1: lea rsi, [rip+0xf38]        ; tableB @ 0x20e0
11a8: mov BYTE PTR [rsp+0x100], 0x72   ; buf[0] = 'r'
...
1240: (loop body)
125d: lea rbp, [rsp+0x100]        ; ptr to built string
1265: mov rdi, rsp
1268: mov rsi, rbp
126b: call strcmp@plt             ; compare input to built string
1270: test eax, eax
1272: je 12b2                      ; match -> "Formula verified"

Step 6 — Read the XOR loop

Goal: Extract the exact decoding formula.

The loop at 0x1240:

1240: mov rcx, rax          ; rcx = i
1243: add rdx, 1            ; dst++
1247: and ecx, 3            ; i & 3
124a: movzx ecx, BYTE PTR [rdi+rcx]   ; tableA[i & 3]
124e: xor cl, BYTE PTR [rsi+rax]      ; ^ tableB[i]
1251: add rax, 1            ; i++
1255: mov BYTE PTR [rdx-1], cl        ; store
1258: cmp r8, rdx
125b: jne 1240

In C:

char buf[0x100];                 // zero-initialized
buf[0] = 'r';                    // 0x72

for (int i = 1; i < N; i++) {
    buf[i] = tableA[i & 3] ^ tableB[i];
}
buf[N] = '\0';

if (strcmp(input, buf) == 0) {
    puts("VALID");
    printf("Formula verified: %s\n", buf);
    puts("Submit to ./check for official scoring.");
} else if (strncmp(input, "r00t{", 5) == 0) {
    puts("INVALID - formula mismatch. Recheck your implementation.");
} else {
    puts("INVALID - unrecognised format.");
}

Where N = r8 - rdx_start + 1:

  • validator: r8 = rsp+0x12a, rdx_start = rsp+0x101 → N = 42
  • check: r8 = rsp+0x124, rdx_start = rsp+0x101 → N = 36 (i.e. loop runs 35 times, i = 1..35)

The format check on "r00t{" is only on the failure path in validator — it isn’t a precondition for the strcmp success.

Step 7 — Extract the tables

Goal: Dump .rodata from each binary.

objdump -s -j .rodata validator
objdump -s -j .rodata check

validator

2000 01000200 56414c49 4400466f 726d756c
2010 61207665 72696669 65643a20 25730a00
2020 72303074 7b000000 5375626d 69742074
...
20c0 dec0adbe 00000000 00000000 00000000
20e0 acf09dca a5ae9ec6 abb3f2fa 9b83e2e7
20f0 81f49d8f e6f7ce89 baf099df bdf89c88
2100 e6f299d8 eaa4958f b8bd
  • tableA @ 0x20c0 = de c0 ad be
  • tableB @ 0x20e0 = 42 bytes

check

2000 01000200 434f5252 4543540a 466c6167
2010 3a202573 0a005752 4f4e4700 00000000
2020 8c2b9759 00000000 00000000 00000000
2040 fe1ba72d f745a421 f958c838 b94da461
2050 bf48a36c bf48f26d e81cf63d be1af16e
2060 e81df324
  • tableA @ 0x2020 = 8c 2b 97 59
  • tableB @ 0x2040 = 35 bytes

Step 8 — First attempt: decode validator (the decoy)

Goal: Confirm validator is a decoy.

tableA = bytes.fromhex("dec0adbe")
tableB = bytes.fromhex(
    "acf09dcaa5ae9ec6abb3f2fa9b83e2e7"
    "81f49d8fe6f7ce89baf099dfbdf89c88"
    "e6f299d8eaa4958fb8bd"
)
out = bytearray(b'r')
for i in range(1, 42):
    out.append(tableA[i & 3] ^ tableB[i])
print(out.decode())
r00t{REDACTED}

Feed it to validator:

echo 'r00t{REDACTED}' | ./validator
VALID
Formula verified: r00t{REDACTED}
Submit to ./check for official scoring.

Feed it to check:

echo 'r00t{REDACTED}' | ./check
WRONG

Step 9 — Decode check (the real flag)

Goal: Decode check’s tables and confirm with check.

tableA = bytes.fromhex("8c2b9759")
tableB = bytes.fromhex(
    "fe1ba72df745a421f958c838b94da461"
    "bf48a36cbf48f26de81cf63dbe1af16e"
    "e81df324"
)

out = bytearray(b'r')
for i in range(1, 36):
    out.append(tableA[i & 3] ^ tableB[i])

print(out.decode())
r00t{REDACTED}

Verify:

echo 'r00t{REDACTED}' | ./check
CORRECT
Flag: r00t{REDACTED}

Flag

r00t{REDACTED}

check’s built string, confirmed with ./check → CORRECT.

Why the Story Doesn’t Matter

The challenge description is deliberately misleading on several points:

Claim in description Reality
“8 data blocks applied in nibble-determined order” No permutation is computed. No block ordering exists.
“72-byte decoy header declaring order 01234567” Header is 44 bytes; the 01234567 is just part of an ASCII string.
“64-byte scrambled state” Present in nexus.bin at 0x02c, never used.
“hash_chain_init field with SHA256-transformed init state” Not present in either binary or in nexus.bin.

Because check never reads nexus.bin and has no other code paths, the flag is exactly check’s built string.

Lessons / Takeaways

  • Trust the binary, not the narrative. When the challenge description and the binaries disagree, the binaries win.
  • Check file access early. strace on openat/read revealed neither binary touches nexus.bin, eliminating an entire branch of analysis.
  • Decoy artifacts are explicit. validator accepts a string containing DECOY and tells you to run ./check — the trap is advertised in plain text.
  • Stripped PIE binaries still leak logic. main is recoverable from _start, and .rodata tables are trivially dumped with objdump.

Techniques

  • Static Reverse Engineering
  • Decoy Analysis
  • XOR Obfuscation

References