Skip to content
Zone for Exploration and
Understanding of Security
← All writeups
Binary Exploitation Hard

Pizza Router

CyLab 2026 · Binary Exploitation · Hard

Vulnerability
Unbounded index → arbitrary heap write
Impact
Hijack a callback pointer to call win()
Tools
objdump, GDB, Python (pwntools-style)
Key move
Diff the binary — don't trust old offsets
FLAG  ✓ captured — flag redacted
Attack Chain
Reconobjdump, diff live binary
→
Live AnalysisGDB leaks offsets
→
Arbitrary Writeunbounded reroute index
→
Callback Hijackfinish pointer → win()
→
Impactdispatch triggers win()

Vulnerability Analysis

Root Cause: reroute takes a signed heap index with no bounds check, turning a route-cost update into an arbitrary 32-bit write anywhere relative to the route list.

  • CWE-129: Improper Validation of Array Index — heap_idx is never checked against the route list's real bounds
  • CWE-787: Out-of-bounds Write — The unvalidated index lets new_cost write past the intended structure, eventually onto a function-pointer slot

Severity: No CVSS score applies — this is a lab-built binary, not a scored vulnerability in a shipped product. The practical effect is full code execution via a hijacked callback.

References:
CWE-129 CWE-787

Summary

A drone-delivery “router” plans routes on a grid. It has a win() that prints flag.txt; the goal is to get it called. The reroute command has no bounds check on its index, giving an arbitrary 32-bit write relative to a heap route list. Two carefully placed writes overwrite an order's finish callback with the address of win(), then dispatch triggers it.

The first attempt failed because the live binary wasn't the build the old scripts targeted — its .text was shifted by +0x10. One sha256sum + nm caught it; every offset was re-derived against the real binary.

The write primitive

reroute <id> <heap_idx> <new_cost> writes two dwords at R + heap_idx*8 with no check on the signed index:

text
[+0] = order.y * G0 + order.x     (G0 = grid width = 16; bounded by map)
[+4] = new_cost                   (fully attacker-controlled 32-bit)

So new_cost is an arbitrary 32-bit write at any offset from the route list R. Each order owns a heap context with two callbacks; the finish pointer lives at CTXptr+0x430 (index 131 from R) and is called by dispatch.

Two-stage overwrite

win and fx_finish share their high 32 bits; win's low dword is fx_finish's + 0x200. The low dword a reroute writes is y*16+x — tiny unless we first enlarge x. Hence two writes:

  • Stage 1 — write win_lo-16 into ORD[0].x; the paired low write also bumps the order's id to 17.
  • Stage 2 — for order 17, write win_hi into the finish slot (index 131); the low half now computes to exactly win_lo.
  • Trigger — dispatch 17 → finish callback is now win() → flag.
How the offsets were recovered (GDB, live)
text
break at the dispatch call and the reroute write; print CTXptr, R, the callback
slots and G0 live, so the exploit is leak-driven and works under ASLR:

R = CTXptr+0x18   finish idx = 131   G[0] = 16   ORD = pie+0x5080
win = pie+0x2480  fx_draw_basic = pie+0x2270

Result

Verified locally first, then against the live instance:

text
[+] win_lo=0x1d5a480 win_hi=0x64b6 idx_ord0=-38775639 finish_idx=131
[!] FLAG: <flag redacted>

Takeaways

  • Diff the binary before trusting any writeup's offsets — a +0x10 shift was the entire first failure.
  • Let GDB hand you the layout instead of fully static-reversing every struct.
  • Leak-driven, not hardcoded — computing pie/heap from runtime leaks makes the exploit ASLR-proof and instance-independent.

References & Standards

Practice next

Explore more binary exploitation challenges on CyLab Security Academy.

Explore CyLab Security Academy ↗