Skip to content
Tutorials Center
My learning

Topics

Lesson 33 of 53 ยท Systems and Post-Exploitation Concepts

Privilege Escalation Concepts and OS Hardening

Learn how privilege escalation happens through weak permissions, services and SUID files, and how least privilege, patching and baselines stop it. With stand-ins.

Attackers rarely arrive with full control. A phished user, a flawed web application or a stolen low-level account usually gives them a foothold with limited rights. Privilege escalation is the step from "can run as an ordinary user" to "can act as an administrator". It matters because most protections assume ordinary users stay ordinary.

This lesson covers where escalation opportunities come from, at the concept level, and focuses on the cure: removing the opportunities through hardening. It does not walk through exploiting specific vulnerabilities. Escalation testing belongs on machines you own or are authorized to assess, ideally inside your lab. The runnable parts are Node stand-ins that audit a made-up file-permission listing.

Where escalation comes from

Bad permissions Files anyone can change.
Weak services Services run as admin with loose settings.
SUID/SGID Programs that run with their owner's rights.
Missing patches Known flaws left open.

Every item is a configuration or maintenance problem you can fix.

1 / 2

Vertical and horizontal escalation

Two directions are worth separating:

  • Vertical: gaining higher rights than you had, such as an ordinary user becoming root (Linux) or Administrator/SYSTEM (Windows).
  • Horizontal: taking over another account with similar rights, such as reading a colleague's files. It is often a stepping stone to vertical escalation or to lateral movement.

On the web, the same idea appears as access-control bugs, covered in Authentication, Sessions and Access Control Flaws. This lesson is about the operating system.

Common sources of escalation (concept level)

Misconfigured file and folder permissions

If an ordinary user can modify a script, program or configuration file that a privileged account later runs, the user can effectively run code as that account. Typical findings are world-writable files in system paths, scripts run by a scheduled job but owned by an ordinary user, and configuration files containing passwords that anyone can read. On Linux, review the permission bits (see Linux and Command-Line Skills for Security Work); on Windows, review access control lists.

Weak or unnecessary services

A service that runs as an administrator account but loads files from a place users can write to, or whose executable path contains unquoted spaces on Windows, can be a route to higher rights. Services listening on the network with default passwords are another. The fix is to run each service as a dedicated low-privilege account, store its files where only administrators can write, and remove services nobody needs.

SUID and SGID programs

On Unix-like systems, a file with the setuid bit runs with the rights of its owner rather than the user who started it. Programs such as the one that changes your password need this to work. The risk arises when a root-owned setuid program is unnecessary, outdated, or lets a user make it run arbitrary commands. Administrators periodically list all setuid files and compare the result with a known-good list. The permission string shows it as an s in the owner's execute position, for example -rwsr-xr-x.

A read-only example of that audit on your own Linux machine:

Terminal
# list setuid files owned by root (run on your own machine)
find / -perm -4000 -type f -user root 2>/dev/null

Unpatched software

Operating-system and application vulnerabilities often allow a local user to gain administrator rights. Attackers read public advisories as well as defenders do, so the time between a fix being published and being installed is a window of risk. Patching on a regular cycle, with faster handling for flaws known to be exploited, closes it. Prioritization is covered in Vulnerability Scanning and Triage.

Credentials left behind

Passwords in scripts, shell history, configuration files and backups let an attacker simply log in as a more privileged user, with no exploit at all. Secrets management and good file permissions remove this class of finding.

Over-broad administrative rights

Users in the administrators group by default, or given unrestricted sudo, hand over escalation without any effort. A sudo rule that allows an editor or interpreter to run as root is the same as allowing everything, because those programs can launch shells.

Hardening: closing the doors

Least privilege is the thread running through all of it: users, services and applications get the minimum rights they need for their job.

A baseline gives you a starting point. Organizations such as the Center for Internet Security publish configuration benchmarks for common operating systems, and vendors publish their own guides. The recommendations vary by system but usually cover:

  • Remove software, services and accounts you do not need; disable default accounts.
  • Require strong authentication, MFA for administrators, and lock inactive accounts.
  • Restrict sudo or administrator rights to named people and specific commands; use separate admin accounts.
  • Set strict permissions on system and application files; avoid world-writable paths.
  • Turn on host firewalls and allow only needed inbound ports.
  • Enable disk encryption and automatic security updates.
  • Turn on auditing and send logs to a central system (Logging, Monitoring and SIEM Basics).
  • Apply mandatory-access-control features where available (for example SELinux or AppArmor on Linux).

Baselines are starting points, not laws: apply them to a test system first, because some settings break applications. Document exceptions and the reason for each.

Stand-in: audit a fake permission listing

The program below receives text that looks like the output of a long directory listing on a made-up Linux server and flags risky entries. The data is invented. The rules are simplified versions of what real audit tools check: world-writable files, unexpected setuid files, and root-owned files that ordinary users can write.

JS Stand-in: permission listing auditor

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

No output.

The results are leads for a human to examine, not proof of a vulnerability. A setuid file that is not on the allow-list might be legitimate software; the audit simply asks for a decision.

Stand-in: compare a system with a baseline

Hardening is easier when it is a checklist you can score. Here a made-up system's settings are compared with a tiny baseline and a percentage is reported. Project: Server Hardening Checklist Checker expands this idea.

JS Stand-in: baseline score

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

No output.

Privilege escalation tooling and famous flaws

Enumeration scripts such as WinPEAS and LinPEAS, PowerUp and the Linux Exploit Suggester list misconfigurations that allow escalation: weak service permissions, unquoted service paths, writable startup scripts, SUID binaries and unpatched kernels. GTFOBins is a public catalogue of Unix programs that can be abused for privilege escalation when granted through sudo or the SUID bit. Defenders run the same scripts on their own systems as an audit, and they should check their sudo rules against that catalogue.

UAC bypass: Windows User Account Control prompts before administrator actions, but Microsoft does not treat it as a strict security boundary: some auto-elevated built-in programs can be tricked into launching code at a higher integrity level without a prompt. Defense is to run daily work as a standard user, raise UAC to the highest level, remove local administrator rights and use application control.

PrintNightmare (CVE-2021-34527) was a flaw in the Windows Print Spooler service that allowed remote code execution or local privilege escalation. Lessons: patch quickly, disable the Spooler on servers and domain controllers that do not print, and restrict who can install printer drivers.

Credential tools such as Mimikatz, and command-and-control frameworks such as Cobalt Strike, are what attackers use after escalation. Defenders respond with Credential Guard, LSA protection, tiered administration and detections for these tools.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is vertical privilege escalation?

    Vertical escalation raises the level of access, for example from ordinary user to administrator. Taking over a peer account is horizontal.
  2. 2. Why does a setuid root program deserve extra review?

    A setuid program executes with the owner's privileges. Keep the set minimal and compare against a known-good list.
  3. 3. Which is the best overall principle for reducing escalation risk?

    When accounts and services have only the rights they need, a compromise of one gains far less.
  4. 4. How should you treat the findings of an automated permission audit?

    Audits flag unusual settings. Someone who knows the system decides whether each one is legitimate or needs fixing.

Summary

  • Privilege escalation turns a limited foothold into administrative control; it is a configuration and maintenance problem as much as a vulnerability problem.
  • Typical sources: weak permissions, weak services, unneeded setuid files, missing patches, stored credentials and over-broad admin rights.
  • Least privilege, patching, baselines and regular audits remove most opportunities.
  • Baselines such as CIS-style guides are starting points; test before applying and document exceptions.
  • Audit findings are leads for human review.
  • The stand-ins worked on invented listings and settings; real audits run on systems you own or are authorized to assess.

Next: Malware Types and Social Engineering Defense.