Overview
| |
Connecting prints a banner.
| |
A 1950s-retrofuture domestic robot programmed with punch cards, and that concept dictates the implementation directly.
| concept | implementation |
|---|---|
| one card = one command | fixed-format frames, not interactive text |
| service key card | opcode 1 auth, hardcoded key |
| the card inside the machine | a struct of data + capacity + state |
| cards can tear | CRC-8 integrity check |
| teletype era | ANSI escapes as frame delimiters |
Typing help does nothing. It takes no text commands, so whole frames have to be pushed in.
1. The protocol
The frame
The receive function FUN_001014cc gives the format.
| |
Opened by ESC [ and closed by ESC \, with payload[0] as the opcode.
The layout of the receive buffer at DAT_00104860 matters later.
| |
The length limit falls out of the parser’s check.
| |
len + 7 <= 0x800, so len goes up to 0x7f9.
CRC-8
Polynomial 0x2f, zero init, no reflection.
| |
The parser compares the received CRC against its own and rejects a mismatch with 0xe3. All of this is ordinary transport machinery so far, unrelated to the attack.
Status codes
The first response byte is a status. It says exactly which part of the reverse engineering is still wrong, so tabulating it early pays off.
| |
2. The auth gate
Only opcode 1 gets through unauthenticated.
| |
local_124 is the auth flag. It is a stack local in the main loop, not a field of the card struct, which turns out to be useful later.
The handler requires a length of exactly 5.
| |
It assembles payload[1..4] big-endian and compares against 0x1337c35f. The key is baked into the binary, so there is nothing to bypass.
| |
The gate does two jobs, though.
It certifies the reverse engineering. Getting through means the frame, the length and the CRC are all correct, so the protocol work is done.
It arms the vulnerability. capacity starts at zero and auth raises it to 0x100. Before authenticating, no write clears the guard.
Those two lines are also the tell that local_118 is a struct rather than an array. Writing at +0x100 and +0x102 of a 256-byte array means more fields follow.
3. The struct
| |
Ghidra names it local_118 [256], but the real address is rbp-0x110, because a local_X sits at (rbp+8) - X.
| |
Taking the number in the variable name as an offset puts everything off by eight.
state is a counter that increments on every write.
| |
It has nothing to do with authentication; that lives in local_124, as above.
4. The off-by-one
The card write handler, FUN_0010174c.
| |
param_3 is the frame length and n = len - 1. The guard is capacity < n and the loop is i <= n. So it writes len bytes while checking len - 1.
Sending len = 0x101 gives n = 0x100.
| |
data[0x100] is past the array. It is the low byte of capacity.
Where the extra byte comes from
The source is payload[1 + 0x100] = payload[0x101], but the payload is 0x101 bytes, indexed up to 0x100. The receive buffer layout says what sits one slot further.
| |
The overflowing byte is the frame’s CRC.
5. The CRC as a write primitive
The CRC is determined by the payload, and the payload is mine. So the CRC can be steered to any value.
| |
Most of the 0x100 bytes are meaningless filler. Pick one position as a free variable and try all 256 values; CRC-8’s output space is 256 wide, so a solution usually exists.
| |
Only the low byte of capacity changes, so 0x0100 becomes 0x01ff. 0x100 itself can’t be reproduced, but retaddr sits at 0x118, so that is plenty.
This is the turning point. A value that exists for integrity checking becomes a one-byte write the attacker chooses.
6. The leak
The read handler emits capacity bytes.
| |
Taking 0x1ff bytes gets all three at once.
| |
retaddr is the instruction after the call to FUN_00101865.
| |
| |
Those two asserts validate the offset guesses immediately. A PIE base is page-aligned, and a glibc canary’s low byte is zero.
7. Overwriting the return address
Everything up to 0x118 has to be rewritten, and that span holds things worth preserving.
| |
Leaving out capacity means something like ljust(0x108, b'B') writes 0x4242 there, and that trips the response function’s length guard.
| |
0x4242 + 8 exceeds 0x801, so write never runs at all and the client sits waiting for a response. The symptom is silence rather than a crash, which makes this a particularly awkward mistake to track down.
leave pops saved_rbp, so the leaked value goes back there too.
This write has its own off-by-one
The same bug fires again. data is 0x140 long, so one CRC byte lands at card+0x140. The chain runs from 0x118 to 0x137, so it is clear of it. The trailing b'C' * 8 widens that margin; without it the byte lands at 0x138, still past the chain.
8. The /bin/sh address
pop rdi needs the address of the string.
The first attempt computed it from the stack, deriving the card address from the leaked saved_rbp.
| |
saved_rbp belongs to the caller’s frame, so reaching the current one means tracking the effect of push rbp / sub rsp / call. Getting it wrong shows up like this.
| |
system ran; only the argument was wrong.
The response function makes the whole calculation unnecessary.
| |
The read command copies the card into BSS. A BSS address is the PIE base plus a fixed offset, and the base is already known.
The response overwrites that string
The final opcode 4 calls FUN_001013a2(0, 0, 0). Even with no data, it still writes a CRC and a terminator.
| |
Which is exactly bytes 0 through 2 of the copied card. So the string moves eight bytes into the card, and the leading b'B' * 8 absorbs those three.
| |
0x406d is clear of the range the response touches.
9. Why system is there at all
The chain calls system@plt directly. That works without a libc leak because the program itself uses system.
| |
This is the opcode 5 handler. All it does is print an empty string, and its only real effect is putting system in the import table.
With Full RELRO the GOT is populated at load time, so opcode 5 never even has to be sent — and the exploit doesn’t send it. That opcode exists in order to exist, not in order to be used.
10. The final chain
| |
The ret at 0x101a is there for 16-byte stack alignment.
Opcode 4 is the trigger.
| |
LAB_00101a69 is where the canary is checked and the function returns normally.
| |
There is one more ordering requirement. After writing the chain, opcode 3 has to be sent once. Not to read anything, but to trigger the BSS copy that puts /bin/sh at 0x406d.
| |
Notes
- The guard and the loop disagree by one character.
capacity < nandi <= neach look fine alone; only together do they show thatlenbytes get written against a check onlen - 1. - The source of the overflowing byte is what has to be chased down. Knowing one byte overflows isn’t usable on its own; it becomes a write primitive only once that byte turns out to be the CRC, which is attacker-controlled.
- A length field like
capacityis consulted by both the read and the write path. Growing it once opens the leak and the overwrite together. - A length-guard violation shows up as no response rather than a crash.
0x4242 + 8 > 0x801merely skips thewrite, leaving the process healthy. When it hangs, check for a clobbered struct field first. - An unused opcode creates the import. Whether
systemis in the binary comes down toFUN_001012d2alone, and that is what keeps the chain at four slots. - checksec shows SHSTK and IBT enabled, but neither was enforced at runtime. Declaring them as ELF properties has no effect by itself.
Full scripts: ctf-writeups/2026-sunshine/homemaker