Revenant-Securinets26
About Securinets 2026
Securinets is a Tunisian cybersecurity community, and every year they run a CTF that pulls in teams from all over. The reversing challenges in particular have a habit of being sneaky, and this year was no exception.
Flags look like Securinets{...}. This post covers Revenant, a reverse challenge that had me going down a GPU rabbit hole, fighting angr, and finally solving the thing with about 50 lines of gdb Python. It’s a good one if you like binaries that lie to you.
The challenge
You get a single binary called challenge plus a small data.bin. Run it and nothing obvious happens. Open it up and you find out why: challenge is only a loader. It decrypts a second ELF on the GPU using a Vulkan compute shader, writes it to a memfd and execs it from there. The actual flag check lives in that second ELF, so step zero is getting it out.
Stage 1: Grabbing the hidden ELF
My first idea was to hook the syscalls, but execve, openat, mmap and memfd_create are all raw syscall instructions inside the binary. They don’t go through the PLT, so LD_PRELOAD can’t touch them.
What does go through the PLT is memcpy and every vk* function. That’s enough. The decrypted ELF has to get copied into the memfd at some point, so I wrote a small preload library that wraps memcpy and dumps the buffer the moment it sees the \x7fELF magic:
void *memcpy(void *dest, const void *src, size_t n) {
if (!real_memcpy) real_memcpy = (memcpy_fn)dlsym(RTLD_NEXT, "memcpy");
void *ret = real_memcpy(dest, src, n);
if (!dumped && n >= 4 && memcmp(dest, "\x7f\x45\x4c\x46", 4) == 0) {
int out = open("stage2.elf", O_WRONLY | O_CREAT | O_TRUNC, 0755);
if (out >= 0) { write(out, dest, n); close(out); }
fprintf(stderr, "[capture] wrote %zu bytes to stage2.elf\n", n);
dumped = 1;
_exit(0);
}
return ret;
}
I also wrapped the Vulkan calls (vkCreateInstance, vkEnumeratePhysicalDevices, vkCreateDevice and friends) to print their return codes. If you don’t have a working GPU or ICD, the loader just calls exit(1), and this tells you exactly which step failed instead of leaving you guessing.
gcc -shared -fPIC -o capture_stage2.so capture_stage2.c -ldl
LD_PRELOAD=./capture_stage2.so ./challenge
Out pops stage2.elf. On to the fun part.
Stage 2: Finding the real checker
main (at 0x404050) reads up to 256 bytes, strips the newline and calls a function pointer stored at 0x4C2338. In the file, that pointer holds 0x404BD0. That would be too easy, though. A constructor at 0x403BC0 (sitting in .init_array) quietly swaps it to 0x403040 before main ever runs.
IDA had 0x403040 marked as data, so I had to undefine it and create a function there before Hex-Rays would decompile it. Once it did, the checker turned out to be:
- Return false unless the input is exactly 76 bytes.
- Map each byte through a 256-byte substitution table at
0x4C3E40. - Shuffle byte positions with
vpshufb/vperm2i128. - Rotate each byte left by an amount that depends on its position (
i % 7 + 1for most of them). - XOR with a Salsa-style keystream (10 double rounds, 64-byte blocks). The keystream only depends on constants, never on your input.
- Call
memcmp(buf, 0x4C3D20, 76)at0x4039fe. Anrdtsctimer wraps this call, so if you’re too slow (say, single-stepping in a debugger) you fail even with the correct flag.
The decoys
The author clearly had fun with this part. A wrong flag prints a fake [specter] session token: Securinets{...} built from an xorshift of your input, so you get something that looks like a flag every time. The binary is also full of long bait strings: fake Ghidra notes, a fake “community solver”, fake author notes. I read more of them than I’d like to admit. None of them lead anywhere.
Attempt 1: Throw angr at it
Every step of the checker is a known transform, so symbolic execution seemed like the obvious move. My first version used entry_state() and promptly ate all my RAM. The reason is that starting from the entry point makes angr symbolically step through all of glibc’s startup (TLS setup, malloc init, ifunc resolution, locale stuff) before main even gets going.
The second version was leaner. It ran only the constructor at 0x403BC0 with call_state, hooked out the anti-debug fopen, the timing check and the decoy string decoder, then jumped straight into 0x403040 with a symbolic buffer:
proj.hook(FOPEN_ADDR, ReturnZero())
proj.hook(TIMING_ADDR, ReturnZero())
proj.hook(DECOY_DECODER_ADDR, angr.SIM_PROCEDURES["stubs"]["ReturnUnconstrained"]())
ctor_state = proj.factory.call_state(CTOR_ADDR)
simgr = proj.factory.simulation_manager(ctor_state)
simgr.run()
Better, but it was still grinding away after 7 minutes. The AVX2 shuffles and the Salsa rounds are a lot of constraints for a solver to chew on. So I tried something less clever.
Attempt 2: Treat it as a black box
What finally cracked it was noticing that every step in the checker works on one byte at a time. The substitution is per byte, the rotation is per byte, the XOR is per byte, and the shuffle only moves bytes around without mixing them. So output byte p(i) depends only on input byte i.
That means you don’t need to understand the math at all. You only need two sets of probes:
- Value table: feed 76 copies of each byte value
vand record the buffer that reachesmemcmp. Now you know what every input byte turns into at every position. - Permutation: feed
"A"*76with one position changed toB, once for each position. Whichever output byte changes tells you where that input position ended up.
Then for each input position i, pick the v whose output at p(i) matches the target byte. That’s roughly 330 runs total.
Getting it to run under gdb
Before any of that works, three things stop the checker from running under a debugger:
0x403bd6: the constructor opens/proc/self/statusand looks forTracerPid. If it finds one, it writes into.rodataand segfaults. I skip the call and return 0.0x403c58:sub_404FD0is a timing check. Under gdb it fires and also writes into.rodata. Same fix.0x4C2330: this byte is 1 in the dumped ELF, somainprintsstill dead.and quits. The stage 1 loader execs the memfd bytes as is, so this byte has nothing to do with the check. I zero it atmain.
The breakpoint on the memcmp call grabs both pointers, rdi (our transformed buffer) and rsi (the target), so the script reads the target straight from memory too.
The solver
Run it from the challenge folder with gdb -q -batch -x solve_stage2_gdb.py:
# Stage 2 solver. Run: gdb -q -batch -x solve_stage2_gdb.py (from this folder, ~2s)
import gdb, os, tempfile
BIN = os.path.abspath("stage2.elf")
INP = os.path.join(tempfile.mkdtemp(), "in.txt")
gdb.execute("file " + BIN)
gdb.execute("set pagination off")
gdb.execute("set confirm off")
class Patch(gdb.Breakpoint):
def __init__(self, addr, cmds):
super().__init__("*%#x" % addr, internal=True)
self.cmds = cmds
def stop(self):
for c in self.cmds: gdb.execute(c)
return False
Patch(0x403bd6, ["set $rax=0", "set $pc=0x403bdb"]) # skip /proc/self/status TracerPid check
Patch(0x403c58, ["set $rax=0", "set $pc=0x403c5d"]) # skip rdtsc timing check
Patch(0x404050, ["set *(char*)0x4c2330=0"]) # clear "still dead." byte
gdb.Breakpoint("*0x4039fe", internal=True) # call memcmp(buf, target, 76)
def run(data):
open(INP, "wb").write(data + b"\n")
gdb.execute("run < %s > /dev/null" % INP, to_string=True)
f, inf = gdb.selected_frame(), gdb.selected_inferior()
out = bytes(inf.read_memory(int(f.read_register("rdi")), 76))
tgt = bytes(inf.read_memory(int(f.read_register("rsi")), 76))
gdb.execute("kill", to_string=True)
return out, tgt
# NUL/newline can't be fed via fgets+strlen; flag is printable anyway
table = {}
for v in range(1, 256):
if v != 10:
table[v], target = run(bytes([v]) * 76)
base, _ = run(b"A" * 76)
flag = bytearray()
for i in range(76):
x = bytearray(b"A" * 76); x[i] = ord("B")
o, _ = run(bytes(x))
(j,) = [k for k in range(76) if o[k] != base[k]]
(c,) = [v for v, out in table.items() if out[j] == target[j]]
flag.append(c)
print("\n[+] FLAG:", flag.decode())
A couple of small details worth pointing out. The Patch breakpoints return False from stop(), so gdb applies the fix and keeps running without ever pausing. And the program reads input with fgets + strlen, so NUL and \n can’t be fed in. That’s fine, the flag is printable anyway.
The whole thing finishes in about 2 seconds, compared to angr’s 7+ minutes of nothing:
[+] FLAG: Securinets{5db6ce3527dfeeafdf5da028ab9282f2bf2fe34400fa06da794cc50afaa43c0e}
Double checking
I don’t trust a flag until the real binary says yes. Zero the dead byte (file offset 0xc1330) and feed it in:
cp stage2.elf s2 && printf '\x00' | dd of=s2 bs=1 seek=$((0xc1330)) conv=notrunc
echo 'Securinets{5db6ce3527dfeeafdf5da028ab9282f2bf2fe34400fa06da794cc50afaa43c0e}' | ./s2
# [+] correct!
Flag
Securinets{5db6ce3527dfeeafdf5da028ab9282f2bf2fe34400fa06da794cc50afaa43c0e}
What I took away from this one
- When syscalls are inlined, look for the library calls around them.
memcpywas the weak spot here. - If every step of a checker is byte-wise and reversible, you can often skip understanding it and just probe it as a black box. It’s less elegant, but it worked in 2 seconds.
- angr is great, but heavy SIMD and crypto rounds can bog it down. If it’s still spinning after a few minutes, that’s a hint to try something dumber.
- Never trust anything that looks like a flag on the wrong-answer path.
Thanks to the Securinets team for a fun, mean little binary. See you next year!
