Перейти к основному содержимому
Windows Privilege Escalation: Tokens, Services & Unquoted Paths
Урок 15 из 26

Windows Privilege Escalation: Tokens, Services & Unquoted Paths

Audit Windows access token privileges, service binary ACLs, unquoted service paths, and installer policies using native tools, and remediate local escalation paths cleanly.

Продвинутый 32 мин Пентест
Этого урока пока нет на выбранном языке — показана версия на другом языке. Перевод готовится.
Только в разрешённой среде — Описанные здесь приёмы применяются только в учебных лабораториях и в системах, которые принадлежат вам или на которые есть письменное разрешение.

Цели обучения

  • Inspect Windows access tokens and evaluate escalation risks tied to privileges such as SeImpersonatePrivilege and SeDebugPrivilege
  • Audit service configurations and filesystem ACLs with sc qc and icacls to identify weak service permissions and unquoted paths
  • Assess registry-based escalation vectors including AlwaysInstallElevated and writable service keys
  • Remediate local Windows privilege escalation flaws using strict ACLs, quoted paths, and least-privilege service accounts

Рекомендуется заранее: Windows Security Architecture, CLI, Registry & ServicesActive Directory Tiering, Group Policy & Delegation Security

#Why this matters

An initial foothold on a Windows workstation or application server rarely starts as NT AUTHORITY\SYSTEM. Instead, a tester or attacker usually lands inside a standard user shell or a restricted web/database service context. Local privilege escalation bridges that gap by turning a misconfigured service, loose folder permission, or over-privileged token into full local Administrator or SYSTEM control.

Because many third-party installers still ship weak directory ACLs or unquoted binary paths, defenders and system administrators need to know how to audit and harden Windows hosts before deployment.

#Access tokens, integrity levels, and risky privileges

Every Windows process runs under an access token created at logon. The token carries the user's Security Identifier (SID), group memberships, an Integrity Level (Low, Medium, High, or System), and a list of privileges. Under User Account Control (UAC), an administrator receives a split token: processes launch at Medium integrity by default and only elevate to High upon approval.

You can inspect your current token privileges with whoami /priv:

Checking token privileges in a lab service shell
$ whoami /priv

PRIVILEGES INFORMATION
----------------------

Privilege Name                Description                               State
============================= ========================================= ========
SeAssignPrimaryTokenPrivilege Replace a process level token             Disabled
SeAuditPrivilege              Generate security audits                  Disabled
SeChangeNotifyPrivilege       Bypass traverse checking                  Enabled
SeImpersonatePrivilege        Impersonate a client after authentication Enabled

A crucial rule in Windows is that Disabled in whoami /priv does not mean removed. Any privilege listed in the token can be enabled programmatically by the process; only privileges completely absent from the token are unavailable.

Token privilege Typical legitimate holder Escalation risk when held by untrusted code
SeImpersonatePrivilege IIS app pools, SQL/service accounts Process can impersonate a SYSTEM token if a privileged service connects to a controlled named pipe or COM endpoint
SeAssignPrimaryTokenPrivilege Service managers, logon daemons Allows launching a new process using an impersonated primary token
SeDebugPrivilege Administrators, system debuggers Allows opening and writing into memory of SYSTEM processes
SeBackupPrivilege / SeRestorePrivilege Backup agents Bypasses NTFS file ACLs to read or overwrite sensitive system files and registry hives

#Service misconfigurations: binary ACLs, service ACLs, and unquoted paths

Windows services typically run as LocalSystem (NT AUTHORITY\SYSTEM). Three distinct configuration flaws allow a standard user to hijack what a privileged service executes:

  1. Weak service binary or directory ACL: The service executable sits in a non-default folder (such as C:\Apps\LabAgent\agent.exe) where BUILTIN\Users or Authenticated Users has Modify (M), Write (W), or Full Control (F) permissions. Replacing or altering that binary executes arbitrary code when the service starts.
  2. Weak service object ACL: The Service Control Manager (SCM) grants a standard user SERVICE_CHANGE_CONFIG or WRITE_DAC, allowing them to modify the service's binPath with sc config or edit HKLM\SYSTEM\CurrentControlSet\Services\<Name>\ImagePath.
  3. Unquoted service path: When a service BINARY_PATH_NAME contains spaces without surrounding double quotes, Windows CreateProcess tries shorter prefix paths in order before reaching the real executable.
  1. Parse unquoted ImagePathC:\Program Files\Lab Vendor\App Service\agent.exe
  2. Probe prefix 1C:\Program.exe
  3. Probe prefix 2C:\Program Files\Lab.exe
  4. Probe prefix 3C:\Program Files\Lab Vendor\App.exe
  5. Launch real binaryC:\Program Files\Lab Vendor\App Service\agent.exe

Notice that an unquoted service path is only exploitable if two additional conditions hold: the user has write permission to one of the intermediate parent directories (such as C:\ or C:\Program Files\Lab Vendor), and the user can restart the service (or wait for a system reboot).

You can audit any service manually using sc qc and icacls:

Auditing a lab service path and directory permissions
$ sc qc LabBackup
[SC] QueryServiceConfig SUCCESS

SERVICE_NAME: LabBackup
        TYPE               : 10  WIN32_OWN_PROCESS
        START_TYPE         : 2   AUTO_START
        BINARY_PATH_NAME   : C:\Program Files\Lab Vendor\Backup Agent\agent.exe
        SERVICE_START_NAME : LocalSystem

$ icacls "C:\Program Files\Lab Vendor"
C:\Program Files\Lab Vendor BUILTIN\Users:(OI)(CI)(M)
                            NT AUTHORITY\SYSTEM:(OI)(CI)(F)
                            BUILTIN\Administrators:(OI)(CI)(F)

Here, BINARY_PATH_NAME lacks quotes and BUILTIN\Users has inherited Modify (OI)(CI)(M) permissions on C:\Program Files\Lab Vendor. Because Backup.exe is probed inside that folder before Backup Agent\agent.exe, a standard user could plant a binary at C:\Program Files\Lab Vendor\Backup.exe. In larger environments, automated audit scripts such as WinPEAS or PowerShell queries against Win32_Service surface these findings across dozens of services quickly.

#Registry and installer vectors

Two additional local vectors appear frequently in Windows hardening reviews:

  • AlwaysInstallElevated: If both HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer\AlwaysInstallElevated and HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer\AlwaysInstallElevated are set to 1, Windows Installer runs any .msi package launched by a standard user with SYSTEM privileges. Setting only one of the two keys has no effect; both must equal 1.
  • Scheduled tasks and writable PATH entries: Scheduled tasks configured to run as SYSTEM that invoke scripts in writable folders (such as C:\Scripts) or call binaries without absolute paths follow the same hijacking logic as services.

#Defending and common mistakes

Securing Windows hosts against local escalation relies on strict defaults:

  • Quote all service paths: Always wrap ImagePath values containing spaces in double quotes, including any arguments placed outside the quotes ("C:\Program Files\App\svc.exe" --config).
  • Protect application folders and SCM ACLs: Install software inside C:\Program Files with default inherited ACLs, and verify non-admin groups never hold Modify (M) or Write (W) on custom directories or service objects.
  • Keep service accounts minimal: Prefer Windows Virtual Accounts (NT SERVICE\<ServiceName>) or low-privilege accounts instead of LocalSystem whenever possible, and avoid granting SeImpersonatePrivilege unless required.
  • Disable AlwaysInstallElevated: Enforce AlwaysInstallElevated = 0 via GPO and monitor Event ID 7045 (new service installed) and 4697 to detect suspicious service creation or binary path changes.

Common mistakes include quoting an unquoted path while leaving BUILTIN\Users:(M) on the binary's own directory (the binary itself can still be overwritten), forgetting that Disabled privileges in whoami /priv can still be enabled by the process, and assuming HKLM AlwaysInstallElevated = 1 alone is inactive without checking HKCU as well.

#Summary

Local Windows privilege escalation commonly stems from token privileges like SeImpersonatePrivilege, modifiable service binaries or ACLs, unquoted service paths with writable parent folders, and AlwaysInstallElevated policies. Auditing hosts with whoami /priv, sc qc, icacls, and automated baseline tools reveals these weaknesses clearly. Quoting service paths, locking down directory and SCM ACLs, disabling AlwaysInstallElevated, and running services under minimal virtual accounts close these escalation routes.

Проверка знаний

Войдите, чтобы проходить тест, завершать уроки и сохранять прогресс. Войти в систему