d4rk{s3cr3t_flll4ggg}c0de
Summary
vault is a stripped, non-PIE x86-64 C++ ELF (dynamically linked, .text at 0x402640) that
prompts Enter the flag: , reads one line, and requires the input to be exactly 25 bytes
(cmp [rsp+0xc8],0x19 @ 0x40bd80). The input is pushed through a 6-stage byte transform
and compared against a hard-coded 25-byte target; a horizontal OR-reduction of all byte
differences decides Correct! (0x40c570) vs Wrong. (0x40c190). Every stage is invertible,
so inverting the target through f6⁻¹…f1⁻¹ and XORing the 5-byte key again yields the flag.
Two decoys (a dead fake S-box and decoy strings in .text) are there to waste time.
Solution / Exploit
1. The check pipeline
in (25B) --[ xor K5[i%5] ]--> b1 --f1--> f2 --> f3 --> f4 --> f5 --> f6 --> transformed
compare: transformed[0..23] == C[0..23] && transformed[24]^0x62 == 0
- XOR key (5-byte, repeating,
i % 5) at0x4d8bb0=5a c3 17 9e 2b(the index is computed by the compiler's/5magic0xcccccccccccccccd). - f1
0x406300—rotl8(byte_i, (i%7)+1) - f2
0x406480— running cumulative sum mod 256 (b[i] += b[i-1]) - f3
0x406500— permutation:out[(3 + 10k + 7j) % 25] = in[5k + j] - f4
0x406a40— byte substitution (S-box)out = SBOX[in] - f5
0x406640— reverse rolling transformal = rol8(al,3) ^ b[i]; b[i] = al - f6
0x4067c0— keystream XOR,k0 = 0x54,k[i] = 5*k[i-1] + 0x11(mod 256) - Target C =
rodata[0x4d8a80..0x4d8a90](16B) ‖rodata[0x4d8bd8..0x4d8be0](8B) ‖0x62:
eb95045b560e2aae6a408360c9d52939 fe6deada9ea0e758 62
2. The real S-box is built at load time
f4 contains a block at 0x406ab9..0x406be6 that movaps-stores 256 bytes from rodata
(0x4d8980, which is just the identity table 00 01 02 … ff) into 0x50e7e0 and then
patches 6 entries. That block is dead: it is guarded by a one-shot flag at 0x50e7c0
which a global constructor has already set to 1, so execution jumps straight to the mapping
loop. Using the rodata identity table yields garbage. The real S-box is built at load time by a
constructor and is a bijection — so capture it live. vaultprotocol_dump_sbox.gdb does that:
set pagination off
set confirm off
file ./vault
python
import gdb
def rd(addr, n):
return gdb.selected_inferior().read_memory(addr, n).tobytes()
class BP(gdb.Breakpoint):
def stop(self):
t = rd(0x50e7e0, 256)
print("SBOX256 " + t.hex())
print("FLAGBYTE " + rd(0x50e7c0, 1).hex())
return False
BP("*0x406a80")
gdb.execute("run < /tmp/vp_in.txt")
print("DONE")
end
quit
3. Capture every intermediate stage (validation harness)
vaultprotocol_dump_transforms.gdb breaks after each stage for input = 25×A:
bps = [
("AFTER_XOR", 0x40bf4b, "rsp+0x80"),
("AFTER_F1", 0x40bfa6, "rsp+0x50"),
("AFTER_F2", 0x40bfe3, "rsp+0x50"),
("AFTER_F3", 0x40c014, "rsp+0x30"),
("AFTER_F4", 0x40c052, "rsp+0x50"),
("AFTER_F5", 0x40c08c, "rsp+0x50"),
("AFTER_F6", 0x40c0c4, "rsp+0x50"),
("AT_CMP", 0x40c0d0, "rsp+0xc0"),
]
Live capture (AFTER_F6 = the final transformed value):
AFTER_XOR 1b8256df6a1b8256df6a1b8256df6a1b8256df6a1b8256df6a # 'A' ^ K5
AFTER_F1 360ab2fd4dc641ac7f53b15095efd46c1465fb9a8d0559fea6
AFTER_F2 3640f2ef3c0243ef6ec172c257461a869afffa9421267f7d23
AFTER_F3 261aef36fac23c7f866e409457027d9ac1f221464323ff72ef
AFTER_F4 058cf47b13f7e2a40f9deab99134277a5cb32b5b612d58cdf4
AFTER_F5 9432d764e31e3dfbeb9c20591cb1b0f211a9430dca750b6af4
AFTER_F6 c0874d77935f6b44279172f274a83e2555cc494eaa84cd8548
4. Implement forward + inverse and invert C
vaultprotocol_solve.py reimplements all six stages (with the live-captured S-box) and their
inverses. The forward direction is asserted against the gdb capture for A×25 before the
inverse is trusted:
1K5 = rd(0x4d8bb0, 5) # 5ac3179e2b
2EXPECT = rd(0x4d8a80, 16) + rd(0x4d8bd8, 8) + bytes([0x62])
3
4# Real S-box, captured live from 0x50e7e0 at runtime (gdb).
5SBOX = bytes.fromhex(
6 "c5ae341d3d19a5e5e89fba54fa2616dd1b92784b4e8244385f078cd0bbe3b0ce"
7 "562b752dc13105e0bd42ec367cb51e47ab6c8e0d208d7b5066f1cffce2d385ef"
8 "eaa1a76124685bd7944fa93ec388b2d5d9dfcacb96fb6e912122998f4c4d9a"
9 "2e14c9a6fd0684f52c9b30b7576f109de78937cd121f73bc0cf3ebdb3b7927"
10 "72a453ac9cee485a0faa117663776d9028a89729093fb903150e01dc7af259"
11 "17401ca371b4da7d3a6a8abead93d833e10851697445d262c2c0b118f66781"
12 "ccaff84afe5cf70246b6835598a2045d43e900c8b87e70d6c68b65e43c6452"
13 "9ebfc7954987603923d4deff80a0e61a0a252a41f46b32b35e2f0bc47fedf0"
14 "1386f9d13558")
15assert len(SBOX) == 256 and len(set(SBOX)) == 256, "S-box not a bijection!"
16SINV = [0]*256
17for i, v in enumerate(SBOX): SINV[v] = i
18
19def invert(target):
20 b = target
21 for inv in (i6, i5, i4, i3, i2, i1): b = inv(b)
22 return bytes(b[i] ^ K5[i % 5] for i in range(25))
Run:
$ python3 vaultprotocol_solve.py
[+] forward() matches live gdb capture for 25*'A'
[+] EXPECT : eb95045b560e2aae6a408360c9d52939fe6deada9ea0e75862
[+] flag : d4rk{s3cr3t_flll4ggg}c0de
[+] roundtrip: True
[+] ascii : True
5. Confirm against the binary
$ printf 'd4rk{s3cr3t_flll4ggg}c0de\n' | ./vault
Enter the flag: Correct! # exit 0
$ printf 'd4rk{s3cr3t_flll4ggg}c0df\n' | ./vault
Enter the flag: Wrong. # exit 1
(The vault binary needs chmod +x; it was not executable in the bundle.)
Flag(s)
d4rk{s3cr3t_flll4ggg}c0de
Alternates
RESULT-vaultprotocol.md'sFLAG:header line and the deliverable README table both list the brace-delimitedd4rk{s3cr3t_flll4ggg}(without the trailingc0de). The source is authoritative and differs: the solver printsd4rk{s3cr3t_flll4ggg}c0de, the binary requires exactly 25 bytes (d4rk{+s3cr3t_flll4ggg+}+c0de= 25), andprintf 'd4rk{s3cr3t_flll4ggg}c0de\n' | ./vaultreturnsCorrect!while the 24-byte form does not.
Notes / Pitfalls
- Fake S-box code.
f4ships a dead block at0x406ab9that builds an identity-plus-6-patch table from rodata. It is guarded by a one-shot byte at0x50e7c0already set to1, so it never runs. Using the rodata identity table yields garbage; the real table lives at0x50e7e0. - Decoy strings in
.text.not_the_A,d4rk{,flag,H4CK-TH3-PL4N,AAAA-BBBB-…are immediate-move fragments of dead comparison strings, not the flag. --verbose/--dump-debugare useless. They only print[vault] init ok/[vault] debug dump unavailable in this build.- Validate forward before trusting the inverse. The live gdb capture for input 25×
Ais what proves the reimplemented pipeline is bit-exact; inverting an unvalidated model would have silently produced a wrong flag. - Non-PIE keeps addresses stable.
vaultis not PIE, so the hard-coded addresses in the gdb scripts work without rebasing.