LESSON 46 · INTERMEDIATE8 min read

Linux and Windows Privilege Escalation, Pivoting, and Lateral Movement

Understand how attackers turn a low-privileged foothold into administrative access, practise enumeration and pivoting in an isolated lab, and design controls that limit lateral movement.

OWASP Top 10 · MITRE ATT&CK · NIST CSF 2.0Free to readModule 9 of 14
YOUR NEXT SMALL WINS

By the end, you’ll be able to…

  • Explain vertical and horizontal privilege escalation and the role of enumeration in an attack path.
  • Enumerate Linux hosts for sudo rules, SUID and SGID files, cron, capabilities, kernel level, and writable paths.
  • Enumerate Windows hosts for privileges, services, unquoted paths, tokens, and AlwaysInstallElevated.
  • Describe pivoting with SSH tunnels, proxychains, and chisel, and the concepts behind lateral movement.
  • Apply least privilege, segmentation, and detection to reduce the blast radius of a compromised host.

01From Foothold to Impact

Initial access is a beginning, not an ending. An attacker with a low-privileged shell wants more: administrative rights, credentials, access to other hosts, and persistence. Privilege escalation is the step from a limited identity to a more powerful one. Vertical escalation moves from a normal user to root or SYSTEM. Horizontal escalation moves from one normal user to another, often to reach mailboxes, file shares, or management interfaces. Both can be achieved through a missing patch, a misconfiguration, a credential left in a file, or a trust relationship that was never intended to be a path.

The work is mostly enumeration. Before you run an exploit, establish the operating system, patch level, users, groups, sudo or administrator rights, services, scheduled tasks, writable paths, network shares, and anything that looks like a secret. Compare what you find with what should be there. Automated tools such as LinPEAS and WinPEAS are useful because they collect many checks quickly, but they produce leads, not conclusions. Their output includes false positives, version-based guesses, and checks that do not apply to your host. Verify each candidate manually and record the evidence.

Privilege escalation is also where lab discipline matters most. A kernel exploit or a careless service change can crash a host or corrupt data. In a client environment, a failed escalation attempt can trigger an outage, an EDR alert, or a business interruption. Work from snapshots, use synthetic credentials, and keep a written scope. If you are in a real incident rather than an authorised test, preserve evidence and coordinate containment instead of experimenting. A low-privileged shell in a lab is a lesson; the same shell on an unowned system is a crime.

02Linux Enumeration and Common Weak Points

On Linux, start with identity and delegation. The id command shows your user, groups, and group IDs. sudo -l shows which commands you may run as root, including whether a password is required. Read the output carefully: a wildcard, an environment variable, an editor, or a file-management command may allow a shell escape even though the rule looks narrow. Check group membership with getent group and look for groups such as docker, lxd, disk, or sudo that can grant effective root. Inspect home directories, SSH keys, shell history, environment files, and backup scripts for credentials, but do not read unrelated personal data outside the engagement scope.

Next, look for privilege-bearing files and scheduled work. SUID and SGID binaries run with the permissions of their owner or group. Find them with find / -perm -4000 -type f and find / -perm -2000 -type f, then compare the list with the package manager. A binary that belongs to no package, or one with an unexpected shell escape, deserves investigation. Linux capabilities are similar: getcap -r / lists file capabilities, and a binary with cap_setuid or cap_dac_read_search may be as dangerous as a SUID root program. Cron jobs and systemd timers matter because root may execute a script that a normal user can edit. Check crontab -l, /etc/crontab, /etc/cron.d, /etc/cron.daily, and systemctl list-timers --all.

Kernel and service misconfigurations are the next layer. uname -a and the distribution release tell you the kernel and patch level; compare them with vendor advisories, but remember that a public exploit may be unstable or unnecessary. Writable directories, service configuration files, PATH entries, and library paths can create escalation paths without a kernel bug. The same is true of backups, log rotation scripts, and anything that runs as root and reads from a user-controlled location. LinPEAS automates much of this collection. Run it in a lab, save the output, and triage by confidence and impact rather than by the colour of the terminal.

linux-enumeration-lab.shShell
# Read-only enumeration in a lab VM.idsudo -lgetent group | grep -E 'sudo|docker|lxd|disk'# Privilege-bearing files.find / -perm -4000 -type f 2>/dev/nullfind / -perm -2000 -type f 2>/dev/nullgetcap -r / 2>/dev/null# Scheduled work that may run as root.crontab -l 2>/dev/nullcat /etc/crontabls -la /etc/cron.d /etc/cron.daily 2>/dev/nullsystemctl list-timers --all --no-pager# Kernel, patch level, and writable locations.uname -acat /etc/os-releasefind / -writable -type d 2>/dev/null | head -50# Automated collection: review the output, then verify manually../linpeas.sh -a | tee linpeas-output.txt
Outputstdout
uid=1001(student) gid=1001(student) groups=1001(student),27(sudo)
Matching Defaults entries for student on lab01:
    env_reset, mail_badpass, secure_path=/usr/local/sbin:...
User student may run the following commands on lab01:
    (ALL) NOPASSWD: /usr/bin/find
/usr/bin/passwd
/usr/bin/sudo
/usr/bin/python3 cap_setuid=ep

03Windows Enumeration and Privilege Concepts

Windows enumeration starts with the token you already hold. whoami /all shows your identity, groups, integrity level, and privileges. whoami /priv is especially important: privileges such as SeImpersonatePrivilege, SeAssignPrimaryTokenPrivilege, SeDebugPrivilege, SeBackupPrivilege, and SeTakeOwnershipPrivilege can be abused by an administrator-level attacker, and some service accounts hold them by default. Check local users and administrators with net user and net localgroup administrators, active sessions with query user, and stored credentials with cmdkey /list. PowerShell equivalents such as Get-LocalUser and Get-LocalGroupMember are easier to filter and export.

Services are a rich source of Windows escalation. An unquoted service path contains spaces and is not wrapped in quotes, so Windows may search a user-writable directory before the intended binary. A service binary or its directory may be writable by a normal user, or the service may run with excessive privileges. Query service configuration with Get-CimInstance Win32_Service and inspect paths, start names, and states. Check scheduled tasks, autoruns, and the AlwaysInstallElevated policy, which can let a normal user install a package with elevated rights. WinPEAS, PowerUp, and Seatbelt collect these checks, but verify each finding by hand and avoid running unknown binaries on a host you do not own.

Credential access is the bridge from local escalation to lateral movement. Attackers look for LSASS memory, SAM and SECURITY hives, cached domain credentials, DPAPI secrets, browser stores, Kerberos tickets, and plaintext passwords in scripts or configuration files. They may also abuse pass-the-hash, overpass-the-hash, Kerberoasting, or AS-REP roasting. This lesson describes the behaviours and the telemetry, not a recipe for stealing credentials. In a lab, use synthetic accounts and isolated hosts. In production, treat any suspicious access to LSASS, credential-dumping tooling, new service creation, or anomalous remote logons as a potential incident and preserve evidence before cleanup.

windows-enumeration-lab.ps1Plain text
# Read-only enumeration in a lab Windows VM.whoami /allwhoami /privwhoami /groupsnet usernet localgroup administratorsquery usercmdkey /listGet-LocalUserGet-LocalGroupMember -Group AdministratorsGet-CimInstance Win32_Service |  Select-Object Name, State, StartName, PathNameGet-ScheduledTask |  Where-Object State -ne Disabled |  Select-Object TaskName, TaskPath# Check both registry locations for AlwaysInstallElevated.reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevatedreg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated# Sysinternals accesschk can show weak service permissions.accesschk.exe -uwcqv "Everyone" *
Outputstdout
USER INFORMATION
User Name        SID
lab01\student    S-1-5-21-...
PRIVILEGES INFORMATION
SeChangeNotifyPrivilege       enabled
SeImpersonatePrivilege        enabled
SeShutdownPrivilege           disabled

SERVICE_NAME: LabUpdater
START_NAME : LocalSystem
BINARY_PATH_NAME : C:\Program Files\Lab Tools\update agent.exe

04Pivoting, Lateral Movement, and Containment

Pivoting uses a compromised host as a relay. If your attack host can reach a jump box but not the internal network behind it, you can forward a local port through SSH, create a SOCKS proxy, or run a tunnelling tool. The command ssh -L 127.0.0.1:8080:10.10.20.10:80 student@10.10.10.50 opens a local port that forwards to the internal web server. The command ssh -D 127.0.0.1:1080 creates a dynamic SOCKS proxy. The -J option chains a jump host for a single connection. proxychains can force supported tools through the SOCKS proxy, and chisel or ligolo-ng can create tunnels when SSH is not available. Each of these is a lab technique that requires explicit authorisation.

Lateral movement is the use of one compromised identity or host to reach another. Attackers reuse passwords and hashes, connect over SMB, RDP, WinRM, or SSH, create services and scheduled tasks, and use native administration tools because they blend in. The path often follows trust: a shared local administrator password, an overprivileged service account, a management network with weak segmentation, or a cloud token that grants access to many resources. Defenders reduce the path with least privilege, unique local administrator passwords, tiered administration, privileged access workstations, just-in-time access, MFA for administrative protocols, SMB signing, and network segmentation.

Detection needs a baseline of normal internal authentication. Alert on a normal user account authenticating to many hosts, new local administrator logons, service creation from unusual sources, remote process execution, SMB or RDP connections between workstations, and sudden east-west traffic. Tunnels can be encrypted and may look like ordinary administrative traffic, so combine network metadata with endpoint and identity logs. If lateral movement is confirmed, contain the hosts, revoke sessions and tickets, reset credentials, hunt for persistence, and rebuild rather than clean when trust is uncertain. Document the scope and preserve evidence before making destructive changes.

pivot-lab.shShell
# Lab only: reach an internal web app through a jump host.ssh -N -L 127.0.0.1:8080:10.10.20.10:80 student@10.10.10.50# Dynamic SOCKS proxy for tools that support it.ssh -N -D 127.0.0.1:1080 student@10.10.10.50proxychains4 -f /etc/proxychains4.conf curl -s http://10.10.20.10/# Jump host for a single SSH connection.ssh -J student@10.10.10.50 student@10.10.20.20# /etc/proxychains4.conf (lab): last line# socks5 127.0.0.1 1080# Chisel reverse tunnel concept, lab hosts only:# server: chisel server --reverse --port 9001# client: chisel client 10.10.10.50:9001 R:8080:10.10.20.10:80
Outputstdout
<!doctype html>
<title>Internal lab application</title>
<p>Reached through the jump host.</p>
LET IT CLICK

The ideas worth keeping.

  • Privilege escalation is an enumeration problem before it is an exploitation problem.
  • Linux and Windows each expose different privilege-bearing objects; verify tool output manually.
  • Pivoting and lateral movement follow trust relationships, so segmentation and least privilege limit the path.
  • Detection needs identity, endpoint, and network evidence, and containment must preserve evidence.
TURN UNDERSTANDING INTO SOMETHING YOU CAN DO

Make it yours.

Type and test your code right here in the interactive workspace. Run your solution, check the output, and compare with the worked guide when ready.

01

Exercise 1: Rank Linux escalation paths

You have a low-privileged shell on a lab Ubuntu host. sudo -l shows (ALL) NOPASSWD: /usr/bin/find. A root cron job runs /opt/backup/run.sh, which is group-writable by your user. getcap -r / shows /usr/bin/python3 with cap_setuid+ep. The kernel is fully patched. Rank the three findings by risk and describe a minimal, non-destructive verification for each. Do not exploit them.

Explore a worked solution
one_possible_solution.mdCybersecurity
The sudo rule is usually the highest-confidence path because it grants a direct, documented route to root, and find can execute commands. The writable root cron script is also high risk because root will run attacker-controlled content on a schedule, but timing and file ownership matter. The Python capability is high impact if the binary can be run by your user, because cap_setuid can change identity, but verify that the capability is effective and that the interpreter is not restricted. Verify by reading the exact sudo rule, running sudo -n /usr/bin/find --version to confirm the allowed binary, checking ls -l and group ownership on /opt/backup/run.sh, and confirming getcap output. Do not modify the script or execute an exploit. Report the paths, evidence, and fixes: remove the broad sudo rule, restrict the script to root, and drop the capability.

Rank by confidence and impact, then verify with read-only commands. A suspected path is not a confirmed finding until the permissions and execution context are understood.

02

Exercise 2: Design a two-hop pivot and its detection

You have a Kali VM on 10.10.10.0/24, a dual-homed jump host, and an internal web server on 10.10.20.10. Describe the lab topology, give an SSH local-forward and a SOCKS command, and list three log sources that would detect the tunnel.

Explore a worked solution
one_possible_solution.mdCybersecurity
Topology: Kali at 10.10.10.20, jump host at 10.10.10.50 with a second interface on 10.10.20.1, and the web server at 10.10.20.10. The internal network has no route from Kali except through the jump host. Local forward: ssh -N -L 127.0.0.1:8080:10.10.20.10:80 student@10.10.10.50. SOCKS: ssh -N -D 127.0.0.1:1080 student@10.10.10.50, then proxychains4 curl http://10.10.20.10/. Detection sources: sshd logs on the jump host showing a long-lived session and port forwarding; firewall or netflow records showing the jump host initiating connections to many internal hosts; proxy, DNS, and EDR telemetry showing unusual east-west traffic or a tool using the SOCKS proxy. Correlate the session identity, source, destination, and timing. Contain by terminating the session, isolating the jump host, and reviewing accounts and keys.

A pivot is a network path, so detection must combine session logs, network metadata, and endpoint behaviour. The lab must be isolated and authorised.

A SMALL QUESTION. A USEFUL NEXT STEP.

What stayed with you?

Check the ideas while they’re fresh. Your answers stay in this page and feedback appears as you go.

A LITTLE ACTIVE RECALL0 / 3 answered
01Which command shows the sudo rights of the current Linux user?
02Why is an unquoted Windows service path risky?
03What does ssh -D 127.0.0.1:1080 create?

Keep exploring.

The official references behind this lesson, when you want a second angle or the full details.

One lesson closer.

Reading is a start. Trying it yourself makes the connection.

Completion is saved in this browser. It records reading and hands-on practice progress.