Writing Proof-of-Concepts
Memory Safety & Exploitation Primitives · Security Fundamentals track
7 min read
In this module
The Art of the PoC
A proof-of-concept (PoC) is the bridge between discovering a vulnerability and communicating it to others - whether that is a vendor, a bug bounty program, or your own development team. A well-written PoC demonstrates that a bug is real, reproducible, and exploitable. A poorly written PoC wastes everyone's time and may result in a legitimate vulnerability being dismissed.
PoC Development Principles
A PoC demonstrates the vulnerability with minimal complexity and maximum clarity, and stops well short of a weaponised exploit. Three questions it must answer: What is the bug? How do you trigger it? What is the security impact?
Minimality is the governing principle. Strip away everything not needed to trigger the bug. A full ROP chain when a simple crash suffices is noise that makes triage harder, not easier. Start with the simplest possible trigger and only add complexity if the security impact can't be shown otherwise.
Reliability matters because an intermittently failing PoC is genuinely hard to triage. If the bug depends on timing or memory layout, document the conditions and give instructions for boosting reproducibility (e.g., "run with ASLR disabled for initial reproduction").
Documentation turns a script into a vulnerability report. Every PoC should have comments explaining what each step does and why it's there.
#!/usr/bin/env python3"""PoC for CVE-YYYY-XXXX: Stack buffer overflow in parse_header()Affected: libexample 1.2.3 through 1.4.0Impact: Crash (denial of service); control flow hijack with crafted input
Compile target: gcc -o vuln vuln.c -lexampleRun: python3 poc.py | ./vuln
The overflow occurs because parse_header() uses a fixed 128-bytebuffer for the header value but does not check the Content-Lengthfield before copying."""
import structimport sys
BUFFER_SIZE = 128SAVED_RBP_SIZE = 8
# Overflow the buffer and overwrite the saved return address# with 0x0000414141414141 to demonstrate control of RIP.# (A full 0x4141414141414141 is non-canonical: ret faults# before loading it, so RIP would still point at the ret.)payload = b"A" * BUFFER_SIZE # Fill the bufferpayload += b"B" * SAVED_RBP_SIZE # Overwrite saved RBPpayload += struct.pack("<Q", 0x0000414141414141) # Overwrite return address
# Construct valid header format to reach the vulnerable code pathheader = b"Content-Value: " + payload + b"\r\n"
sys.stdout.buffer.write(header)Trigger Reliability
A PoC must trigger the vulnerability consistently. This requires understanding the exact conditions under which the bug manifests.
Identify the root cause precisely. A crash in function X might be caused by corruption in function Y that executes much earlier. Trace backward from the crash to find the actual corruption point, and trigger that specific code path.
Control the environment. Document the exact versions of the target software, compiler, operating system, and libraries. Different compiler versions produce different stack layouts. Different libc versions use different heap allocators. A PoC that works on Ubuntu 22.04 with gcc 11 might not work on Fedora 38 with gcc 13.
Handle non-determinism. If the bug involves a race condition, provide a version that widens the race window (using techniques from the previous lesson). If the bug depends on heap layout, include heap grooming code and explain why those specific allocation patterns are necessary.
A crash demonstrates a bug exists. To demonstrate exploitability, you need to show that the attacker controls something meaningful: the instruction pointer (RIP/EIP), a function pointer, a security-critical variable, or the contents of a memory write. Showing RIP=0x0000414141414141 proves the attacker controls execution flow. (On x86-64 pick a canonical value like that one: returning to 0x4141414141414141 faults on the ret itself, so the crash shows RIP at the ret and the A's sitting at the top of the stack.) A NULL dereference crash at a fixed address usually does not.
Environment Assumptions
Every PoC makes assumptions about the target environment. Making these explicit is critical for reproducibility.
Compile-time assumptions: Which compiler and flags were used? Is the target compiled with optimisations (-O2)? Are debug symbols present? Is the target compiled as PIE (Position Independent Executable)?
Runtime assumptions: Is ASLR enabled? What is the kernel version? Is the target running as root or an unprivileged user? Are there resource limits (ulimits) that affect behaviour?
Configuration assumptions: What is the target's configuration? For a daemon, what config file settings affect the vulnerable code path? For a library, which API sequence triggers the bug?
# Environment setup for reproducing the PoC# Tested on: Ubuntu 22.04 LTS, kernel 5.15.0-91-generic# Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
# Compile the vulnerable target with protections disabled for clear demonstrationgcc -fno-stack-protector -no-pie -z execstack -o vuln vuln.c -lexample
# Optionally disable ASLR for deterministic reproduction# (a debugging aid, not a reliability fix: the real target has ASLR on)echo 0 | sudo tee /proc/sys/kernel/randomize_va_space
# Run the PoCpython3 poc.py | ./vuln# Expected: Segfault with RIP = 0x0000414141414141Minimizing a PoC
Start with whatever input or sequence triggers the crash, then systematically reduce it:
- Binary search reduction: Cut the input in half. Does it still crash? Keep the half that crashes. Repeat.
- Field isolation: In a structured input (like a file format or protocol), zero out fields one at a time. Which fields are necessary for the crash?
- Path minimisation: If the trigger requires multiple API calls, remove calls one at a time to find the minimal sequence.
- Delta debugging: Tools like
delta,creduceor its successorcviseautomate the minimisation process by systematically removing parts of the input while checking that the crash still occurs.
The result should be the smallest possible input or sequence that triggers the bug. For a file format parser, this might be a 50-byte file instead of a 50 MB one. For an API sequence, this might be three calls instead of thirty.
The runner below is a tiny delta debugger. Its "target" is a parser whose name field has a 16-byte buffer; rather than really overflowing, crashes() reports when an input would. The minimiser tries deleting chunks, keeps any deletion that still crashes, and halves the chunk size when nothing more can go. Predict the final input before you run it.
Responsible PoC Development
A PoC should demonstrate impact without being weaponisable. Remote code execution? Popping a calculator or writing a file is sufficient — a reverse shell payload is gratuitous. If the target is widely deployed, give the vendor time before publishing. Coordinated disclosure is what separates a researcher from a threat actor in the eyes of everyone reading your report later.
Document the timeline: when you found the bug, when you reported it, every vendor exchange. That record protects you as much as them.
The timeline below is a typical coordinated-disclosure schedule, built around Project Zero's 90-day deadline. Click through the stages and note which dates you'd want written down in your own record: the report, the vendor's acknowledgement and the patch release are the ones people argue about later.
Click a step to see details about the coordinated disclosure process
Before submitting a PoC, verify: (1) it triggers the bug on a clean, documented environment, (2) it includes clear comments explaining each step, (3) it demonstrates the security impact (not just a crash), (4) it is minimal - no unnecessary exploit stages, (5) it lists all environment assumptions, and (6) someone unfamiliar with the bug can reproduce it by following the documentation.