Chapter 59

Registry as Attack Surface

Every persistence autorun location, how each works mechanically, the detection event it triggers, and the Sigma rules that catch it.

Scenario

An incident responder runs Autoruns on a compromised endpoint and finds five suspicious entries — but only if they knew where to look. An attacker who knows registry persistence locations better than the defender can hide in plain sight: a value in a rarely-checked key, a COM object hijack under HKCU, an IFEO debugger entry. This chapter is the complete map. After reading it, you should be able to name at least 10 autorun locations from memory — because interviewers will ask exactly that.

Run Keys — The Classic

The most common persistence mechanism. Values under these keys are executed at user logon or system startup.

Registry PathWho Runs ItTimingHKLM requires admin?
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunAll users at logonLogonYes
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceAll users — runs once then deletedLogonYes
HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\RunCurrent user onlyLogonNo — user level
HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceCurrent user — once then deletedLogonNo
HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run32-bit processes on 64-bit WindowsLogonYes

Detection: Sysmon Event 13 (RegistryValueSet) with TargetObject containing \CurrentVersion\Run. Filter out known software installers. Autoruns.exe from Sysinternals highlights unsigned or unknown-hash entries in green/red/yellow.

Winlogon Keys

Winlogon handles the logon sequence. Its registry entries control what programs run as part of logon initialization — any modification is high-value persistence.

ValueDefaultAbuse Method
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\UserinitC:\Windows\system32\userinit.exe,Append malware path after the comma: userinit.exe, malware.exe
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\Shellexplorer.exeReplace with or append malware.exe (runs instead of Explorer)
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\Notify(subkeys for notification DLLs)Add subkey pointing to malicious DLL (older technique)

Services Registry Keys

Every Windows service is defined under HKLM\SYSTEM\CurrentControlSet\Services\<ServiceName>. Key values:

ValueDescriptionMalware Use
ImagePath (REG_EXPAND_SZ)Path to service binary or %SystemRoot%\svchost.exe -k groupnamePoint to malicious .exe or inject via svchost (ServiceDll)
ServiceDll (under Parameters\)For svchost services: actual DLL containing service logicMalicious DLL in system32 or temp, loads inside svchost.exe
Start (REG_DWORD)0=Boot, 1=System, 2=Automatic, 3=Manual, 4=DisabledSet to 2 for autostart
Type (REG_DWORD)1=Kernel, 2=FileSys, 16=Win32Own, 32=Win32ShareUsually 16 for standalone malware service

Detection: Event 7045 (System channel, new service installed) and Event 4697 (Security channel). Alert on ServiceFileName pointing to unusual paths (not System32, not Program Files).

AppInit_DLLs

HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows\AppInit_DLLs — DLLs listed here are loaded into every process that loads User32.dll (essentially every GUI process). Disabled by default when Secure Boot is enabled.

Mental model

AppInit_DLLs is a blunt instrument — it injects your DLL into hundreds of processes. Legitimate software rarely uses it. Any non-empty value is suspicious on a modern system with Secure Boot. The value is LoadAppInit_DLLs = 1 alongside the DLL path. Detection: Sysmon Event 13 on this key path.

Image File Execution Options (IFEO)

IFEO, at HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\<binary.exe>, was designed for attaching a debugger to a process at launch. Attackers abuse the Debugger value to hijack program execution.


  IFEO Debugger Abuse
  ══════════════════════════════════════════════════════════════════

  Registry entry:
  HKLM\...\Image File Execution Options\sethc.exe
    Debugger = "C:\Windows\System32\cmd.exe"

  What happens:
  User presses Shift 5 times → Windows tries to launch sethc.exe
                                           │
                                           ▼
                             Windows checks IFEO for sethc.exe
                             Finds Debugger = cmd.exe
                                           │
                                           ▼
                             Executes: cmd.exe sethc.exe
                             → cmd.exe opens as SYSTEM
                               (running before logon, at lock screen)

  Real-world abuse:
  - sethc.exe  → Sticky Keys (triggered at lock screen with Shift×5)
  - osk.exe    → On-Screen Keyboard
  - utilman.exe → Ease of Access (Win+U at lock screen)
  - narrator.exe → Narrator
  All run as SYSTEM before authentication — perfect backdoor

    

SilentProcessExit

A variation under HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SilentProcessExit\<binary.exe> — triggers a monitor process when the named binary exits. Abuse: set a malicious monitor that relaunches on process exit.

COM Hijacking via HKCU

Windows resolves COM objects first from HKCU\Software\Classes\CLSID, then HKLM\Software\Classes\CLSID. A user (no admin required) can create a HKCU entry that shadows a system COM object.


  COM Object Hijacking — Registry Precedence
  ══════════════════════════════════════════════════════════════════

  Application calls CoCreateInstance(CLSID_TaskScheduler, ...)
                             │
                             ▼
           Windows looks up CLSID in registry:
           ┌─────────────────────────────────────────────────────┐
           │  1st: HKCU\Software\Classes\CLSID\{CLSID}           │ ← ATTACKER PLANTS HERE
           │       InProcServer32 = C:\Users\victim\AppData\      │
           │       Roaming\malware.dll                            │
           └─────────────────────────────────────────────────────┘
                             │ (if not found ↓)
           ┌─────────────────────────────────────────────────────┐
           │  2nd: HKLM\Software\Classes\CLSID\{CLSID}           │
           │       InProcServer32 = C:\Windows\System32\          │
           │       taskschd.dll (legitimate)                      │
           └─────────────────────────────────────────────────────┘

  Result: malware.dll loaded instead of taskschd.dll
  Persistence trigger: any application that uses the COM object
  Admin required: NO — HKCU is user-writable

    

Detection: Sysmon Event 12/13 for HKCU\Software\Classes\CLSID key creation, especially with InProcServer32 pointing to non-system paths. Sysmon Event 7 (ImageLoad) showing a DLL from %APPDATA% or %TEMP% loaded by a legitimate process.

BootExecute

HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\BootExecute — programs listed here run during early boot before the Session Manager fully initializes. Default: autocheck autochk *. Any additional entries run with highest possible privilege and before most security software starts.

LSA Authentication Packages and Security Packages

Two registry keys tell the LSA (Local Security Authority) which DLLs to load as authentication providers:

KeyValueDefaultAbuse
HKLM\SYSTEM\CurrentControlSet\Control\LsaAuthentication Packages (REG_MULTI_SZ)msv1_0Add malicious DLL; loaded by lsass.exe at boot with SYSTEM rights
HKLM\SYSTEM\CurrentControlSet\Control\LsaSecurity Packages (REG_MULTI_SZ)kerberos, msapsspc, schannel…Add malicious SSP DLL; loaded by lsass.exe, sees all credentials
HKLM\SYSTEM\CurrentControlSet\Control\SecurityProvidersSecurityProviders (REG_SZ)credssp.dllAppend malicious DLL path (space-separated)
Common mistake

LSA package persistence requires a reboot to activate (lsass.exe loads them at boot). Detection note: Sysmon Event 13 on these key paths, plus Event 7 showing unexpected DLLs loaded by lsass.exe after reboot. The Mimikatz misc::memssp technique installs an in-memory SSP without touching the registry — completely bypasses this detection angle.

Complete Autorun Locations Table

LocationTriggerAdmin?Detection Event
HKLM\...\RunSystem startup / all user logonYesSysmon 13, Event 4657
HKCU\...\RunUser logonNoSysmon 13
Winlogon\UserinitUser logonYesSysmon 13
Winlogon\ShellUser logonYesSysmon 13
Services\ImagePathService start (boot/auto)YesEvent 7045, 4697, Sysmon 13
Services\Parameters\ServiceDllsvchost service startYesEvent 7045, Sysmon 13, Event 7
AppInit_DLLsEvery User32 loadYesSysmon 13, Event 7
IFEO\<binary>\DebuggerSpecified binary launchYesSysmon 13, Event 4688
SilentProcessExit\<binary>Specified binary exitYesSysmon 13
HKCU\Software\Classes\CLSID\<CLSID>\InProcServer32COM object instantiationNoSysmon 12/13, Sysmon 7
BootExecuteEarly boot (before logon)YesSysmon 13 (offline parse)
Lsa\Authentication Packageslsass.exe boot loadYesSysmon 13, Event 7 in lsass
Lsa\Security Packageslsass.exe boot loadYesSysmon 13, Event 7 in lsass
Scheduled Tasks (TaskCache)Configured triggerVariesEvent 4698, 4702, Sysmon 13
Startup folder (per-user and all-users)User logonVariesSysmon 11 (file creation), Event 4688
HKCU\Environment\UserInitMprLogonScriptUser logon (logon script)NoSysmon 13
COM\InprocServer32 (HKLM)COM instantiationYesSysmon 13, Event 7
KnownDLLsDLL load from HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\KnownDLLsYesSysmon 13, 7

The Autoruns Tool

Sysinternals Autoruns (free from Microsoft) checks all autorun locations and color-codes entries:

Command-line: autorunsc.exe -a * -c -h -s * > autoruns.csv — scan all categories, CSV output, include hash, scan all users. Great for baseline comparison: diff baseline.csv current.csv.

Try this

Run Autoruns on a clean VM, export to CSV (File → Save). Then install a suspicious program or add a test Run key. Run again, compare. This is the workflow for detecting persistence changes between snapshots — critical for incident response when you have a pre-compromise baseline.

Q & A

Q: Name 5 Windows registry persistence locations from memory.

Interviewer-expected answer (any 5): (1) HKCU\Software\Microsoft\Windows\CurrentVersion\Run — user-level, no admin needed; (2) HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run — system-wide, needs admin; (3) HKLM\SYSTEM\CurrentControlSet\Services — service-based persistence; (4) HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\<binary>\Debugger — IFEO hijack; (5) HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\Userinit — Winlogon persistence; (6) HKCU\Software\Classes\CLSID\{CLSID}\InProcServer32 — COM hijack, no admin; (7) HKLM\SYSTEM\CurrentControlSet\Control\Lsa\Authentication Packages — LSA auth package persistence; (8) HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\BootExecute — pre-boot execution.

Q: An attacker wants to persist without admin privileges. Which registry locations are available to them?

User-writable locations (HKCU only): (1) HKCU\...\Run and RunOnce — classic; (2) HKCU\Software\Classes\CLSID — COM hijacking, no admin, highly effective; (3) HKCU\Environment\UserInitMprLogonScript — runs at logon; (4) HKCU startup folder: %APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup — not registry but user-writable; (5) Scheduled tasks as current user — ITaskService allows creating tasks that run as current user. Notably missing from this list: services (require admin), HKLM Run (requires admin), AppInit_DLLs (requires admin and Secure Boot must be off). COM hijacking (option 2) is particularly dangerous because it triggers on legitimate application use and requires zero admin.

Q: How would you write a Sigma rule to detect Run key persistence?

Target Sysmon Event 13 (RegistryValueSet). TargetObject should match *\SOFTWARE\Microsoft\Windows\CurrentVersion\Run*. Exclude known-good: filter by image (trusted software installers) or by known-good value names (antivirus, update agents). Example Sigma: detection: selection: EventID: 13, TargetObject|contains: '\CurrentVersion\Run' filter_legit: Image|startswith: 'C:\Program Files\'. condition: selection and not filter_legit. Add a second filter layer based on the Details field — known-good paths like C:\Windows\system32, C:\Program Files, %SystemRoot% reduce false positives. Alert on Details pointing to %TEMP%, %APPDATA%, or %PUBLIC%.