"Stark Industries' JARVIS AI core is live and taking protocol, command, and token registrations over the network. Somewhere in its handling of your input, JARVIS trusts you more than it should." A live service behind a proof-of-work gate, five-step chain to an arbitrary read.
Hint
Two of the menu options write fixed-size buffers with no NUL terminator required. What does a format string that expects a terminated string do when it doesn't find one?
1/5Step 1: get past the PoW gate
sha256(token || suffix) must start with 21 zero bits. Plain brute
force over an incrementing suffix with hashlib solves it in a couple
of seconds - this gate is rate-limiting, not cryptographic.
2/5Step 2: leak the PIE base
"Register Protocol" stores a 16-byte name with no NUL byte required
and accepts a version field as 0x0101010101010101 - also NUL-free.
"Show Protocol" then prints the struct with printf("%s", ...). Because
neither the name nor the version contains a terminating zero, the format
string keeps reading straight past both fields into the next thing in
memory: a function pointer, FUN_00101da0, at a fixed offset from the
PIE base. One leaked pointer, one known offset, PIE base recovered.
3/5Step 3: leak a second secret the same way
"Issue Command" stores a random 8-byte "integrity" word right after a
24-byte command buffer, with any zero bytes in it replaced by '*' (so
it never accidentally terminates a string early). "Show Command" prints
with "%.32s" - which happily reads past the 24-byte command into that
integrity word, leaking it directly.
4/5Step 4: turn a negative length into an overflow
"Edit Command" asks for a payload length and only checks
length < 0x19 - never checks for negative. Supplying -1 makes
that comparison pass trivially, and the length flows straight into
read(0, cmd, (size_t)length). Cast to size_t, a negative length
becomes an enormous unsigned value, so read() happily accepts far more
attacker-controlled bytes than the 24-byte command buffer was ever sized
for.
5/5Step 5: overwrite the command and execute
Overflow in exactly the right shape: 16 bytes of filler, a hardcoded
magic constant (0x9c4e17b3a5d2680f) at offset 0x10, the leaked
integrity word at offset 0x18, and PIE_base + 0x1e3a (the real
"override" handler) at offset 0x20. "Execute Command" checks the
integrity word, finds it matches (because it's the value we leaked
earlier), and calls through the pointer we supplied instead of the
legitimate handler. That function compares the magic constant and, on
success, opens and prints /app/flag.txt.
1payload = (b'C' * 16
2 + struct.pack('<Q', MAGIC)
3 + struct.pack('<Q', integrity)
4 + struct.pack('<Q', override))
Pitfall
Two flag-shaped strings sit in the binary's own .rodata:
L3m0n{a7c31f0e5b92d4486ff1c07a3e5d9b21} and
L3m0n{5d0b8e14c7a36f92014bd8e3fa7c6520}. Neither is the flag - the
real value is only ever read live from /app/flag.txt by the override
handler, per-instance, and never appears as a static string anywhere in
the binary at all.
L3m0n{c02b64ce29fd9d5a3ddf69c847afa121}