Skip to content
Adam Omar Saleh

Securinets CTF placeholder badge (unofficial)Securinets CTFReverse Engineering

revenant

challenge is a loader. It derives a key from the hostname, data.bin and its own ELF sections, then decrypts an 800 KB payload appended to itself using XTEA-CTR running in a Vulkan compute shader.

Competition
Securinets CTF placeholder badge (unofficial)Securinets CTF
Category
Reverse EngineeringHard · estimated
Source status
Source-documented · not platform-verified
Document
PDF edition5 min read

Brief

The challenge

Category
Reverse Engineering
Points
385
Author
blackkader
File
revenant.zip (challenge, data.bin)

The binary is dead on arrival. Or is it?

Challenge page
Challenge page

TL;DR

challenge is a loader. It derives a key from the hostname, data.bin and its own ELF sections, then decrypts an 800 KB payload appended to itself using XTEA-CTR running in a Vulkan compute shader. If the decrypted payload is an ELF, it gets executed from a memfd. The payload (stage 2) is hard-wired to print still dead.. Its real flag check is still in the binary, though: S-box, then reverse, then per-byte rotate, then Salsa20 XOR, then compare against a constant. Inverting that check gives the flag.

Text
hostname "blackkad" + hash(data.bin) + build-id  → SHA-256 → XTEA key/IVXTEA-CTR (GPU) over appended blob                → stage2 ELFstage2 check: sbox → reverse → rol(i%7+1) → ⊕ Salsa20 == target  → invert → flag

01

Recon

  • challenge: ELF64, dynamically linked against libc and libvulkan.so.1, built with clang 21 and LLD, and stripped.

  • The section headers end at 0x5ec8, but the file is 0xca898 bytes long. That leaves ~800 KB of high-entropy data appended after the ELF.

  • The last 8 bytes, 0x0c4990, give the length of that blob.

  • The only libc imports are getauxval, getrlimit/setrlimit, sigaltstack, memset and memcpy. All file I/O goes through raw syscall instructions.

  • strings finds Securinets{c3b7a291...59110} in a custom .note.securinets section. That's a decoy: stage 2 rejects it.

  • The binary also contains an embedded SPIR-V module with the names ParamsBuf, key, iv0, iv1, n_blocks, PtBuf and CtBuf.

When run, it prints nothing and exits.

02

Stage 1 – the loader

Every string is obfuscated as enc[i] ^ (0x1a + 0xb*i) ^ 0x37 (strs.py). Decoded, they are /proc/self/status, TracerPid:, /proc/self/exe, .stab, .note.gnu.build-id and data.bin.

Here's what main does:

  1. Anti-debug: reads TracerPid and remembers whether the process is being traced.

  2. Maps /proc/self/exe and looks up two sections:

    • .stab (8 bytes): 86;911;>

    • .note.gnu.build-id

  3. Calls uname() and compares nodename[0:8] with .stab ^ 0x5a = blackkad. On a mismatch it doesn't exit. It quietly flips bit 7 of every hostname byte, so the key comes out wrong. That's the "dead on arrival" part.

  4. Reads data.bin and hashes the first 256 bytes with a small stub that it decodes at runtime (byte ^ (i + 0x71)) and runs from an RWX page:

    Text
    h = 0; for b in data[:256]: h = ror64(h,1) ^ b; h += 0xbf58476d1ce4e5b9

    There's also a rdtsc timing check: if this step is slow, h ^= 0xbb…. Then h ^= build_id_desc[4:12].

  5. Computes digest = SHA-256(hostname[0:8] ‖ h ‖ data.bin[0xa0:0xb0]). The IV and K constants are the standard ones.

  6. Builds the GPU parameters: key = digest[0:16], iv0 = digest[16:20], iv1 = digest[20:24], n_blocks = len/8.

  7. Dispatches the compute shader over the appended blob, checks the result for \x7fELF, writes it to a memfd_create file and execves /proc/self/fd/N.

03

The compute shader

spvdis.py is a small SPIR-V disassembler. The shader turns out to be XTEA in CTR mode, with 32 rounds and delta 0x9e3779b9:

Text
v0 = iv0 + idx;  v1 = iv1XTEA-encrypt(v0, v1, key)pt[2*idx]   = ct[2*idx]   ^ v0pt[2*idx+1] = ct[2*idx+1] ^ v1

Every input to the key is in the handout, and the hostname comes straight from .stab, so the whole decryption can run offline on the CPU (solve.py). No GPU or hostname spoofing is needed:

Text
hostname b'blackkad' L 0xc4990 magic b'\x7fELF'

04

Stage 2 – "still dead."

stage2 is a static, stripped glibc binary. main (0x404050) works like this:

C
if (dead)                     // byte at 0x4c2330, initialised to 1, never cleared    { puts("still dead."); return 1; }fgets(buf, 0x100, stdin);  strip '\n';if (check(buf, len)) puts("[+] correct!");else { printf("[specter] session token: Securinets{%s}\n", random_hex); puts("[-] wrong!"); }

Nothing ever writes to dead, so the binary always dies. Wrong guesses also print a random fake flag. A constructor in .init_array (0x403bc0) runs another TracerPid check plus a second anti-debug check, fills the global tables, and sets check = 0x403040.

check (0x403040) requires len == 76, then:

  1. b[i] = SBOX[in[i]], with the S-box copied from 0x48dec0.

  2. Reverses the 76 bytes. This is done with AVX2 vperm2i128 and vpshufb.

  3. b[i] = rol8(b[i], (i % 7) + 1).

  4. b ^= Salsa20(key = 0x48dfc0, nonce = 0) keystream. The key schedule rotates each byte left by 3 and then by 5, which cancels out.

  5. memcmp(b, target, 76), where target = 0x48dfe0[0:64] ‖ 0xfeaecc3589a1a323 ‖ 0x02ab8200. An rdtsc timing check is folded into the return value.

Every stage is a bijection, so the check can be inverted. To avoid having to reproduce the AVX2 Salsa20 exactly, I pulled the keystream straight from the real binary:

  • patch_dump.py clears dead and redirects the memcmp call into a 23-byte code cave that write(2, buf, 76)s the final buffer.

  • Running it on two different 76-byte inputs and XORing out rol(reverse(sbox(input))) gave the same keystream both times. That confirms the S-box, reverse and rotate stages are correct.

  • solve3.py then works backwards: target ⊕ ks → ror → reverse → inverse S-box.

Text
Securinets{5db6ce3527dfeeafdf5da028ab9282f2bf2fe34400fa06da794cc50afaa43c0e}

05

Verification

verify.sh patches only the dead byte and pipes candidates into the original check:

Text
--- real flag:flag: [+] correct!​--- decoy from stage 1 note:[specter] session token: Securinets{05611bc920441862ea070bef7e32c609ff5a02e80f377553a98a3547ab100eaa}flag: [-] wrong!

Files

FilePurpose
strs.pyDecodes stage-1 strings and the runtime hash stub
spvdis.pyMinimal SPIR-V disassembler, dumps shader.spv
solve.pyDerives the SHA-256 key and decrypts the blob with XTEA-CTR, writing stage2
xref.pyFinds string cross-references in stage 2
solve2.pyExtracts the stage-2 tables and models the check
patch_dump.py, run_dump.shBuild and run stage2_dump to capture the real keystream
solve3.pyInverts the check, writing flag_candidate.txt
verify.shRuns the original check with only the dead byte cleared

Flag

Flag

Securinets{5db6ce3527dfeeafdf5da028ab9282f2bf2fe34400fa06da794cc50afaa43c0e}

Source-documented · not platform-verified

Takeaways

  • Flags sitting in plain sight (.note.securinets, the [specter] token) are decoys.

  • "Dead" binaries often fail on purpose, through a hard-coded kill flag or an environment-bound key that corrupts things silently. Look for what the code would do if it lived.

  • If every key input ships with the challenge, replicate the crypto offline instead of satisfying the environment (here: the hostname, a Vulkan GPU, no debugger, and timing checks).

  • When a cipher is buried in hand-vectorised AVX2, patching the binary to dump its internal buffer and solving for the keystream is quicker than emulating it exactly.

PDF edition

Writeup PDF

Formatted edition of this walkthrough, built from my source notes · 6 pages.