Post-exploitation and pivoting in Cybersecurity - Time & Space Complexity
Start learning this pattern below
Jump into concepts and practice - no test required
When attackers gain access to one system, they often try to move to others. This process is called pivoting.
We want to understand how the effort to move through multiple systems grows as the number of systems increases.
Analyze the time complexity of the following simplified pivoting process.
for each system in network:
if system is reachable:
exploit(system)
gather_credentials(system)
add system to compromised_list
for each new_system in network:
if new_system not in compromised_list:
try pivot(new_system)
This code tries to exploit reachable systems and then pivot to new systems repeatedly.
Identify the loops and repeated attempts to move between systems.
- Primary operation: Looping over all systems to exploit and pivot.
- How many times: For each system, it may attempt to pivot to many others, repeating nested loops.
As the number of systems (n) grows, the number of pivot attempts grows faster because each compromised system tries to reach others.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | About 100 attempts |
| 100 | About 10,000 attempts |
| 1000 | About 1,000,000 attempts |
Pattern observation: The effort grows roughly by the square of the number of systems.
Time Complexity: O(n²)
This means if you double the number of systems, the work to pivot between them roughly quadruples.
[X] Wrong: "Pivoting effort grows linearly with the number of systems."
[OK] Correct: Because each compromised system tries to reach many others, the attempts multiply, not just add up.
Understanding how pivoting scales helps you think like an attacker and defender. It shows why networks with many systems need strong segmentation.
"What if pivoting only tries new systems once per compromised system instead of repeatedly? How would the time complexity change?"
Practice
post-exploitation in cybersecurity?Solution
Step 1: Understand post-exploitation context
Post-exploitation refers to activities done after an attacker has gained access to a system.Step 2: Identify main goal
The main goal is to explore, gather information, and maintain control over the compromised system.Final Answer:
To perform actions after gaining access to a system -> Option CQuick Check:
Post-exploitation = actions after access [OK]
- Confusing post-exploitation with prevention
- Thinking it means installing security tools
- Mixing it with data encryption
Solution
Step 1: Identify pivoting command
Pivoting often uses SSH tunneling to forward ports from a compromised system to reach other targets.Step 2: Analyze options
ssh -L 8080:target:80 user@compromised uses SSH local port forwarding, which is a common pivot technique.Final Answer:
ssh -L 8080:target:80 user@compromised -> Option AQuick Check:
SSH tunneling = pivoting method [OK]
- Choosing ping or tracert which are just network tests
- Confusing netstat with pivoting
- Not recognizing SSH port forwarding syntax
Solution
Step 1: Understand SSH port forwarding types
Local forwarding (-L) forwards a local port to a remote host:port, enabling pivoting.Step 2: Match command to pivoting goal
ssh -L 3389:192.168.10.5:3389 user@compromised forwards local port 3389 to internal host 192.168.10.5 port 3389 via compromised machine, enabling access.Final Answer:
ssh -L 3389:192.168.10.5:3389 user@compromised -> Option BQuick Check:
Local port forwarding = pivoting access [OK]
- Confusing -L (local) with -R (remote) forwarding
- Using -D which is dynamic SOCKS proxy, not direct pivot
- Trying direct ssh to internal host without pivot
ssh -R 9000:10.0.0.5:80 user@compromised but cannot access the service on port 9000 locally. What is the most likely issue?Solution
Step 1: Understand difference between -L and -R
-L forwards local port to remote host; -R forwards remote port to local host.Step 2: Identify access goal
If you want to access the service locally on port 9000, you need local forwarding (-L), not remote (-R).Final Answer:
You need to use-Linstead of-Rfor local access -> Option AQuick Check:
Local access requires -L, not -R [OK]
- Mixing up -L and -R options
- Assuming remote forwarding exposes local ports
- Ignoring firewall or network reachability
Solution
Step 1: Recognize network restrictions
Direct access to Windows machine is blocked; only accessible via compromised Linux server inside network.Step 2: Use SSH local port forwarding
Set up SSH tunnel from your local machine forwarding a local port to Windows machine's RDP port through Linux server.Step 3: Connect via forwarded port
Use RDP client to connect to local forwarded port, effectively pivoting through Linux server.Final Answer:
Set up SSH local port forwarding from your machine to Windows RDP port via compromised Linux server -> Option DQuick Check:
Pivoting = SSH tunnel + local port forwarding [OK]
- Trying direct connection ignoring network restrictions
- Confusing port scanning with pivoting
- Installing unrelated software like antivirus
