Windows Privilege Escalation
Escalating from an unprivileged user to SYSTEM (or local Administrator) is the bridge between “I have a shell” and “I control the machine.” On Windows, a kernel exploit is rarely needed: the norm is abusing weak configurations —service permissions, poorly defined paths, token privileges, scheduled tasks— that administration itself left exploitable. The kernel is the last resort, not the first. The broken invariant: the system trusts paths, permissions and privileges that someone misconfigured, and the attacker uses its own rules against it.
flowchart TD
W["whoami /priv"] -->|SeImpersonate| P["Potato → SYSTEM"]
W -->|SeBackup/SeDebug| C["dump SAM/LSASS"]
S["services/tasks"] -->|weak binPath or DLL| SYS["execution as SYSTEM"]
A["AlwaysInstallElevated"] -->|.msi| SYS
K["kernel (last resort)"] -.-> SYS
Threat model
Section titled “Threat model”- Who attacks: someone with a low-privilege shell on the host (a service account, a normal user) who wants to reach SYSTEM or local Administrator.
- What it breaks: misplaced trust in configuration. A service running as SYSTEM but whose binary is modifiable by a normal user is, in effect, SYSTEM for that user.
- What it gains: full host control: SAM/LSASS dumping, persistence, disabling defenses and —on a domain host— jumping to domain credentials.
- Why it’s almost never kernel: kernel exploits are noisy and can take down the host; escalation is almost always finding the weak-configuration link.
Anatomy
Section titled “Anatomy”The vectors, from most to least common
Section titled “The vectors, from most to least common”- Token privileges (
whoami /priv): the most reliable quick win. - Misconfigured services: reconfigurable
binPath, unquoted paths, weak permissions, DLL hijacking. - Scheduled tasks and autoruns that run elevated invoking something modifiable.
- AlwaysInstallElevated: any
.msiinstalls as SYSTEM. - Credentials and secrets reusable toward an admin account.
- Kernel exploits: last resort.
Variants
Section titled “Variants”1. Token privileges
Section titled “1. Token privileges”If the user (typical in IIS/MSSQL service accounts) has SeImpersonatePrivilege, the Potato family
forces a privileged service to authenticate to you and impersonates its SYSTEM token (full detail in
tokens):
PrintSpoofer.exe -i -c cmd # SeImpersonate -> SYSTEMGodPotato.exe -cmd "cmd /c whoami" # Win8-11 / Server 2012-2022Other direct privileges: SeBackup (read SAM/NTDS.dit), SeRestore/SeTakeOwnership (take over
files/services), SeDebug (dump LSASS), SeLoadDriver (BYOVD).
2. Misconfigured services
Section titled “2. Misconfigured services”accesschk.exe -uwcqv "Users" * # Sysinternals: writable permissionssc qc <service> # view binPath and accountsc config <service> binPath= "C:\tmp\evil.exe" # if you can reconfiguresc stop <service> & sc start <service>- Weak service permissions: reconfigure
binPath→ execution as the service’s account. - Unquoted service path: a path with spaces without quotes (
C:\Program Files\...) → dropC:\Program.exe. - Weak binary/folder perms: replace the service’s executable.
- DLL hijacking: the service loads a DLL from a writable path.
3. Scheduled tasks and autoruns
Section titled “3. Scheduled tasks and autoruns”schtasks /query /fo LIST /vreg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run"Tasks that run as SYSTEM invoking modifiable scripts/binaries; writable startup entries (Run keys, Startup folder).
4. AlwaysInstallElevated
Section titled “4. AlwaysInstallElevated”If both keys are 1, any .msi installs as SYSTEM:
reg query HKCU\Software\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevatedreg query HKLM\Software\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevatedmsiexec /quiet /qn /i evil.msi5. Credentials and secrets
Section titled “5. Credentials and secrets”GPP cpassword, unattend.xml, autologon in the registry, cmdkey, DPAPI, in-memory credentials →
reuse toward an admin account (see credential dumping).
6. Kernel exploits (last resort)
Section titled “6. Kernel exploits (last resort)”Map systeminfo + hotfixes with wesng/Watson → PrintNightmare, CVE-2021-1732, etc. Noisy and can take
down the host; use it when everything else fails.
Red Team
Section titled “Red Team”Investigator workflow
Section titled “Investigator workflow”whoami /priv: SeImpersonate/Backup/Restore/Debug/LoadDriver? → to tokens.- accesschk/winPEAS over services: reconfigurable binPath, unquoted path, hijackable DLL?
- Tasks and Run keys modifiable that run elevated.
- AlwaysInstallElevated in HKCU and HKLM.
- Credentials reusable toward admin.
- Only if nothing works: kernel, mapping build+hotfixes.
- winPEAS / PowerUp (
Invoke-AllChecks) / Seatbelt / SharpUp: automatic detection of all vectors. - accesschk.exe (Sysinternals): service, file and registry permissions.
- PrintSpoofer / GodPotato / SigmaPotato: SeImpersonate exploitation.
- wesng / Watson: mapping patches to kernel exploits.
Impact and chaining
Section titled “Impact and chaining”From user to local SYSTEM: SAM/LSASS dumping, persistence, disabling defenses and —on a domain host— jumping to domain credentials and pivoting.
Blue Team
Section titled “Blue Team”Detection
Section titled “Detection”- Service reconfiguration (
sc config, events 7040/4697), creation of new services (7045). - Potato/PrintSpoofer execution (anomalous named pipes,
spoolsv/rpcss→ SYSTEM shell). msiexeclaunching installers from user paths; accesschk/winPEAS.- Scheduled task creation/modification (4698/4702).
Telemetry and sources
Section titled “Telemetry and sources”- Sysmon (1/7/11/13), service and task creation auditing, Script Block Logging.
- LSASS access alerts (Sysmon event 10 toward
lsass.exe).
Hardening
Section titled “Hardening”- Correct permissions on services, binaries and folders; quotes on all service paths.
- Disable AlwaysInstallElevated; review Run keys and tasks.
- Remove dangerous privileges from service accounts; use gMSA.
- LAPS for the local admin; patch up to date (closes kernel exploits).
- EDR with LSASS-access blocking and, against BYOVD, Microsoft’s vulnerable driver blocklist (default on Windows 11 2022+) with HVCI.
Response
Section titled “Response”Rebuild the host if it reached SYSTEM, rotate all local secrets and credentials of accounts that logged in, and close the specific vector (permission/service/task).
CVEs and real cases
Section titled “CVEs and real cases”- PrintNightmare (CVE-2021-34527 / CVE-2021-1675): RCE/LPE via the spooler, mass exploitation.
- HiveNightmare/SeriousSAM (CVE-2021-36934): lax ACLs on SAM/SYSTEM allow reading hashes as a user.
- CVE-2021-1732, CVE-2022-21882: win32k LPE used in real attacks.
- The Potato family (SeImpersonate) is a standard TTP against IIS/MSSQL service accounts (MITRE T1134).
Test checklist
Section titled “Test checklist”-
whoami /priv— SeImpersonate/Backup/Restore/Debug/LoadDriver? - Services with weak permissions or reconfigurable
binPath(accesschk). - Unquoted service paths with a writable folder.
- DLL hijacking in privileged services/apps.
- Modifiable scheduled tasks and Run keys that run elevated.
- AlwaysInstallElevated = 1 in HKCU and HKLM.
- Credentials in configs/registry reusable toward admin.
- Unpatched build mappable to a kernel exploit (only if everything else fails).