Skip to content
Tutorials Center
My learning

Topics

Lesson 23 of 37 ยท Meterpreter and Post-exploitation

Privilege Escalation Concepts and Hardening

Learn why privilege escalation matters in a penetration test, the common weakness classes, and how to audit and harden your own systems against them.

Getting a session usually means running as an ordinary user. Privilege escalation is moving from that account to one with more rights, such as an administrator or root. For a tester it demonstrates impact; for a defender it is the step that turns a small incident into a major one, so preventing it is where hardening pays off.

This lesson stays at the level of weakness classes and checks. It does not include working exploit code. Metasploit ships modules that probe for such weaknesses, and a local_exploit_suggester post module compares a host's facts with known issues, but the real lesson is how to find and fix the root causes in your own estate.

Escalating privileges on a system you do not own or have permission to test is illegal. Practice on your own lab machines only.

Why it works: weakness classes

Almost every escalation comes from one of a small set of causes:

  1. Unpatched software. A known vulnerability in the kernel, a driver or a privileged service.
  2. Misconfiguration. A service running as admin that ordinary users can modify, a world-writable script run by a scheduled job.
  3. Excess privilege. A user in too many groups, sudo rules like "run anything without a password".
  4. Exposed secrets. Admin passwords in scripts, config files or shell history.
  5. Weak trust boundaries. Unquoted service paths on Windows, writable directories on a program's search path.
flowchart TD
    U["Low-privilege session"] --> P["Patch gap"]
    U --> M["Misconfiguration"]
    U --> X["Too many rights"]
    U --> S["Exposed secrets"]
    P --> A["Administrator or root"]
    M --> A
    X --> A
    S --> A

Four common roads to the same destination.

What the tools report

The suggester module and similar enumeration scripts list candidates. Their output is a lead, not proof, and false positives are common because they judge by version numbers.

TEXT
# Illustrative output (invented)
[*] 192.0.2.30 - Collecting local exploits for x64/linux...
[*] 192.0.2.30 - 40 exploit checks are being tried...
[+] 192.0.2.30 - exploit/linux/local/example_one: The target appears to be vulnerable.
[-] 192.0.2.30 - exploit/linux/local/example_two: The target is not exploitable.

A responsible report lists the affected package and version, the fix (usually an update), and how the tester confirmed it in the lab, never a copy-paste attack recipe.

Auditing your own hosts

You can find most of these issues without any exploit by simply reading configuration. The stand-in below audits an invented sudoers-style rule list and a file-permission table.

Python Audit sudo-style rules and file permissions

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Scoring and fixing

Findings need priority. A rough model multiplies how easy the weakness is to use by how much the attacker gains.

Python Prioritise escalation findings

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Hardening checklist

  • Patch operating systems and privileged services on a schedule; track kernel updates separately.
  • Follow least privilege: separate admin accounts, no standing admin on daily-use accounts.
  • Review sudo rules and Windows service permissions; avoid wildcards and shell-capable commands.
  • Remove secrets from scripts; use a secrets manager.
  • Enable application control (allow-lists) and endpoint detection that flags privilege changes.
  • Alert on new administrators, new services, and changes to scheduled tasks.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which is the most common single cause of privilege escalation in assessments?

    Unpatched software and misconfigured permissions or services account for most escalations.
  2. 2. What does a suggester module's 'appears to be vulnerable' result mean?

    Version-based checks produce leads and false positives, so confirm in the lab.
  3. 3. Why is NOPASSWD: ALL risky?

    The account can run anything as root without further proof, so escalation is automatic.
  4. 4. Which response belongs in a report?

    Reports describe the weakness and remediation, not a recipe for misuse.

Summary

  • Escalation comes from patch gaps, misconfiguration, excess rights, exposed secrets and weak trust boundaries.
  • Enumeration output is a lead to confirm, not proof.
  • Auditing configuration finds many issues without any exploit.
  • Least privilege, patching, secrets management and monitoring remove the paths.

Next: Auxiliary Modules