Linux Privilege Escalation
Escalating from an unprivileged user to root is the goal after getting access to a Linux host. You rarely need a kernel exploit: the norm is abusing misconfigurations —SUID, sudo, cron, capabilities, loose permissions, reused credentials— that the admin left exploitable. This card is the overall map of local post-exploitation; each vector has its own card with the detail and commands.
flowchart TD
A[Low-privilege shell] --> B[Orderly enumeration]
B --> C{Vector found}
C -->|sudo -l| D[Sudo abuse / GTFOBins]
C -->|find -perm -4000| E[SUID/SGID]
C -->|getcap -r /| F[Capabilities]
C -->|pspy / cron| G[Cron and timers]
C -->|grep secrets| H[Reused credentials]
C -->|groups| I[docker / lxd / disk]
C -->|uname -a| J[Kernel exploit]
D & E & F & G & H & I & J --> K[root]
K --> L[Persistence]
Threat model
Section titled “Threat model”The system trusts permissions, paths, and privileges configured by the admin. The attacker doesn’t break Linux: they use its rules against it. A badly chosen SUID binary, an over-permissive sudo, or a cron task that runs a writable script are, in effect, root for whoever can spot them. Escalation is finding that link; enumeration almost always reveals it, and firing exploits blindly is noisy and unnecessary.
The objective sets the aggressiveness: in a scoped pentest you prioritize reliability and avoiding crashes; in a lab (OSCP, HTB) anything goes. Always work within the agreed scope.
Theory / Anatomy
Section titled “Theory / Anatomy”Almost every local escalation exploits one of these misplaced trusts:
- Trust in a binary’s owner — SUID/SGID runs with the owner’s permissions, not the caller’s.
- Trust in a delegation rule —
sudoersgrants running something as root that can be diverted to a shell. - Trust in a path or environment — relative PATH,
LD_PRELOAD, unsanitized wildcards (wildcard injection). - Trust in a granular power — a capability (
cap_setuid,cap_dac_read_search) equivalent to partial root. - Trust in a recurring process — cron/timer that runs a resource you control as root.
- Trust in group membership —
docker/lxdare root by design.
The kernel only comes into play when none of those trusts is broken: a memory bug in the kernel itself ignores permissions and configuration.
Red Team
Section titled “Red Team”Methodology (most reliable to last resort)
Section titled “Methodology (most reliable to last resort)”- Enumerate methodically (see Linux Enumeration);
linpeassummarizes every vector at a glance. sudo -land SUID/caps: the most reliable and quietest quick wins.- Cross-reference binaries with GTFOBins for the exact abuse recipe.
pspyto see root cron/processes without privileges.- Reused credentials toward root or another user.
- Dangerous groups (docker/lxd/disk).
- Kernel only if the rest bears no fruit: noisy and can crash the host.
The quick wins, in commands
Section titled “The quick wins, in commands”sudo -l # what can I run as root? (do this FIRST)find / -perm -4000 -type f 2>/dev/null # root SUID binariesgetcap -r / 2>/dev/null # binaries with capabilitiesid # docker/lxd/disk/adm group?cat /etc/crontab; ls -la /etc/cron.* # scheduled tasksuname -a # kernel version (last resort)Each finding is detailed in its own card: Sudo Abuse, SUID/SGID Binaries, Linux Capabilities, Cron Jobs and Timers, Credential Theft, Container and Docker Escapes, Kernel Exploits.
Other frequent vectors
Section titled “Other frequent vectors”# PATH hijacking: binary/cron calling a command without an absolute pathexport PATH=/tmp:$PATH; printf '#!/bin/sh\n/bin/bash -p\n' > /tmp/service; chmod +x /tmp/service# LD_PRELOAD via sudo with env_keepsudo LD_PRELOAD=/tmp/x.so <allowed_command># NFS no_root_squash: mount the export, create a SUID binary as remote root# writable /etc/passwd -> add a UID 0 user with a known hash# openssl emits only the HASH; build the full record and append it yourself:h=$(openssl passwd -1 -salt x pwn); echo "pwn:$h:0:0:root:/root:/bin/bash" >> /etc/passwd# then: su pwn (password: pwn) -> UID 0- linpeas.sh (PEASS-ng): automatic detection of all the above vectors, highlighted by likelihood.
- pspy: root processes/cron without privileges.
- GTFOBins: how to abuse a specific binary (sudo/SUID/caps).
- linux-exploit-suggester: kernel-exploit candidates by version.
Blue Team
Section titled “Blue Team”Detection
Section titled “Detection”- auditd on
execveof interpreters and shells spawned by EUID 0 processes that previously ran as a user,setuid/setresuidto 0, and writes to/etc/passwd,/etc/shadow,/etc/sudoers. - Enumerator execution:
linpeas,pspypatterns, bursts offind / -perm,getcap -r /. - Execution telemetry (auditd/eBPF, e.g. Falco) over file signatures: record what runs and with which arguments.
Hardening
Section titled “Hardening”- Least privilege in sudoers: no wildcards, no GTFOBins binaries,
NOPASSWDonly where essential,env_reset. - Review SUID/SGID and capabilities: remove unneeded ones; mount
nosuidwhere applicable. - Secure cron: absolute paths, scripts owned by root and non-writable.
- No credentials in text: managed secrets, 600 permissions.
- Patch the kernel and sudo/polkit promptly (see patch management); AppArmor/SELinux; no unnecessary dangerous groups.
Response
Section titled “Response”On signs of escalation: isolate the host, preserve artifacts (Linux DFIR), rotate credentials and keys, and if root was reached, assume persistence compromise and rebuild.
Checklist
Section titled “Checklist”-
sudo -l→ GTFOBins / NOPASSWD / sudo CVEs - SUID/SGID → GTFOBins (SUID/SGID Binaries)
- Dangerous capabilities (Linux Capabilities)
- Cron/timers with writable scripts or relative PATH (Cron Jobs and Timers)
- Reused credentials (Credential Theft)
- Dangerous groups (docker/lxd/disk) (Docker)
- PATH/LD_PRELOAD/NFS/wildcard and other vectors
- Vulnerable kernel (Kernel Exploits) as last resort
- Confirm root (
id) and document the chain