Skip to content
Tutorials Center
My learning

Topics

Lesson 27 of 38 ยท Post-exploitation and Privilege Escalation

Windows Privilege Escalation Review

Review how Windows privilege escalation paths arise from services, tokens, installers and permissions, and learn to audit for them and fix them with least privilege.

On Windows, the highest local account is NT AUTHORITY\SYSTEM, and administrators can reach it. A tester who starts as a standard user, or as a service account after a web flaw, looks for ways the configuration lets that account become an administrator, and for ways an administrator becomes a domain administrator (see lateral movement).

As with Linux, most paths are configuration and design mistakes rather than exotic exploits. The usual themes are services, tokens and privileges, installers, scheduled tasks, stored credentials and old patch levels. This lesson explains each, shows the commands defenders use to audit them on their own machines, and builds stand-in checkers that parse sample output.

Who am I and what can I do?

Windows tracks rights in a security token attached to each process. The token lists the user, groups and a set of privileges such as SeBackupPrivilege or SeImpersonatePrivilege. Basic awareness commands are read-only:

TEXT
whoami /all           user, groups, integrity level and privileges
systeminfo            OS version, patches (hotfixes), domain membership
net user              local accounts
net localgroup administrators
sc query              services and their state
schtasks /query       scheduled tasks

Interpreting the output is the skill. For example, a High integrity level means an elevated token; a service account holding SeImpersonatePrivilege is a known risk (many "potato"-family techniques rely on it), which is why web servers and database engines should not run as accounts with extra rights.

Common weakness categories

Category What goes wrong Fix
Unquoted service path A service path with spaces and no quotes lets a lower user place a file earlier in the path search Quote the path; lock down folder permissions
Weak service permissions A normal user can change a service's binary or configuration Remove write access; run service as a least-privilege account
Dangerous token privileges Service accounts hold SeImpersonate, SeDebug, SeBackup, SeLoadDriver Use managed service accounts with only the rights needed
AlwaysInstallElevated Installer packages run as SYSTEM for any user Disable both policy keys
Scheduled tasks and writable scripts A SYSTEM task runs a file anyone can change Fix ACLs; sign scripts
Stored credentials Passwords in scripts, unattend files, browser stores, registry autologon Remove; use a vault; rotate
UAC bypass and weak UAC Elevation prompts disabled or bypassable Keep UAC at default or higher; use standard accounts
Missing patches Known local vulnerabilities Patch cadence and reporting
DLL search order hijacking Applications load a DLL from a writable folder Use absolute paths and safe DLL search settings

Unquoted service paths

If a service's ImagePath is C:\Program Files\Acme Tools\agent.exe without quotes, Windows tries C:\Program.exe, then C:\Program Files\Acme.exe, and only then the real file. If a low-privilege user can create one of the earlier files, the service starts their file as SYSTEM when it restarts. The risk needs both an unquoted path and a writable location, so an audit checks both.

Python Find unquoted service paths

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.

The output lists the file names Windows could try before reaching the real program. Defensively you check whether a standard user can write to any of those folders (icacls C:\ and icacls "C:\Program Files"). Normal installs deny it, so unquoted paths in protected folders are low risk, but custom software installed at C:\ often is exploitable.

Token privileges

Dangerous privileges deserve review wherever they appear. The stand-in below takes sample whoami /priv style output and rates each privilege.

Python Rate token privileges

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.

Disabled in the listing means the privilege is held but not active; a process that holds it can usually enable it. So what matters is whether the account holds the privilege at all, not just whether it shows as enabled.

AlwaysInstallElevated and registry checks

Two registry values (HKLM and HKCU, key Software\Policies\Microsoft\Windows\Installer, value AlwaysInstallElevated) make Windows Installer packages run with SYSTEM rights. If both are set to 1, any user can install a package as SYSTEM. Auditors check both keys; the fix is to delete the values or set them to 0 via Group Policy.

TEXT
reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated
reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated

Credentials Windows keeps around

  • Autologon passwords in the registry, and credentials in unattended-install files (unattend.xml, sysprep).
  • Saved credentials (cmdkey /list), browser stores, and scripts with embedded passwords.
  • LSASS memory and the SAM/SYSTEM registry hives, which hold hashes; protecting them is a job for Credential Guard, LSA protection and removing local admin rights.

Test only what the scope allows. Extracting hashes from a host you do not control, or from a machine outside scope, can be a serious legal problem.

Remediation checklist

  • Least privilege: standard user accounts for daily work, separate admin accounts, no shared local admin passwords (use LAPS or Windows LAPS to randomize them).
  • Quote service paths, review service and folder ACLs, and run services as managed service accounts.
  • Disable AlwaysInstallElevated; keep UAC enabled.
  • Patch on a schedule and verify with an inventory.
  • Turn on Credential Guard, LSA protection, attack surface reduction rules and an EDR product.
  • Monitor Windows event logs for service creation (event 7045), new local admins and unusual token use.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why is an unquoted service path with spaces a risk?

    Windows tries shorter names first. If a lower user can write there, the service may run their file with its own account rights.
  2. 2. A web server account holds SeImpersonatePrivilege. What is the right recommendation?

    Service accounts should hold only what they need; impersonation rights are a well-known escalation helper.
  3. 3. When is AlwaysInstallElevated exploitable?

    Both policy keys must be enabled for installer packages to run as SYSTEM for ordinary users.
  4. 4. Which control helps prevent shared local administrator passwords from enabling lateral movement?

    Unique, rotated local admin passwords stop one stolen credential from working everywhere.

Summary

  • Windows privilege escalation comes from services, token privileges, installer policies, tasks, stored credentials and patching gaps.
  • Read tokens and privileges with whoami /all; a disabled privilege that is held can usually be enabled.
  • Unquoted service paths need both a gap in quoting and writable folders to matter.
  • Fix with least privilege, LAPS, managed service accounts, quoting, patching and credential protection.
  • Only inspect credentials and hashes on hosts the scope explicitly allows.

Next: Lateral movement and Active Directory