Table of Contents
Summery
This note was created as a quick access, general purpose reference for assessing a host in term of privilege escalation.
For more detailed breakdowns refer to Full linux privilege escalation checklist.
As always with automation, especially of privilege escalation. Be sure to perform manual privilege escalation as well.
Checker
Here are the sections that will be covered.
- - Automation
- - Users and groups
- - Permissive sudo privileges
- - Permissive group membership
- - PATH abuse
- - System
- - Kernel exploits
- - OS version exploits
- - Network information
- - New networks
- - Locally opened ports
- - Files and directories
- - Write permissions abuse
- - SUID and SGID abuse
- - Permissive Linux capabilities
- - Private keys
- - Processes
- - Privileged process abuse
- - Cron
- - Writable binaries or scripts
- - Writable jobs
- - Unmounted drives
- - Unauthorized storage enumeration
- - systemd
- - Abuse misconfigured services
- - Override insecure services or add malicious ones
- - Installed applications
- - Public exploits
- - Drivers
- - Public exploits
Automation
Run linpeas in the background while you perform a manual check.
You may also consider unix-privesc-check for a double check but it’s optional - it’s pre-installed on kali at /usr/bin/unix-privesc-check. You can run it in standard and detailed mode on target host - ./unix-privesc-check standard > output.txt. Linenum is also an option.
Users and groups
Attacks: Permissive sudo privileges, Permissive group membership, PATH abuse
Current user
whoami - Confirm the user you’re on
sudo -l - List sudo permissions your current Linux user has
id - Basic contextual user information
getent group <GROUP NAME> - Check who is the member of a given group
find / -group <group> -ls 2>/dev/null - Find files owned by a given group
History
cat .bashrc; echo "__________";cat .bash_history; echo "__________"; cat .bash_logout; echo "__________"; cat .bash_profile; echo "__________"; cat .profile - Read the Bash shell configuration file, history file, logout file and profile setup
env - Shows and manipulates environment variables for processes. Sometimes system administrators store credentials inside environment variables
Other users
cat /etc/passwd - Enumerate all users
ps au - See logged-in users
cat /etc/shadow - Check if you can view the host’s credentials
cat /etc/security/opasswd - Check of old passwords
PATH
echo $PATH - Prints your shell’s PATH environment variable
env - Check environmental variables
PATH=.:${PATH}, export PATH and then echo $PATH - Check if you can write to $PATH
System
Attacks: Kernel exploits, OS version exploits
System basics
hostname - Confirm the host you’re on
uname -a - Get operating system information and kernerl version (kernel version - 5.9.0-050900-generic)
System details
cat /etc/issue - Gather further data about the OS
cat /etc/*-release - Gather further data about the OS
cat /proc/version - Gather further data about the OS
arch - Get system’s architecture
Sudo
sudo -V - Check sudo version
Network information
Attacks: New networks, Locally opened ports
Basic
ifconfig /all or ip a - List the TCP/IP configuration
route or routel - Display network routing tables
ss -anp - Display active network connections and listening ports
ss -tun - Check locally open ports
With special rights
sudo tcpdump -i lo -A | grep "pass" - Inspect running raw sockets for a mention of “pass” in them
find / -iname "*iptables*" 2>/dev/null - List firewall rules
Binaries
Attacks: Write permissions abuse, SUID and SGID abuse, Permissive Linux capabilities, Private keys
Files and directories
find / -writable 2>/dev/null - Search for all writable files and directories by the current user
find / -name ".*" -ls 2>/dev/null - Look for hidden folders and files
find /home/* -type f -name "*.txt" -o ! -name "*.*" - Look for simple notes that might’ve been missed
for l in $(echo ".sql .db .*db .db*");do echo -e "\nDB File extension: " $l; find / -name *$l 2>/dev/null | grep -v "doc\|lib\|headers\|share\|man";done - Look for database files
find / -type f -name "*.sh" 2>/dev/null | grep -v "src\|snap\|share" and for l in $(echo ".py .pyc .pl .go .jar .c .sh");do echo -e "\nFile extension: " $l; find / -name *$l 2>/dev/null | grep -v "doc\|lib\|headers\|share";done - Check for scripts
find / -type d -iname "*git*" 2>/dev/null - Look for .git directories across the filesystem
grep -rinC 2 "password" . 2>/dev/null - Check for a string in files recursively through directories
SUID and SGID
find / -perm /4000 -type f 2>/dev/null - Search for SUID binaries
find / -user root -perm -6000 -exec ls -ldb {} \; 2>/dev/null - Search for SUID and SGID
while read -r i; do bin="${i##*/}"; url="https://gtfobins.github.io/gtfobins/$bin/"; [ "$(curl -sSL -o /dev/null -w '%{http_code}' "$url")" = "200" ] && echo "Check GTFO: $url"; done < suid.txt - Check for potentially GTFObins exploitable binaries and programs. This command is run locally, you list program and binaries in a file and look through it
Linux capabilities
/usr/sbin/getcap -r / 2>/dev/null - Enumerate binaries with linux capabilities
Private keys
grep -rnw "PRIVATE KEY" /* 2>/dev/null | grep ":1" - Look for private keys
grep -rnw "ssh-rsa" /home/* 2>/dev/null | grep ":1" - Look for private keys
Processes
Attacks: Privileged process abuse
ps aux - List system processes
watch -n 1 "ps -aux | grep pass" - Create a live preview of the running processes - grep it to your likings
Scheduled tasks
Attacks: Writable binaries or scripts, Writable jobs
To enumerate cron fully, here’s a short cheatsheet:
ls -lah /etc/cron*- Enumerate all cron jobs from the sub-directoriescat /etc/crontab; echo "__________"; cat /etc/cron.d/*- Reads both/etc/crontababd/etc/crontab- Run
crontab -lto view the current user’s scheduled jobs - Additionally, you can check for existance of both
cat /var/log/cron.logandgrep "CRON" /var/log/syslog
Also, you can check recently ran cron jobs wtih systemctl status cron.
Unmounted drives enumeration
Attacks: Unauthorized storage enumeration
Disks and file systems
cat /etc/fstab or cat /etc/fstab | grep -v "#" | column -t (for prettier output) - View mounted file systems
df -h - View mounted file systems
mount - List all mounted filesystems (disks and and remote things like shares), (always use both for redundency)
lsblk - View all available disks and partitions
NFS
showmount -e - Check for a accessible NFS mounts
mount -t nfs - Check for locally mounted NFS shared
systemd
systemctl list-unit-files --type=service - List all services
systemctl list-unit-files --type=service --state=enabled - Show all enabled services
systemctl cat <service> - Inspect an interesting service
systemctl show <service> -p ExecStart - Check what command it executes
systemctl show <service> -p User - Check which user runs it
systemctl is-enabled <service> - Check whether it starts automatically
systemctl list-dependencies <service> - Check dependencies
Installed applications
Attacks: Public exploits
dpkg -l - List applications installed by dpkg. Consider other file managers depending on the distro
Driver enumeration
Attacks: Public exploits
lsmod - Enumerate the loaded kernel modules
modinfo - Find out more about the specific module