Initial access usually lands you as a low-privileged user: a web server account, a service account, or a phished employee. Privilege escalation is the step from there to root. On real engagements it shows the client how far one weakness really goes; in defence, it tells administrators which misconfigurations to hunt down first.
Lab only while you learn. Practise on VulnHub machines, Hack The Box, TryHackMe and your own VMs. On client systems, privilege escalation is done only when the rules of engagement allow it, and anything that could crash a host needs explicit approval.
The mindset: enumerate, don't guess
Escalation is rarely about clever exploits. It's about noticing something an administrator got wrong. Build a mental checklist and work through it every time:
- Who am I, and what can I already do?
- What can I run as someone else (sudo, SUID, capabilities)?
- What runs automatically as root that I can influence (cron, services, timers)?
- What can I write to that I shouldn't be able to?
- What credentials are lying around?
- Is the kernel or a core package badly outdated?
Manual enumeration
id; whoami; hostname
cat /etc/os-release; uname -a
sudo -l # what may I run with sudo?
ps aux --forest # what's running, and as whom?
ss -tulpn # services listening only on localhost
cat /etc/crontab; ls -la /etc/cron.* /var/spool/cron 2>/dev/null
find / -perm -4000 -type f 2>/dev/null # SUID binaries
getcap -r / 2>/dev/null # file capabilities
find / -writable -type f -not -path "/proc/*" 2>/dev/null | head -50
ls -la /home/*; ls -la /opt /srv /var/backupsServices listening on 127.0.0.1 are easy to miss from outside: an internal database or admin panel that trusts local connections can be your path up.
Automated helpers
LinPEAS, LinEnum and linux-smart-enumeration (lse) run hundreds of checks and highlight likely paths. They're noisy and produce a lot of output, so learn the manual checks first; then use the tools to make sure you didn't miss anything. On client systems, ask before dropping tools onto a host, and remove them afterwards.
Sudo misconfigurations
sudo -l is the first command many testers run, because it so often ends the exercise.
User webadmin may run the following commands on app01:
(root) NOPASSWD: /usr/bin/find
(root) NOPASSWD: /usr/bin/vim /etc/nginx/nginx.confMany ordinary programs can start a shell or read files: find, vim, less, awk, python, tar, git and more. If one of them is allowed as root, the user effectively is root. The GTFOBins project documents which binaries can be abused through sudo, SUID or capabilities, and it's the reference every tester and defender should know.
Other sudo issues:
- Wildcards in sudo rules (
/usr/bin/tar *) that let users add their own options. env_keeppreserving variables likeLD_PRELOAD, which lets a user load their own library into a root process.- Scripts the user can edit that are allowed through sudo.
- Outdated sudo versions with known vulnerabilities, such as the Baron Samedit heap overflow (CVE-2021-3156).
Fix: grant sudo only to specific commands that can't spawn shells, avoid wildcards, never allow editing of scripts that run as root, and keep sudo patched.
SUID, SGID and capabilities
A SUID binary runs with the privileges of its owner, often root. Standard ones like passwd and mount are expected. A SUID copy of bash, find, cp or a custom in-house program is a red flag.
find / -perm -4000 -type f -exec ls -la {} \; 2>/dev/nullCompare the list against a clean install of the same distribution, then check anything unusual on GTFOBins. Custom SUID programs deserve special attention: if one calls another program without a full path (for example system("service backup start")), a user can put their own service earlier in PATH.
Capabilities split root's powers into smaller pieces. cap_setuid on an interpreter like Python, or cap_dac_read_search on a tool that reads files, can be as dangerous as SUID root:
getcap -r / 2>/dev/null
# /usr/bin/python3.10 cap_setuid=ep <- effectively rootFix: remove SUID bits and capabilities that aren't needed, and include them in configuration baselines and file-integrity monitoring.
Cron jobs, timers and services
Anything that runs as root on a schedule is a target if a normal user can influence it:
- A root cron job runs a script the user can write to. Whatever the user adds runs as root at the next interval.
- A cron job runs a command without a full path, and
PATHin the crontab includes a writable directory. - A backup script uses
tarwith a wildcard (tar czf backup.tgz *) in a directory users can write to. File names beginning with--are treated as options. - systemd service or timer files, or the binaries they start, are writable by the user.
To find jobs that aren't in crontab files, tools like pspy watch for new processes without needing root, showing you exactly what runs and when.
Fix: root-owned scripts must be writable only by root, use full paths, avoid wildcards, and audit cron and systemd units regularly.
Writable files and weak permissions
| Writable by a normal user | Why it matters |
|---|---|
/etc/passwd |
A user can add an account with UID 0 |
/etc/shadow readable |
Password hashes can be cracked offline |
/etc/sudoers or files in /etc/sudoers.d |
A user can grant themselves sudo |
| Service configuration or binaries | Code runs as the service account at next restart |
Directories in root's PATH |
Planted programs run when root uses a command |
Membership of certain groups is also equivalent to root: docker, lxd, disk and sometimes adm (log reading). A user in the docker group can start a container that mounts the host's root filesystem.
Credentials lying around
Escalation often needs no exploit at all:
cat ~/.bash_history ~/.mysql_history 2>/dev/null
grep -RiE "password|passwd|secret|token" /var/www /opt /etc 2>/dev/null | head
ls -la ~/.ssh /root/.ssh 2>/dev/null
find / -name "*.bak" -o -name "*.old" -o -name "*.conf" 2>/dev/null | headLook for database passwords in web application configs, private SSH keys, credentials in shell history and backup files. Password reuse is extremely common: the database password is often also the root or admin password. On a client system, record where the credential was found and redact it in the report.
Kernel exploits: the last resort
Old kernels have well-known local privilege escalation flaws, such as Dirty COW (CVE-2016-5195), Dirty Pipe (CVE-2022-0847) and the Netfilter flaws exploited by ransomware groups. They're tempting, but:
- Kernel exploits can crash or corrupt the host.
- They depend on exact kernel versions and configurations.
- A finding of "kernel is outdated and vulnerable to CVE-X" is usually enough for the report.
On client systems, report the missing patch with authenticated evidence and only attempt exploitation with explicit approval, ideally on a non-production clone.
Containers
If /.dockerenv exists or /proc/1/cgroup mentions docker or kubepods, you're in a container. Escape paths include privileged containers, a mounted Docker socket (/var/run/docker.sock), sensitive host paths mounted inside, and dangerous capabilities like CAP_SYS_ADMIN. These are configuration findings; report them even if you don't attempt an escape.
Defending and detecting
| Path | Prevention | Detection |
|---|---|---|
| Sudo abuse | Minimal, specific rules; no shell-capable binaries | Log sudo use centrally; alert on unusual commands |
| SUID / capabilities | Baseline and remove extras | File-integrity monitoring (AIDE, Wazuh) |
| Cron and services | Root-only write permissions, full paths | auditd rules on cron directories and unit files |
| Credentials | Secrets managers, no passwords in files | Alert on reads of sensitive files |
| Kernel | Patch quickly; live patching where available | EDR alerts on known exploit behaviour |
A simple auditd rule set covering /etc/passwd, /etc/shadow, /etc/sudoers, cron directories and execve by UID 0 from unusual parents catches most of these paths.
Lab
- Download two beginner-to-intermediate privilege escalation VMs from VulnHub, or use the TryHackMe "Linux PrivEsc" room. Keep them on your host-only network.
- On each, enumerate manually first. Write down every candidate path before trying any.
- Escalate using a misconfiguration (sudo, SUID, cron or credentials), not a kernel exploit.
- Run LinPEAS afterwards. Did it find anything you missed?
- For each path you found, write the fix and the detection in one sentence each.
Checkpoint
- Why is
sudo -lone of the first commands to run? - What makes a custom SUID program that calls
system("service ...")dangerous? - Name three groups whose membership is effectively root.
- Why are kernel exploits a last resort on client systems?
- What would you monitor to detect someone abusing a writable root cron script?