Linux Privilege Escalation
This post explains the process of enumerating a linux system in order to find paths to escalate privileges.
Overiview
Automated tools
Manual - General things
These are the general things we will be enumerating in the process below
OS
- OS Version
- Kernel Version
Services
- Running Services:
ps aux | grep root
- Installed Packages and Versions
User
whoami
,id
,hostname
- User Home Directories
- Sudo Privileges:
sudo -l
Files & Directories
- Configuration files:
.conf
&.config
- Readable Shadow File
- Password Hashes in
/etc/passwd
(more common on embedded devices and routers) - Writeable Directories
- Writeable Files
- SETUID and SETGID Permissions
Cron Jobs
- Under:
/etc/cron*
File Systems
- Unmounted File System and Aditional Drivers
- File Systems & Additional Drives
Process of enumeration
1. Gaining Situational Awareness
whoami
id
hostname
cat /etc/os-release
echo $PATH
env
uname -a
lscpu
cat /etc/shells
lsblk # block devices
lpstat # printers
cat /etc/fstab
# network information
route
arp -a
cat /etc/passwd
cat /etc/passwd | cut -f1 -d: # usernames
grep "*$" /etc/passwd
cat /etc/group
getent group sudo
ls /home
# file systems
df -h
# unmounted fs
cat /etc/fstab | grep -v "#" | column -t
# hidden files for $USER
find / -type f -name ".*" -exec ls -l {} \; 2>/dev/null | grep $USER
# setuid files
find / -perm -4000 -exec ls -ldb {} \; 2>/dev/null
find / -perm -4000 -type f -exec ls -l {} \; 2>/dev/null
# setgid files
find / -uid 0 -perm -6000 -type f 2>/dev/null
# hidden directories
find / -type d -name ".*" -ls 2>/dev/null
ls /var/tmp # data retained 30 days
ls /tmp # data retained 10 days or until system reboot
2. Linux Services & Internals Enumeration
ip a
cat /etc/hosts
lastlog # users's last login command
who # check who's logged in
finger
history
find / -type f \( -name *_hist -o -name *_history \) -exec ls -l {} \; 2>/dev/null
# finding history files
# Cronjobs
ls -la /etc/cron.*/
cat /etc/crontab
# writeable files (check for cronjob abuse)
find / -path /proc -prune -o -type f -perm -o+w 2>/dev/null
# proc filesystem is a virtual fs that contains info about system processes, hw, system info
find /proc -name cmdline -exec cat {} \; 2>/dev/null | tr " " "\n"
apt list --installed | tr "/" " " | cut -d" " -f1,3 | sed 's/[0-9]://g' | tee -a installed_pkgs.list # list of installed packages
sudo -V # sudo version
ls -l /bin /usr/bin/ /usr/sbin/ # list of binaries
# compare available binaries against GTFO
for i in $(curl -s https://gtfobins.github.io/ | html2text | cut -d" " -f1 | sed '/^[[:space:]]*$/
# analyze system calls and signal processing
strace ping -c1 IP
find / -type f \( -name *.conf -o -name *.config \) -exec ls -l {} \; 2>/dev/null # configuration files
# Scripts
find / -type f -name "*.sh" 2>/dev/null | grep -v "src\|snap\|share"
ps aux | grep root
# running services by user