Metasploit - Pivoting

pivoting in penetration testing can be done using Metasploit, where an attacker uses a compromised host (with a Meterpreter session) as a pivot point to access other systems within a private network.

Pivoting steps

Sequence Step Source Description/Context
1. Discover live hosts in the network. This is the first objective of pivoting. Once a system is initially compromised, an ARP scan (or similar scan) is performed to discover the list of live systems in the network reachable from the compromised host.
2. Set up routing rules. After identifying reachable IP addresses, routing rules must be set up. This involves using tools like Metasploit to route all traffic destined for the private network through the existing compromised system and Meterpreter session.
3. Scan ports of live systems. Once the necessary routing rules are implemented, port scanning is performed against the newly accessible live systems to identify active services.
4. Exploit vulnerable services. After the ports are scanned, the vulnerable services running on those open ports can be exploited to compromise further systems within the network.

Explanation of Setting Up Routing Rules in Metasploit:

When an attacker gains access to a machine inside the target network (via a Meterpreter session), that machine becomes a pivot point. The attacker needs to route network traffic through this compromised machine to access other systems on the internal network that are not directly accessible from the attacker’s machine. This technique is commonly called pivoting.

Steps Involved:

  1. Background the Meterpreter Session:
    • After compromising a system and getting a Meterpreter session, the first step is to background the session, which means pausing it so that you can issue commands for network routing.
background
  1. Add a Route:
    • You use the route add command in Metasploit to set up a routing rule. This tells Metasploit to send any traffic destined for a specific IP range (subnet) through the compromised machine (the system you have the Meterpreter session on).

    • The command structure is:

route add <target_ip_address> <subnet_mask> <session_number>

Example:

Suppose an attacker wants to route all traffic destined for the 10.10.10.0/24 network (the private network) through a Meterpreter session (session number 1). The command would be:

route add 10.10.10.0 255.255.255.0 1

Why Set Up Routing Rules?

Visualizing Pivoting and Routing:

Here’s a simple example:

Once the attacker sets up the route to the private network via the compromised host, any traffic destined for the 10.10.10.0/24 network from Metasploit will automatically be routed through 10.0.0.5.

Key Points to Remember:

Example Workflow:

  1. Compromise a system inside the target network (with Metasploit, for example).
  2. Background the Meterpreter session.
  3. Set up a routing rule to direct traffic to the internal network via the compromised system.
  4. Perform network actions (e.g., port scanning, vulnerability scanning) on other systems in the internal network.
  5. Exploit any vulnerable systems inside the private network.

Clean Up:

After completing the actions, it’s important to remove the routing rules to avoid detection:

route delete <target_ip_address> <subnet_mask>

Summary:

To set up routing rules in Metasploit for pivoting:

  1. Establish a Meterpreter session with a compromised host.
  2. Use route add <IP address> <subnet mask> <session number> to route traffic to the target private network.
  3. This allows you to scan ports and exploit services within the private network through the compromised system.
    This setup is critical for lateral movement and network reconnaissance in penetration testing.