Lab 16: Linux Privilege Escalation

Objective

Escalate from an unprivileged shell to root inside a Docker container using four real techniques:

  1. SUID binary abuse — find setuid executables and use GTFOBins payloads to get a root shell

  2. Sudo misconfiguration — exploit NOPASSWD sudo rules that allow running commands as root

  3. Writable cron jobs — overwrite a script executed by root's cron with a reverse shell

  4. World-writable /etc/passwd — add a new root user by writing directly to the password file


Background

Privilege escalation (privesc) is the step after initial access — turning a low-privileged foothold into root. Every real engagement involves it. The Linux privesc playbook is well-documented because the same misconfigurations appear in production environments year after year.

Real-world examples:

  • CVE-2021-4034 (PwnKit) — polkit pkexec SUID binary mishandles argv; any local user → root. Affects all major Linux distros; 12 years undetected. Thousands of cloud VMs compromised within 24h of PoC release.

  • CVE-2019-14287sudo versions < 1.8.28: sudo -u#-1 runs as root even when user is explicitly excluded. A (ALL, !root) sudoers rule fails to block it.

  • 2021 TeamCity privesc chain — writable cron script in /etc/cron.d/ executed by root; attacker overwrites it post-SQLi compromise to get root shell.

  • Dirty COW (CVE-2016-5195) — race condition in kernel copy-on-write; unprivileged user writes to root-owned SUID binaries. Exploited in wild against hosting providers.

OWASP / MITRE: MITRE ATT&CK T1548 (Abuse Elevation Control), T1053 (Scheduled Task)


Architecture

Time

45 minutes


Lab Instructions

Step 1: Setup — Create Vulnerable Environment


Step 2: Reconnaissance as lowuser

📸 Verified Output:


Step 3: Technique 1 — SUID Python3 → Root Shell

📸 Verified Output:


Step 4: Technique 2 — Sudo Misconfiguration (find)

📸 Verified Output:


Step 5: Technique 3 — Writable Cron Script

📸 Verified Output:


Step 6: Technique 4 — World-Writable /etc/passwd

📸 Verified Output:


Steps 7–8: Full Privesc Checklist + Remediation


Further Reading

Last updated