Chapter 15 Exercises: Linux Exploitation and Privilege Escalation
⚖️ Legal Note: All exercises must be performed on systems you own or have explicit authorization to test. Use your Student Home Lab or platforms like TryHackMe/HackTheBox.
Exercise 1: SUID Binary Enumeration and Analysis
Difficulty: Beginner | Time: 20 minutes
On your Student Home Lab Linux VM, perform a complete SUID/SGID enumeration.
- Use
findto locate all SUID binaries on the system. - Cross-reference each binary against GTFOBins (https://gtfobins.github.io/).
- For any custom (non-standard) SUID binaries found, use
stringsandltraceto analyze their behavior. - Document which binaries are default/expected and which are potentially exploitable.
Deliverable: A table listing each SUID binary, whether it appears in GTFOBins, and the exploitation method if applicable.
Exercise 2: Kernel Vulnerability Assessment
Difficulty: Beginner | Time: 15 minutes
Using your lab VM, perform a kernel vulnerability assessment.
- Record the exact kernel version using
uname -aandcat /proc/version. - Run Linux Exploit Suggester against the system.
- For each suggested exploit, research whether the specific kernel build is actually vulnerable (consider distribution backports).
- Create a risk matrix showing each potential exploit, its likelihood of success, and its potential impact on system stability.
Deliverable: A kernel vulnerability assessment report with risk ratings.
Exercise 3: Cron Job Exploitation Lab
Difficulty: Intermediate | Time: 30 minutes
Set up a vulnerable cron job scenario on your lab VM and exploit it.
- As root, create a script
/opt/scripts/backup.shthat runstar czf /backup/data.tar.gz /var/www. - Add a cron entry:
* * * * * root /opt/scripts/backup.sh. - Make the script world-writable:
chmod 777 /opt/scripts/backup.sh. - Switch to a low-privilege user and exploit the writable cron script to escalate to root.
- Repeat the exercise using PATH hijacking instead of direct script modification.
Deliverable: Screenshot proof of root access obtained through both methods, plus a remediation report.
Exercise 4: PATH Hijacking Challenge
Difficulty: Intermediate | Time: 25 minutes
Create and exploit a PATH hijacking vulnerability.
- Write a simple C program that calls
system("date")without the full path. - Compile it and set the SUID bit (as root).
- As a low-privilege user, exploit the PATH hijacking vulnerability.
- Modify the C program to use the absolute path
/usr/bin/dateand verify the fix prevents exploitation.
Deliverable: Source code for both vulnerable and fixed versions, plus exploitation proof.
Exercise 5: Capabilities Exploitation
Difficulty: Intermediate | Time: 20 minutes
Explore Linux capabilities as a privilege escalation vector.
- As root, assign
cap_setuid+epto/usr/bin/python3. - As a low-privilege user, exploit this capability to gain root.
- Remove the capability and instead assign
cap_dac_read_search+ep. - Exploit this to read
/etc/shadowand crack a password hash. - Document the differences between these two capability-based attacks.
Deliverable: Step-by-step exploitation documentation for both capabilities.
Exercise 6: Container Escape Lab
Difficulty: Advanced | Time: 45 minutes
Practice container escape techniques.
- Install Docker on your lab VM.
- Run a container with the Docker socket mounted:
docker run -v /var/run/docker.sock:/var/run/docker.sock -it ubuntu. - From inside the container, install the Docker CLI and escape to the host.
- Run a privileged container:
docker run --privileged -it ubuntu. - From inside, escape by mounting the host filesystem.
- Document the indicators that reveal you are inside a container.
Deliverable: Container escape documentation with screenshots and indicators of compromise.
Exercise 7: Automated Enumeration Comparison
Difficulty: Beginner | Time: 30 minutes
Compare the output of different automated enumeration tools.
- Run LinPEAS on your lab VM and save the output.
- Run Linux Smart Enumeration (LSE) at all three verbosity levels.
- Run linuxprivchecker.
- Compare the findings across all three tools.
- Identify any findings that one tool caught but others missed.
Deliverable: A comparative analysis document showing the strengths and gaps of each tool.
Exercise 8: Sudo Abuse Techniques
Difficulty: Intermediate | Time: 30 minutes
Practice exploiting sudo misconfigurations.
- Configure the following sudo entries for a test user (one at a time):
-
(root) NOPASSWD: /usr/bin/vim-(root) NOPASSWD: /usr/bin/find-(root) NOPASSWD: /usr/bin/less-(root) NOPASSWD: /usr/bin/python3-(root) NOPASSWD: /usr/bin/env - For each entry, escalate to root using the GTFOBins technique.
- For each entry, write a remediation recommendation.
Deliverable: Exploitation proof for each sudo entry plus remediation guidance.
Exercise 9: Writable /etc/passwd Exploitation
Difficulty: Beginner | Time: 15 minutes
Exploit writable /etc/passwd to add a root user.
- Create a backup of
/etc/passwd. - Make
/etc/passwdwritable by your test user (as root). - As the test user, generate a password hash using
openssl passwd -1 -salt hacker MyPassword. - Add a new line to
/etc/passwdwith UID 0 and the generated hash. - Switch to the new user and verify root access.
- Restore the original
/etc/passwdand fix permissions.
Deliverable: Documentation of the exploitation process and the password hash format.
Exercise 10: LD_PRELOAD Exploitation
Difficulty: Advanced | Time: 30 minutes
Exploit LD_PRELOAD for privilege escalation.
- Configure sudoers to preserve LD_PRELOAD:
Defaults env_keep += "LD_PRELOAD". - Grant a test user sudo access to a harmless command (e.g.,
/usr/bin/id). - Write a malicious shared library that spawns a root shell.
- Compile it as a shared object and use LD_PRELOAD with the sudo command.
- Remove the LD_PRELOAD from env_keep and verify the fix.
Deliverable: Source code for the malicious shared library and exploitation proof.
Exercise 11: Wildcard Injection Attack
Difficulty: Advanced | Time: 25 minutes
Exploit wildcard expansion in a cron job using tar.
- Create a cron job that runs
cd /var/www/html && tar czf /backup/web.tar.gz *as root. - As a low-privilege user with write access to
/var/www/html, create files named: ---checkpoint=1---checkpoint-action=exec=sh privesc.sh - Create
privesc.shwith a payload. - Wait for the cron job and verify execution.
Deliverable: Explanation of why wildcard injection works and defensive measures.
Exercise 12: NFS Root Squashing Bypass
Difficulty: Intermediate | Time: 25 minutes
Exploit NFS misconfigurations.
- Set up an NFS share with
no_root_squashenabled. - From a remote machine, mount the share as root.
- Create a SUID binary on the share.
- Access the SUID binary from the target and escalate privileges.
- Fix the configuration by removing
no_root_squash.
Deliverable: NFS exploitation documentation and secure configuration guide.
Exercise 13: Python Script for Linux Enumeration
Difficulty: Intermediate | Time: 45 minutes
Write a Python script that automates Linux privilege escalation enumeration.
- The script should check: SUID binaries, capabilities, cron jobs, writable directories, sudo permissions, and kernel version.
- Color-code output by severity (use ANSI escape codes).
- Cross-reference SUID binaries against a built-in GTFOBins database.
- Output results in both human-readable and JSON format.
Reference: See code/example-01-linux-enum.py for a starting framework.
Deliverable: Working Python script with sample output.
Exercise 14: Shared Library Hijacking
Difficulty: Advanced | Time: 30 minutes
Exploit a missing shared library in a SUID binary.
- Create a simple C program that loads a shared library from a non-standard path.
- Compile it, set SUID, and remove the library.
- Verify the binary attempts to load the missing library using
strace. - Create a malicious library at the expected path.
- Execute the SUID binary and verify code execution.
Deliverable: Source code for both the binary and the malicious library, plus exploitation walkthrough.
Exercise 15: Complete Privilege Escalation Challenge
Difficulty: Advanced | Time: 60 minutes
Set up a multi-layered privilege escalation scenario.
- Create a VM with at least three different privilege escalation vectors (e.g., SUID binary, writable cron, misconfigured capability).
- Create a low-privilege user.
- Challenge a partner to find and exploit all three vectors.
- Time the exercise and compare approaches.
- Write a penetration test report documenting all findings.
Deliverable: Full penetration test report with executive summary, technical findings, evidence, and remediation recommendations.
Exercise 16: Restricted Shell Escape
Difficulty: Intermediate | Time: 20 minutes
Practice escaping restricted shell environments.
- Configure
rbashfor a test user. - Attempt to escape using at least three different methods (vim, awk, python, ssh, etc.).
- Document which methods work and which are blocked.
- Configure additional restrictions and test again.
Deliverable: Table of escape methods tested with success/failure status.
🔵 Blue Team Exercise: Hardening Challenge
Difficulty: Intermediate | Time: 45 minutes
Harden a Linux system against all privilege escalation vectors covered in this chapter.
- Audit and remove unnecessary SUID bits.
- Review and fix cron job permissions.
- Remove dangerous capabilities.
- Configure sudo with least privilege.
- Enable and configure AppArmor or SELinux.
- Set up auditd rules to detect privilege escalation attempts.
- Run LinPEAS and verify minimal findings.
Deliverable: Hardening checklist with before/after comparison.