Skip to content
Tutorials Center
My learning

Topics

Lesson 22 of 37 ยท Meterpreter and Post-exploitation

Pivoting and Routing Concepts

Understand pivoting, routes and port forwards in Metasploit as network concepts, and see how segmentation and egress filtering stop lateral movement.

Real networks are divided into zones. A web server in a DMZ cannot usually reach the database zone, and a laptop cannot talk to the payroll servers. Pivoting means using one compromised, authorized host as a stepping stone to reach networks the tester cannot reach directly. It is how an assessment shows whether segmentation really works.

This lesson explains the ideas and the commands in a read-only way, then models the logic in Python, so you can think like both the tester and the person writing firewall rules.

Pivoting extends your reach into other systems. Your scope document must list every network you may touch, or the pivot stops at the first host.

The picture

flowchart LR
    T["Tester"] --> D["DMZ web host (in scope)"]
    D -->|"allowed by firewall"| A["App zone"]
    D -.->|"blocked"| DB["Database zone"]
    A --> DB

The tester reaches the DMZ host, and the zone behind it only through allowed paths.

The tester cannot see the app or database zones directly. Through a session on the DMZ host, traffic can be relayed inward, but only as far as the firewalls between the zones allow it.

Routes inside Metasploit

Metasploit can send the traffic of its own modules through an existing session. The route command adds a rule: "to reach this subnet, use session N."

TEXT
msf6 > route add 198.51.100.0 255.255.255.0 1
[*] Route added
msf6 > route print
IPv4 Active Routing Table
   Subnet           Netmask          Gateway
   198.51.100.0     255.255.255.0    Session 1

After this, scanners and modules aimed at that subnet are tunnelled through session 1 automatically. Nothing outside the framework (such as your browser) uses the route.

Port forwarding

portfwd in Meterpreter opens a local port on the tester's machine that is relayed to a service on a host the session can reach:

TEXT
meterpreter > portfwd add -l 8080 -p 80 -r 198.51.100.15
[*] Forward TCP relay created: (local) :8080 -> (remote) 198.51.100.15:80

Now an authorized test tool pointed at 127.0.0.1:8080 talks to the web server in the inner zone. A SOCKS proxy module offers the same idea for tools that speak SOCKS, handy for scripts and browsers.

Technique What it relays Used for
route Framework module traffic Scanning inner subnets
portfwd One fixed port Reaching a single service
SOCKS proxy Any proxy-aware tool Wide testing through one session

A reachability model

The whole idea is a graph: nodes are zones, edges are allowed flows. A pivot is a path through the graph. The stand-in below computes which zones are reachable from a foothold, given a firewall rule list. It is exactly the check a defender should run on paper before an assessment.

Python Which zones can a foothold reach?

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The output shows an internet attacker can chain dmz -> app -> db. A better rule set makes the app zone accept only specific ports from the DMZ, or none at all.

Python Test a tighter rule set

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Defences against pivoting

  • Segmentation: default-deny between zones; allow only named ports and hosts.
  • Egress filtering: servers rarely need to start outbound connections, so block them.
  • Host firewalls: even inside a zone, restrict who can talk to whom.
  • Monitoring: alert when a server suddenly connects to many internal addresses or runs scanner-like traffic.
  • Credential hygiene: unique local admin passwords stop one compromise spreading everywhere.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is pivoting?

    Pivoting relays traffic through a host that can reach networks the tester cannot.
  2. 2. What does route add 198.51.100.0 255.255.255.0 1 do?

    It adds a routing rule so Metasploit modules aimed at the subnet use session 1 as the gateway.
  3. 3. Which control best limits lateral movement between zones?

    Default-deny rules between zones allow only the flows that are needed.
  4. 4. Why is egress filtering useful?

    Blocking unneeded outbound traffic breaks reverse shells and relays.

Summary

  • Pivoting uses an in-scope host to reach otherwise unreachable networks.
  • route, portfwd and SOCKS proxies are the main relay tools.
  • Reachability is a graph problem: model flows and check paths.
  • Segmentation, egress filtering and monitoring defeat most pivots.

Next: Privilege Escalation Concepts and Hardening