Finding & modifying exploits¶
Most OSCP footholds are a known vulnerability in software you enumerated, with a public proof-of-concept you adapt. The skill isn't writing exploits — it's finding the right one and making it work on your target, which almost always means editing it. People fail here not because they can't find a PoC, but because they run it unmodified, it doesn't fire, and they assume the vuln is wrong instead of fixing the script.
The core loop¶
flowchart TD
A["exact version string (from enum)"] --> B["searchsploit + Google + GitHub"]
B --> C["READ the PoC fully"]
C --> D["adapt: IP/port, payload, paths, py2->py3, offsets"]
D --> E["compile if needed"]
E --> F["start listener, run it"]
F --> G{"shell?"}
G -->|yes| H["foothold"]
G -->|no| I["WHY not? version/arch/badchars/firewall -> fix one thing"]
I --> D
The two steps people skip are C (reading the PoC) and I (diagnosing why it failed instead of abandoning it).
Searching — cast a wide net¶
searchsploit apache 2.4.49
searchsploit -m 50383 # mirror a PoC into the current dir
searchsploit -x 50383 # read it first
searchsploit is offline exploit-db — fast but incomplete. Also Google "<product> <version>" exploit, check GitHub (often has better/updated PoCs than exploit-db), and read the CVE. Under exam conditions these are allowed; an AI chatbot is not.
Vetting a PoC before you run it (non-negotiable)¶
Read the whole script. Two reasons. First, exam-legitimacy: a public PoC is fine, but you must know it's not an auto-exploitation framework and not destructive. Second, self-preservation: some "PoCs" are backdoored (they exfiltrate to the author) or will crash/wipe the target. Look at: what command it runs, what's hardcoded (IPs, ports, URLs, offsets), the language and dependencies.
The edits you'll actually make¶
This is the part that matters. A downloaded PoC targets the author's box, not yours. Fix:
# 1) callback/target variables at the top — the #1 reason PoCs "don't work"
RHOST = "10.10.10.10" # the target
LHOST = "10.10.14.5" # YOUR box (check: ip a / the tun0 address)
LPORT = 443 # a port that beats egress filtering
- The embedded payload. Many PoCs carry a reverse-shell string or shellcode aimed at the author's listener. Swap in your
$LHOST:$LPORTand a shell that fits the target OS (a Linux bash one-liner won't run on Windows). See shells. - Python 2 → 3. Old PoCs are everywhere. Fix
print x→print(x),urllib2,raw_input→input, and bytes/str (.encode()before sending over a socket). Or just run it withpython2if it's installed. - URL paths / parameters. The PoC hits
/admin/upload.php; your enumeration showed/panel/upload.php. Align it to your target. - Offsets / bad characters (binary exploits). Rare on the current exam, but if present, respect the PoC's badchar list and offsets exactly.
Compiling¶
gcc exploit.c -o exploit # native Linux; add -m32 for a 32-bit target
x86_64-w64-mingw32-gcc exploit.c -o exploit.exe # Windows exe, cross-compiled from Kali
i686-w64-mingw32-gcc exploit.c -o exploit32.exe # 32-bit Windows
When it fails — diagnose, don't abandon¶
A failed exploit is data. Walk the list:
- Right version? Off-by-one on the version is the usual culprit — the PoC is for
2.4.49, the box is2.4.50(patched). Re-check your enumeration. - Right architecture? 32 vs 64-bit mismatch.
- Listener/port? Is your
ncactually listening on the$LPORTthe PoC uses? Try 443/80/445 — high or odd ports are often firewalled outbound and your shell never connects back. - Did the request even land? Add a
print/tcpdumpto confirm the exploit reached the target before assuming the vuln is absent. - Badchars mangling the payload (binary exploits).
Kernel/privesc exploits specifically: match the exact kernel+arch, and prefer a user-space misconfiguration first — a kernel exploit that's slightly off panics the box, and a dead target scores zero even though it was vulnerable.