Privilege Escalation, Explained
If you are reading this, you have probably seen "privilege escalation" in every attack write-up and you want to know what it really means, why it happens, and what stops it.
By the end you will be able to explain what privilege escalation is, tell vertical from horizontal escalation, name the common ways it happens on Linux, Windows and web applications, and describe the defences and the warning signs. Real examples are included, and every technique is described at the level a defender needs to understand it.
1. What privilege escalation is
Every account on a system has a level of privilege: what it is allowed to read, change and run. A normal user can use their own files. An administrator (or root on Linux, SYSTEM on Windows) can change almost anything.
Privilege escalation is when someone gets more privilege than they were meant to have, usually by moving from a low-privilege account to a high-privilege one. In MITRE ATT&CK, the standard catalogue of attacker behaviour, the tactic is described in one line (MITRE ATT&CK, TA0004):
"The adversary is trying to gain higher-level permissions."
Why attackers need it
An attacker's first foothold is often weak. They might have tricked one employee into running something, or stolen one ordinary password. MITRE explains that initial access may be possible with basic user privileges, but adversaries typically need administrator-level or system-level access to accomplish their objectives. With only a normal account, they cannot disable security tools, read other people's data, install themselves permanently, or reach other systems easily.
So privilege escalation is usually a middle step in an attack:
- Get a foothold (a low-privilege account or process).
- Escalate privileges.
- Do the real damage with the higher access (steal data, spread, persist).
The hotel keycard picture
Your hotel keycard opens your room only. Privilege escalation is either of these:
- You find a way to make your card open the master key door (reaching a higher level), or
- You find a way to open another guest's room (reaching someone else's level).
Security people call the first vertical and the second horizontal.
It is an outcome, not one bug
There is no single "privilege escalation bug". It is a result that many different weaknesses can produce. The CWE project, which catalogues weaknesses, makes this point directly: reports that only say "privilege escalation" describe the technical impact rather than the root cause (CWE-269). To understand or fix an escalation, you always ask: what weakness made it possible?
2. Vertical and horizontal escalation
| Type | Meaning | Example |
|---|---|---|
| Vertical | A user gains access to functions reserved for a higher level | "A non-admin user accesses an admin page to delete accounts" |
| Horizontal | A user gains access to another user's resources at the same level | "An employee accessing other employees' records beyond their own" |
| Horizontal to vertical | Horizontal access is used to compromise a more privileged user | Taking over an administrator's account after reaching another user's data |
The definitions above follow PortSwigger's Web Security Academy (source), which defines vertical escalation as gaining "access to functionality that they are not permitted to access" and notes that "a horizontal privilege escalation attack can be turned into a vertical privilege escalation, by compromising a more privileged user."
Two points that clear up confusion:
- On an operating system, "privilege escalation" usually means vertical (user to admin/root).
- In web applications you will see both. Reading another customer's order by changing an ID in the URL is horizontal. Reaching an admin-only page is vertical. Both fall under Broken Access Control, the number one category in the OWASP Top 10:2025.
Not the same as lateral movement
Lateral movement means moving from one machine to another. Privilege escalation means gaining a higher level of access, on the same machine or in the same system. They often happen together, but they are separate steps in ATT&CK.
3. Why it is possible: four root causes
Almost every escalation traces back to one of these:
| Root cause | Plain meaning | Example |
|---|---|---|
| Software vulnerabilities | A bug in code that runs with high privilege | A flaw in the operating system kernel or a system service |
| Misconfigurations | Settings that give more power than intended | A file that root runs but any user can edit; an over-generous sudo rule |
| Credential and identity weaknesses | Stolen, reused or weak credentials for stronger accounts | A shared local administrator password |
| Excess privilege by design | Programs and accounts given more power than their job needs | A service running as root when it needs no such rights |
The last cause has its own CWE entry. CWE-250, Execution with Unnecessary Privileges, describes software that "performs an operation at a privilege level that is higher than the minimum level required", which makes otherwise harmless bugs dangerous.
The ATT&CK techniques
ATT&CK currently lists 13 techniques under the Privilege Escalation tactic. You do not need to memorize them, but the list shows how wide the topic is:
| ID | Technique | In plain words |
|---|---|---|
| T1548 | Abuse Elevation Control Mechanism | Misusing the system's own tools for gaining higher rights (setuid, sudo, UAC) |
| T1134 | Access Token Manipulation | Borrowing or forging the identity token of a more powerful process (Windows) |
| T1098 | Account Manipulation | Changing accounts or their permissions to gain or keep access |
| T1547 | Boot or Logon Autostart Execution | Making code run automatically at startup or login, possibly with higher rights |
| T1037 | Boot or Logon Initialization Scripts | Abusing scripts that run at startup or login |
| T1543 | Create or Modify System Process | Creating or editing services that run with high privilege |
| T1484 | Domain or Tenant Policy Modification | Changing central policy settings in a domain or cloud tenant |
| T1611 | Escape to Host | Breaking out of a container to reach the machine underneath |
| T1546 | Event Triggered Execution | Running code when a system event happens, possibly with higher rights |
| T1068 | Exploitation for Privilege Escalation | Using a software vulnerability to gain higher rights |
| T1055 | Process Injection | Running code inside another process, borrowing its rights |
| T1053 | Scheduled Task/Job | Using task scheduling to run code as a more privileged account |
| T1078 | Valid Accounts | Using legitimate credentials, including high-privilege ones |
MITRE adds that these techniques "often overlap with Persistence techniques, as OS features that let an adversary persist can execute in an elevated context."
4. Linux examples
Linux enforces who may do what through users, groups and file permissions (see the Linux Fundamentals post). Escalation happens when something lets a normal user borrow root's power.
4.1 Setuid and setgid programs
A program with the setuid bit runs with the privileges of its owner, not the person who launched it. That is how a normal user can run passwd to change their own password. MITRE describes the risk: when these bits are set, "the application will run with the privileges of the owning user or group respectively", and attackers can abuse an existing setuid program that has weaknesses, or set the bit on their own code (T1548.001).
If a setuid-root program can be tricked into running other commands, the person who tricked it gets root's power. For this reason defenders keep the list of setuid programs as short as possible and know what is on it. Whether a given program is dangerous depends on what it can be made to do. The GTFOBins project catalogues which common Unix programs have functions that can be misused in setuid, sudo and capability contexts. Its authors note it is "not a list of exploits": the programs are not vulnerable themselves, but misconfiguration around them is the problem (GTFOBins).
4.2 sudo rules that are too generous
sudo lets selected users run commands as root, controlled by the /etc/sudoers file. Problems arise with overly broad rules, for example one that lets a user run any command with no password (NOPASSWD: ALL). MITRE lists weak sudoers entries and long-lived password caching as abuse paths (T1548.003).
Two facts from the sudo manual are worth knowing (sudoers manual):
- By default sudo requires a password, but the
NOPASSWDtag changes that for specific commands. - Sudo remembers a successful password for a time. The default is 5 minutes, and setting the timeout to 0 makes it ask every time.
Even a sudo rule that allows only one program can be too much if that program can launch a shell or edit arbitrary files, which is exactly what GTFOBins documents for the sudo context.
4.3 Jobs and services that run as root
If root runs a script or program on a schedule (cron) or as a service, and an ordinary user is allowed to edit that file or the folder it lives in, the user can effectively run code as root. ATT&CK covers this under Scheduled Task/Job, where tasks can run "under the context of a specified account (such as one with elevated permissions/privileges)", and under Create or Modify System Process (T1053, T1543). The principle is simple: whoever can change what root runs, controls root.
4.4 Capabilities
Linux splits root's powers into separate capabilities that can be given individually: "Linux divides the privileges traditionally associated with superuser into distinct units, known as capabilities, which can be independently enabled and disabled." A program granted a strong capability can be as dangerous as a setuid-root program. For example CAP_DAC_OVERRIDE allows bypassing file permission checks, and the manual warns that CAP_SYS_ADMIN "can plausibly be called 'the new root'" (capabilities(7)).
4.5 Kernel and system software vulnerabilities
Sometimes the cause is a genuine bug in a privileged component. Two well-known examples:
| Name | CVE | What it was |
|---|---|---|
| Dirty COW | CVE-2016-5195 |
A race condition in the Linux kernel's copy-on-write handling that let a local user turn a read-only memory mapping of a file into a writable one. It existed since kernel 2.6.22 (September 2007) and affected kernels before 4.8.3. Affected systems included Android devices (Wikipedia) |
| PwnKit | CVE-2021-4034 |
A memory corruption flaw in pkexec, part of polkit, that let "any unprivileged local user" obtain full root privileges. The vulnerable code had been present since pkexec was created in May 2009 and was installed by default on major Linux distributions (Qualys advisory) |
Both are local bugs: the attacker must already be on the machine. That is exactly the situation after an initial foothold, which is why patching them matters even on machines "nobody can reach from outside."
4.6 Checking your own Linux lab
On a machine you own, these commands show what an attacker would look at first. They are standard auditing steps:
id # who am I, which groups
sudo -l # what may I run with sudo
find / -type f -perm /6000 2>/dev/null # setuid or setgid files (any of those bits)
getcap -r / 2>/dev/null # files with capabilities
ls -l /etc/crontab /etc/cron.* 2>/dev/null # scheduled jobs
uname -r # kernel version
For the find command, -perm /6000 means "any of these bits is set", here setuid (4000) or setgid (2000). Compare the results to what you expect. An unfamiliar setuid file, or a root-run script writable by regular users, deserves immediate attention.
5. Windows examples
Windows uses access tokens (a record of who you are and which privileges you hold) and integrity levels.
5.1 User Account Control (UAC)
Microsoft describes UAC as limiting "the ability of malicious code to execute with administrator privileges." When an administrator signs in, Windows creates two tokens: a standard-user token (with administrative privileges and SIDs removed) used for normal work, and a full administrator token used only after the user approves an elevation prompt (Microsoft Learn). Microsoft's recommended and more secure practice is to run as a standard user.
Attackers look for ways to get elevation without the prompt. ATT&CK calls this Bypass User Account Control: for example, certain built-in programs auto-elevate, and some can be made to launch other code with elevated rights. The community project UACME documents many such methods (T1548.002). MITRE's mitigations include removing local administrator membership from standard users, keeping Windows updated, and using the highest UAC setting.
5.2 Access tokens and sensitive privileges
Windows grants named privileges that are very powerful. The privilege list in Microsoft's logon event documentation includes SeDebugPrivilege (debug programs, including attaching to any process), SeImpersonatePrivilege (impersonate a client after authentication), SeLoadDriverPrivilege (load drivers into the kernel) and SeTakeOwnershipPrivilege (take ownership of any object) (Event 4672). Microsoft recommends that SeDebugPrivilege be granted "to Administrators, and only to Administrators."
Access Token Manipulation (T1134) is the technique of copying or forging tokens to run as a different, stronger security context. MITRE notes that stealing a token typically requires administrator access and commonly takes an attacker from administrator to SYSTEM, while some impersonation tokens can be created by standard users (T1134).
5.3 Services and file paths
Windows services often run as SYSTEM. Two classic weaknesses:
- Unquoted service paths. If a service's program path contains spaces and is not wrapped in quotes, Windows can mistake the first part of the path for the program. CWE gives the example that a call to
C:\Program Files\Foo\Barwithout quotes could end up running a file namedProgram.exeplaced inC:\(CWE-428). If an ordinary user can write to such a location, they run code as the service's account. - Weak permissions on service files or configuration, which let a normal user change what a SYSTEM service runs.
5.4 Vulnerable drivers
MITRE also notes that attackers may bring a signed but vulnerable driver onto a machine ("Bring Your Own Vulnerable Driver") so they can exploit it "to execute code in kernel mode" (T1068).
5.5 Checking your own Windows machine
On a machine you own, as an administrator:
whoami /priv # privileges in the current token
whoami /groups # group memberships
Get-CimInstance Win32_Service | Select-Object Name, StartMode, PathName
In the service listing, look for PathName values that contain spaces but are not wrapped in quotation marks, and for services you do not recognise.
6. Beyond the operating system
- Web applications. Missing server-side checks let a user reach another user's data (horizontal) or an admin function (vertical). Every such bug is an access control failure. PortSwigger's free access control labs are good practice.
- Cloud and identity. ATT&CK lists Temporary Elevated Cloud Access as part of abusing elevation controls, and Valid Accounts includes cloud accounts. Over-broad cloud roles and reused credentials give the same effect as a bad
sudorule. - Containers. Escape to Host is the container version: leaving the container's boundary to gain access to the machine it runs on.
- Valid Accounts. The simplest escalation needs no exploit: using legitimate credentials that happen to have higher rights. MITRE notes inactive accounts (for example of former employees) are attractive because the real owner will not notice misuse (T1078).
7. Defence
The principle behind everything below is the one in the NIST glossary for least privilege: a system should "restrict the access privileges of users (or processes acting on behalf of users) to the minimum necessary to accomplish assigned tasks." If every account and every program holds only the rights it needs, then a successful foothold gets the attacker little, and an escalation bug has less to give.
Prevent
| Area | What to do | Why |
|---|---|---|
| Least privilege | Give users, services and programs only the rights their job needs. Run services as dedicated low-privilege accounts. Raise privileges as late as possible and drop them afterwards (CWE-250) | Limits what a compromise yields |
| Patching | Apply operating system, kernel and software updates promptly | MITRE lists updating software first among its mitigations for exploitation (T1068). Dirty COW and PwnKit were both fixed by patches |
| Setuid and setgid | Keep the list short; avoid the bits on programs with shell-escape features | MITRE T1548.001 mitigation |
| sudo | Write narrow rules; avoid NOPASSWD where possible; consider timestamp_timeout of 0; restrict who can edit sudoers |
MITRE T1548.003 mitigations |
| Scheduled jobs and services | Make sure root- and SYSTEM-run files and folders are not writable by regular users | "Whoever can change what root runs controls root" |
| Windows administration | Remove local administrator rights from standard users; use standard accounts day to day and elevate only when needed; keep UAC at its highest level | MITRE T1548.002 and T1134 mitigations |
| Service paths | Quote service executable paths and lock down permissions | CWE-428 |
| Accounts | Use multi-factor authentication, disable unused accounts, use unique local administrator passwords, manage privileged accounts | Reduces Valid Accounts abuse (T1078) |
| Hardening | Mandatory access control (such as SELinux), exploit protection, application isolation, blocking known vulnerable drivers, Data Execution Prevention and ASLR | Makes exploitation harder or limits the damage |
Detect
The ATT&CK pages and Microsoft documentation suggest watching for:
- On Linux:
chmodoperations that set setuid or setgid bits followed by privileged process execution; changes to/etc/sudoers; commands running with an effective user ID of root from an unexpected user; newly created cron jobs or services. - On Windows: Event 4672, "special privileges assigned to new logon". Microsoft advises monitoring it where the account is not one of the expected built-in or administrative principals, and checking for privileges such as
SeDebugPrivilegethat should rarely be granted. Also new service or scheduled task creation, and unusual parent-child process relationships. - Everywhere: privilege changes on accounts, new administrators, and changes to central policy.
Remember the lesson from the false positives post: test these detections on purpose (for example in a purple team exercise) rather than assuming they would fire.
8. Common mistakes
| Myth | The facts |
|---|---|
| "Privilege escalation means breaking in" | It happens after a foothold. The first access can be a very ordinary account |
| "Only root or administrator matters" | Horizontal access to other users' data is also escalation, and Windows SYSTEM or service accounts can matter as much |
| "If the system is patched, it is safe" | Many escalations come from misconfiguration, not bugs |
| "Local bugs are low priority because attackers need to be on the machine first" | Being on the machine is exactly what a foothold gives them |
| "sudo itself is the problem" | Sudo is a good tool. The danger is broad or careless rules |
| "Least privilege is only for human users" | Services and programs need it too (CWE-250) |
| "A bypass of the prompt is a minor issue" | It removes the step designed to stop malicious code from running as administrator |
Closing
Privilege escalation is the step where a small foothold becomes a serious compromise. It is not one attack but a result, and it comes from only a few kinds of weakness: bugs in privileged software, loose configuration, weak or reused credentials, and programs and accounts that hold more power than they need.
Keep these points:
- Vertical means up a level; horizontal means sideways to someone else's data.
- Whoever can change what a privileged account runs controls that account.
- Least privilege and prompt patching are the two strongest defences.
- Configuration matters as much as code: sudo rules, setuid files, service paths and file permissions.
- Detect it deliberately: watch for new privileges, new administrators, and changes to sudo, services and scheduled tasks.
If you can look at a system and list who can change what root or SYSTEM runs, you are thinking about privilege escalation the way defenders and attackers both do.
Practise safely
Only practise on machines you own or on training platforms built for it. TryHackMe's Jr Penetration Tester path covers privilege escalation among its topics, and the GTFOBins and LOLBAS catalogues are useful references for how common Unix and Windows tools are misused.
Related: the Windows terms used here (access token, UAC, services, SYSTEM) are explained from scratch in Operating Systems and Windows Basics, and the idea being defended is least privilege from Security Design Principles.