🎯Meterpreter Tunneling

Overview

When we have Meterpreter shell access on a pivot host, we can perform enumeration and pivoting without relying on SSH port forwarding. Meterpreter provides built-in tunneling capabilities that can be leveraged for network pivoting, including SOCKS proxies, routing, and port forwarding.

Based on HTB Academy Page 5: Meterpreter Tunneling & Port Forwarding


Scenario Description

Network Topology

[Attack Host] ←→ [Ubuntu Pivot] ←→ [Windows Target]
10.10.14.x         10.129.202.64      172.16.5.19
                   (Meterpreter)       (Internal Only)

The Approach

  • Meterpreter session on Ubuntu pivot host

  • Built-in pivoting without SSH dependencies

  • SOCKS proxy for traffic routing

  • AutoRoute for network routing

  • Port forwarding through Meterpreter


1. Creating Meterpreter Payload for Pivot Host

Generate Linux Meterpreter Payload

Configure Metasploit Handler

Execute Payload on Pivot

Establish Meterpreter Session


2. Network Discovery Through Meterpreter

Ping Sweep with Meterpreter Module

Alternative Ping Sweep Methods

Linux Pivot Host (Bash):

Windows Pivot Host (CMD):

Windows Pivot Host (PowerShell):

Note: Ping sweeps may require multiple attempts to build ARP cache for successful replies.


3. SOCKS Proxy Configuration

Configure Metasploit SOCKS Proxy

Verify SOCKS Proxy Status

Configure Proxychains

Note: May need to change socks4 to socks5 depending on SOCKS server version.


4. AutoRoute for Traffic Routing

Configure AutoRoute Module

Alternative: AutoRoute from Meterpreter Session

List Active Routes


5. Testing Proxy & Routing

Network Scanning Through Proxy


6. Meterpreter Port Forwarding

Local Port Forwarding with portfwd

Create Local TCP Relay

Connect Through Port Forward

Verify Connection with Netstat


7. Meterpreter Reverse Port Forwarding

Configure Reverse Port Forward

Configuration Explanation:

  • -R: Reverse port forwarding

  • -l 8081: Local port on attack host

  • -p 1234: Port on Ubuntu pivot

  • -L 10.10.14.18: Attack host IP

Setup Handler for Windows Payload

Generate Windows Payload

Execute Payload and Receive Shell


8. Traffic Flow Analysis

Local Port Forwarding Flow

Reverse Port Forwarding Flow

SOCKS Proxy Flow


9. Meterpreter vs SSH Tunneling Comparison

Aspect

Meterpreter Tunneling

SSH Tunneling

Prerequisites

Meterpreter session

SSH access

Setup Complexity

Integrated in Metasploit

Requires SSH commands

SOCKS Proxy

Built-in auxiliary module

External tools needed

Port Forwarding

portfwd module

ssh -L/-R commands

Routing

AutoRoute module

Manual route setup

Session Management

Metasploit framework

Terminal sessions

Stealth

More detectable

Blends with SSH traffic


10. Troubleshooting Common Issues

AutoRoute Compatibility Warnings

SOCKS Proxy Connection Issues

Port Forward Verification


11. HTB Academy Official Walkthrough

Complete Step-by-Step Lab Solution

Question 1: Network Discovery

"What two IP addresses can be discovered when attempting a ping sweep from the Ubuntu pivot host? (Format: x.x.x.x,x.x.x.x)"

Official Answer: 172.16.5.19,172.16.5.129

Step 1: Create Linux Meterpreter Payload

Step 2: Configure Metasploit Handler

Step 3: Transfer Payload to Pivot

Step 4: Execute Payload on Pivot

Step 5: Perform Ping Sweep

Question 2: AutoRoute Configuration

"Which of the routes that AutoRoute adds allows 172.16.5.19 to be reachable from the attack host? (Format:x.x.x.x/x.x.x.x)"

Official Answer: 172.16.5.0/255.255.254.0

Step 1-4: Same as Question 1 (Create payload, handler, transfer, execute)

Step 5: Configure SOCKS Proxy

Step 6: Configure Proxychains

Step 7: Setup AutoRoute

Route Analysis: The AutoRoute adds 172.16.5.0/255.255.254.0 which encompasses the target 172.16.5.19

Lab Success Criteria

βœ… Payload created and transferred successfully βœ… Meterpreter session established on pivot βœ… Ping sweep reveals two active IPs: 172.16.5.19, 172.16.5.129 βœ… SOCKS proxy configured on port 9050 βœ… AutoRoute adds route 172.16.5.0/255.255.254.0 βœ… Network pivoting enabled through Meterpreter session


12. Best Practices

Session Management

  1. Background sessions properly with bg command

  2. Monitor active sessions with sessions -l

  3. Clean up port forwards when finished

  4. Document active routes for complex networks

Network Discovery

  1. Use multiple discovery methods (ping, TCP scan)

  2. Attempt discovery twice to build ARP cache

  3. Document discovered hosts for later reference

  4. Test connectivity before setting up tunnels

Security Considerations

  1. Minimize payload size for stealth

  2. Use HTTPS payloads when possible

  3. Clean up artifacts after assessment

  4. Monitor for detection during operations


13. Command Reference

Essential Meterpreter Commands

Metasploit Auxiliary Modules


References

Last updated