Windows Privilege-Escalation Classes
On Windows, as on Linux, most local privilege escalation in real engagements comes from configuration, not from exploits: a service that runs as LocalSystem from a path an ordinary user can write to, a service whose permissions let users reconfigure it, an installer policy that elevates every package, a password left in a deployment file. This lesson describes the four classic classes as concepts, each with the evidence a tester collects by reading configuration, how a defender detects use of it, and the fix. A PowerShell audit runs on a synthetic export of a lab host's configuration; there is no exploitation and no tooling for it here. Windows internals (tokens, services, the Registry, UAC) are covered properly in Windows & Active Directory Security.
The four classes
| Class | The misconfiguration | Evidence (read-only) | Fix |
|---|---|---|---|
| Unquoted service path | a service's ImagePath contains spaces and no quotes, e.g. C:\Program Files\Lab Agent\bin\agent.exe. Windows tries C:\Program.exe, then C:\Program Files\Lab.exe, … in order |
the service's ImagePath, its account (LocalSystem?), and whether any of the candidate folders is writable by ordinary users |
quote the path in the service configuration; keep C:\ and Program Files writable only by administrators |
| Weak service permissions | the service's security descriptor lets Users or Authenticated Users change its configuration (SERVICE_CHANGE_CONFIG) or the service binary's file ACL lets them replace it |
the service SDDL (sc.exe sdshow <name>) and the binary's ACL (icacls) |
default service permissions; binaries writable only by administrators and TrustedInstaller |
| AlwaysInstallElevated | the policy "Always install with elevated privileges" is enabled in both HKLM and HKCU (…\Policies\Microsoft\Windows\Installer\AlwaysInstallElevated = 1): any user's .msi installs as SYSTEM |
the two registry values | disable the policy in both hives; deploy software through a management tool instead |
| Stored credentials | passwords in unattended-setup files (C:\Windows\Panther\Unattend.xml), old Group Policy Preferences files (cpassword, whose key Microsoft published; fixed by MS14-025 in 2014), scripts, saved credentials (cmdkey /list), application configuration |
the file's presence, location, ACL and the account named; not the password's use | remove the file, rotate the password, use gMSAs or a secrets manager; Windows LAPS for local administrator passwords |
A fifth group, token privileges, is worth naming: service accounts often hold SeImpersonatePrivilege (needed by IIS and SQL Server to act for clients). Several public techniques turn that privilege into SYSTEM on unpatched or default configurations. For the report, the finding is "a web application compromise would run with SeImpersonatePrivilege"; the fix is to run the application pool with a virtual account and keep hosts patched, and the detection is in the AD course.
An audit on a synthetic export
The audit reads objects of the kind Get-CimInstance Win32_Service, Get-Acl, sc.exe sdshow and Get-ItemProperty return, here saved from the lab host ws17.lab.test during an authorised internal test (lab data). The SDDL rights it looks for: DC is SERVICE_CHANGE_CONFIG, WP is SERVICE_STOP, RP SERVICE_START; trustees BU Builtin Users, AU Authenticated Users, WD Everyone.
# Synthetic export from ws17.lab.test (lab data): services, folder ACL summaries, two registry values, files found
$services = @(
[pscustomobject]@{ Name='LabAgent'; Account='LocalSystem'; Path='C:\Program Files\Lab Agent\bin\agent.exe -service'
Sddl='D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWLOCRRC;;;IU)' }
[pscustomobject]@{ Name='Spooler'; Account='LocalSystem'; Path='C:\Windows\System32\spoolsv.exe'
Sddl='D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWLOCRRC;;;IU)' }
[pscustomobject]@{ Name='LabUpdate'; Account='LocalSystem'; Path='"C:\Tools\Lab Update\update.exe"'
Sddl='D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCDCLCSWRPWPLOCRRC;;;AU)' }
[pscustomobject]@{ Name='PrintHelp'; Account='NT AUTHORITY\LocalService'; Path='C:\Lab Tools\Print Helper\ph.exe'
Sddl='D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)' }
)
$userWritable = @('C:\Lab Tools') # folders where BUILTIN\Users may create files (from Get-Acl)
$registry = @{ 'HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer\AlwaysInstallElevated' = 1
'HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer\AlwaysInstallElevated' = 1 }
$files = @('C:\Windows\Panther\Unattend.xml', 'C:\Users\Public\deploy\install.ps1')
function Get-Parent([string]$p) { $p.Substring(0, $p.LastIndexOf('\')) } # Windows-style parent folder
function Get-CandidatePaths([string]$path) {
# The executable part of an unquoted path, and every prefix Windows would try first.
$exe = ($path -split '\.exe', 2)[0] + '.exe'
$parts = $exe -split ' '
for ($i = 1; $i -lt $parts.Count; $i++) { ($parts[0..($i - 1)] -join ' ') + '.exe' }
}
$findings = foreach ($s in $services) {
if (-not $s.Path.StartsWith('"') -and (($s.Path -split '\.exe', 2)[0]) -match ' ') {
$writable = Get-CandidatePaths $s.Path | Where-Object { $userWritable -contains (Get-Parent $_) }
$sev = if ($writable -and $s.Account -eq 'LocalSystem') { 'HIGH' } elseif ($writable) { 'MEDIUM' } else { 'LOW' }
[pscustomobject]@{ Service=$s.Name; Class='unquoted path'; Severity=$sev
Detail = if ($writable) { "user-writable candidate: $($writable -join ', ')" } else { 'no candidate folder writable by users' } }
}
foreach ($ace in [regex]::Matches($s.Sddl, '\(A;;([A-Z]+);;;([A-Z]{2})\)')) {
$rights, $who = $ace.Groups[1].Value, $ace.Groups[2].Value
$pairs = for ($i = 0; $i -lt $rights.Length; $i += 2) { $rights.Substring($i, 2) }
if ($who -in 'BU', 'AU', 'WD' -and $pairs -contains 'DC') {
[pscustomobject]@{ Service=$s.Name; Class='weak service permissions'; Severity='HIGH'
Detail="$who has SERVICE_CHANGE_CONFIG (DC); service runs as $($s.Account)" }
}
}
}
$aie = $registry.Values | Where-Object { $_ -eq 1 }
if (@($aie).Count -eq 2) {
$findings += [pscustomobject]@{ Service='(policy)'; Class='AlwaysInstallElevated'; Severity='HIGH'; Detail='enabled in HKLM and HKCU' }
}
foreach ($f in $files) {
$findings += [pscustomobject]@{ Service='(file)'; Class='stored credentials?'; Severity='REVIEW'; Detail="$f present: check ACL and content with the client, rotate if it holds a password" }
}
$rank = @{ HIGH = 0; MEDIUM = 1; LOW = 2; REVIEW = 3 }
$findings | Sort-Object { $rank[$_.Severity] }, Service | Format-Table -AutoSize -Wrap | Out-String -Width 160
Service Class Severity Detail
------- ----- -------- ------
(policy) AlwaysInstallElevated HIGH enabled in HKLM and HKCU
LabUpdate weak service permissions HIGH AU has SERVICE_CHANGE_CONFIG (DC); service runs as LocalSystem
PrintHelp unquoted path MEDIUM user-writable candidate: C:\Lab Tools\Print.exe
LabAgent unquoted path LOW no candidate folder writable by users
(file) stored credentials? REVIEW C:\Windows\Panther\Unattend.xml present: check ACL and content with the client, rotate if it holds a password
(file) stored credentials? REVIEW C:\Users\Public\deploy\install.ps1 present: check ACL and content with the client, rotate if it holds a password
Reading the results:
- AlwaysInstallElevated is on in both hives: any user can install a package as SYSTEM. High, and trivially fixed by Group Policy.
- LabUpdate grants Authenticated Users
SERVICE_CHANGE_CONFIGon a SYSTEM service: any domain user logged on tows17could point the service at another program. High. The SDDL string is the evidence. - PrintHelp's unquoted path has a candidate
C:\Lab Tools\Print.exein a folder users can write to, but the service runs asLocalService, a low-privileged account: Medium. - LabAgent's path is unquoted, but no candidate folder is writable by users, so it is not exploitable as configured: Low, fix it anyway, because one folder permission change would make it High.
- The two files are leads, not findings yet. With the client's administrator, check whether they contain credentials (an unattended-setup file often holds the local administrator's password) and who can read them. If they do, the finding is the exposed credential, and the fix includes rotating it.
The severity logic matters as much as the detection. An unquoted path on its own is a hygiene issue; it becomes an escalation only with a writable candidate folder and a privileged service account.
How use of these classes is detected
| Class | Signals |
|---|---|
| Unquoted path, writable binary | a new executable appearing in C:\, C:\Program Files or a service folder (Sysmon event 11, file create); a service starting an unexpected image (Sysmon 1 with parent services.exe) |
| Weak service permissions | Registry changes to HKLM\SYSTEM\CurrentControlSet\Services\<name>\ImagePath (Sysmon 13); sc.exe config in process command lines (4688 with command-line logging); events 4697 / 7045 (service installed) fire only for new services, not for a changed ImagePath |
| AlwaysInstallElevated | msiexec.exe started by a non-administrator and running children as SYSTEM; MsiInstaller events 1033/11707 for unexpected packages |
| Stored credentials | logons with the exposed account from unusual hosts (4624, 4648); access to Unattend.xml (object-access auditing, 4663) |
How they are fixed and kept fixed
Quote every service path and audit services with spaces in their paths after each software installation; reset service security descriptors to defaults (sc.exe sdset with the vendor's SDDL) and keep service folders writable only by administrators; disable AlwaysInstallElevated in both hives through Group Policy; delete unattended-setup files after deployment and never put passwords in scripts or Group Policy Preferences; use Windows LAPS so every machine's local administrator password is unique and rotated. The CIS Benchmarks and Microsoft's security baselines contain the policy settings; a scheduled audit like the one above catches drift.
Pitfalls
- Rating every unquoted path High. Without a writable candidate folder it is not exploitable.
- Opening credential files to "prove" them. Agree with the client how to check; the presence, location and ACL are the first evidence.
- Forgetting the service account. A writable path for a service that runs as
LocalServiceis less severe than the same forLocalSystem. - Testing on shared workstations. Changing service configuration or installing packages to demonstrate a class affects real users. The configuration is the proof.
Practice
- Change the LabAgent folder
C:\Program Files\Lab Agentto be writable by users (add it to$userWritable). What does the audit report now, and why? - Decode
(A;;CCDCLCSWRPWPLOCRRC;;;AU): which rights does it give, and which one is the problem?
Answers
- Nothing changes. The candidates Windows tries are
C:\Program.exeandC:\Program Files\Lab.exe, in the foldersC:andC:\Program Files; the agent's own folder holds none of them. MakingC:\Program Filesuser-writable (add it to$userWritable) would turn LabAgent HIGH. A user-writable application folder is still a finding of its own: the real binary could be replaced. CCquery config,DCchange config,LCquery status,SWenumerate dependents,RPstart,WPstop,LOinterrogate,CRuser-defined control,RCread control, for Authenticated Users.DC(SERVICE_CHANGE_CONFIG) is the problem: it allows changing the binary path and the account of a SYSTEM service.
Test yourself
When does an unquoted service path allow privilege escalation?
- Always
- When a candidate path's folder is writable by ordinary users and the service runs with higher privileges
- Only on Windows XP
- When the path is longer than 260 characters
In a service SDDL, which right lets a user change the service's binary path?
- RP
- WP
- DC (SERVICE_CHANGE_CONFIG)
- LC
AlwaysInstallElevated is dangerous only when enabled in which hives?
- HKLM only
- HKCU only
- Both HKLM and HKCU
- Neither
A tester finds C:\Windows\Panther\Unattend.xml. What is the correct next step?
- Use the password inside to log in as administrator
- Record its presence and ACL, and check its contents with the client; if it holds a password, report it and recommend rotation
- Delete it
- Ignore it