Overview
We’re given a stripped PIE binary basilisk, along with two helper binaries (check, validator), a suspicious debug_stub.py, a decoy fake_dump.bin, and a memory_layout.txt that describes an XOR + SHA‑256 decryption scheme. Running ./basilisk with any input prints DENIED — we need the passphrase that unlocks the flag.
Prerequisites / Setup
objdump,radare2(r2),readelf, Python 3basiliskand the helper files in the working directoryunset ASAN_OPTIONS LSAN_OPTIONSbefore running the binary (sanitizer env vars trigger anti-debug)
Recon
Step 1 — Identify the binary
Goal: Confirm the file type and protections.
file basilisk
ELF 64-bit LSB pie executable, x86-64, dynamically linked, stripped
checksec shows PIE, NX, and no canary. strings reveals an anti-debug theme: /proc/self/status, TracerPid:, ASAN_OPTIONS, LSAN_OPTIONS, DENIED, BASILISK, K_STAGE2.
The provided memory_layout.txt claims a simple scheme:
stage1_key = XOR(stage1_key_enc, 0x41) # 16 bytes
expected = XOR(stage1_blob, stage1_key) # 32 bytes
stage2_key = SHA256(expected)[:16]
flag = XOR(stage2_blob, stage2_key) # 64 bytes
…but naively applying those offsets to fake_dump.bin produces garbage. fake_dump.bin also starts with \x7fELF and has an unknown machine type — it’s a red herring.
Exploitation
Step 2 — Locate the real data in .rodata
Goal: Find the true encrypted blobs and keys, ignoring the decoy fake_dump.bin and memory_layout.txt offsets.
Section headers show .rodata at VA 0x2000, size 0x200:
[15] .rodata PROGBITS 0x00002000 0x002000 0x000200
Dumping it with objdump -s -j .rodata basilisk (and confirming with px in radare2) reveals the real layout:
| VA | Contents |
|---|---|
0x2000 |
misc / anti-debug strings |
0x2018 |
TracerPid: |
0x202a |
ASAN_OPTIONS |
0x2037 |
LSAN_OPTIONS |
0x2060 |
64-byte encrypted blob (flag) |
0x20a0 |
32-byte encrypted blob (expected passphrase) |
0x20c0 |
256-byte table (SHA-256 K constants, obfuscated) |
0x21c0 |
16-byte XOR key |
0x21e0 |
SHA-256 init values, custom byte order |
The addresses referenced in main confirm this: lea rsi, [0x2060] is the flag blob, and the loop at 0x11e0 XORs a 32-byte buffer from 0x20a0 with the 16-byte key at 0x21c0.
Step 3 — Extract the passphrase
Goal: Replicate the XOR loop in main to recover the 32-byte passphrase compared against with memcmp.
data_expected = bytes.fromhex(
"2aea1146ad0ee52ffb70baff0f0dbfe7"
"f0914b8ef728ba1185f3a87f4df5cd24"
)
key1 = bytes.fromhex("b2e274ce2611a2134462e29d09482363")
expected = bytes(b ^ key1[i % 16] for i, b in enumerate(data_expected))
# 980865888b1f473cbf12586206459c8442733f40d1391802c1914ae244bdee47
Step 4 — Bypass the custom SHA-256
Goal: Avoid reimplementing the hand-written SHA-256 variant; feed the passphrase to the binary itself.
The disassembly of fcn.000015c0 shows a hand-written SHA-256 variant that:
- Builds its message as
expected[:8] + b"BASILISK_STAGE2"(movabs rax, 'BASILISK',movabs rdi, 'K_STAGE2'at0x1216/0x1220). - Uses little-endian word loads (unlike standard SHA-256), which is why a stock Python
hashlib.sha256produces the wrong key. - Uses SSE vector instructions in
main(0x1294–0x1427) to expand the 32-byte hash into a 64-byte keystream, then XORs it against the blob at0x2060.
Rather than reimplement all of that, the easiest path is to feed the recovered passphrase directly to the binary:
unset ASAN_OPTIONS LSAN_OPTIONS
printf '\x98\x08\x65\x88\x8b\x1f\x47\x3c\xbf\x12\x58\x62\x06\x45\x9c\x84\x42\x73\x3f\x40\xd1\x39\x18\x02\xc1\x91\x4a\xe2\x44\xbd\xee\x47' | ./basilisk
r00t{REDACTED}
Flag
r00t{REDACTED}
Lessons / Gotchas
- Provided “recovered” artifacts can be decoys.
fake_dump.binanddebug_stub.pyboth tried to nudge you toward a specific interpretation of offsets and key derivation that didn’t match the real binary. Always verify against the actual section data. - PIE + hardcoded addresses = pain.
debug_stub.pyset breakpoints at0x401c40and dumped0x402000, but PIE means the binary loads at a randomized base. Static extraction from.rodatasidesteps this entirely. - Custom SHA-256 variants love little-endian. Standard SHA-256 uses big-endian word loads; the binary at
0x15c0uses little-endian throughout. Reimplementing it from scratch is error-prone — feeding the input to the binary is faster and guaranteed correct. - Anti-debug can be sidestepped by not debugging. The
TracerPid/ASAN_OPTIONS/LSAN_OPTIONSchecks only fire under a debugger or with sanitizer env vars set. Running cleanly from a normal shell avoids all of them.
Techniques
References
- radare2: https://radare.org/r2/

