Chapter 66

COM Hijacking

HKCU override technique, identifying hijackable CLSIDs with ProcMon, user-privilege persistence, UAC bypass variants, and Sigma rules for COM hijack detection.

Scenario

A threat hunt surfaces an unusual DLL in %APPDATA%\Microsoft\ named mlang.dll. No legitimate MLANG.DLL belongs there. Registry check: HKCU\Software\Classes\CLSID\{C90250F3-4D7D-4991-9B69-A5C5BC1C2AE6}\InprocServer32 points to that AppData path. The system MLANG CLSID is registered in HKLM — but HKCU wins. Every time a process loads this CLSID, the malicious DLL runs. This is COM hijacking — no admin rights required, survives reboots, and the vector is a user-writable registry key.

Hijack Mechanism


  COM Hijacking via HKCU Override
  ══════════════════════════════════════════════════════════════════

  Normal COM resolution:
  CoCreateInstance({A-B-C-D}) → checks HKCU first → not found
                              → checks HKCR (HKLM) → found
                              → loads C:\Windows\System32\legit.dll

  After hijack (no admin required):
  HKCU\Software\Classes\CLSID\{A-B-C-D}\InprocServer32
       = C:\Users\victim\AppData\Roaming\malicious.dll

  CoCreateInstance({A-B-C-D}) → checks HKCU first → FOUND
                              → loads malicious.dll into caller's process
                              → legit.dll from HKLM is NEVER consulted

  Persistence: registry key survives reboots
  Privilege: no admin needed, runs as current user
  Trigger: any process that calls CoCreateInstance for this CLSID

    

Finding Hijackable CLSIDs

A CLSID is hijackable if:

  1. Registered in HKLM (exists legitimately in HKCR)
  2. NOT already overridden in HKCU for this user
  3. Called by a process the attacker controls or can trigger

Standard method: run Process Monitor (procmon) with a filter for RegOpenKey Result: NAME NOT FOUND on paths containing HKCU\Software\Classes\CLSID. These are COM lookups that fall through to HKLM — prime hijack targets.

PowerShellfind_hijackable_clsids.ps1
# Find CLSIDs in HKLM that are NOT overridden in HKCU
$hklm_clsids = Get-ChildItem "HKLM:\SOFTWARE\Classes\CLSID" -ErrorAction SilentlyContinue |
    Select-Object -ExpandProperty PSChildName

$hkcu_clsids = Get-ChildItem "HKCU:\Software\Classes\CLSID" -ErrorAction SilentlyContinue |
    Select-Object -ExpandProperty PSChildName

$candidates = $hklm_clsids | Where-Object { $_ -notin $hkcu_clsids }

# Filter for InprocServer32 (DLL-based, more stealthy than LocalServer32)
foreach ($clsid in $candidates) {
    $key = "HKLM:\SOFTWARE\Classes\CLSID\$clsid\InprocServer32"
    if (Test-Path $key) {
        $dll = (Get-ItemProperty $key -ErrorAction SilentlyContinue).'(default)'
        Write-Output "$clsid → $dll"
    }
}

COM Hijacking for UAC Bypass

Some auto-elevated processes (those that run elevated without a UAC prompt, such as eventvwr.exe) load COM objects. If an attacker hijacks a CLSID loaded by an auto-elevated process, the hijacked DLL runs elevated — without triggering a UAC dialog.

Classic example: eventvwr.exe auto-elevates and looks up a CLSID in HKCU. Attacker plants malicious DLL at HKCU CLSID path → eventvwr.exe loads it → elevated shell.

Detection: process spawned from eventvwr.exe that is not Event Viewer UI. Event 4688 with ParentCommandLine eventvwr.exe and unusual child.

Detection Rules

YAMLcom_hijack_registry.yml
title: COM Object Hijack via HKCU InprocServer32
status: experimental
logsource:
    product: windows
    category: registry_set
    definition: 'Sysmon Event ID 13 (RegistryValueSet)'
detection:
    selection:
        TargetObject|contains: '\Software\Classes\CLSID\'
        TargetObject|endswith: '\InprocServer32\(Default)'
    filter_legit:
        # Legitimate installers write to HKCU CLSID during install
        Image|startswith:
            - 'C:\Windows\System32\msiexec.exe'
            - 'C:\Windows\SysWOW64\msiexec.exe'
    condition: selection and not filter_legit
falsepositives:
    - Software installation writing COM objects per-user
level: medium
tags:
    - attack.persistence
    - attack.t1546.015
YAMLcom_dll_suspicious_path.yml
title: COM InprocServer32 DLL in Suspicious Path
status: stable
logsource:
    product: windows
    category: registry_set
detection:
    selection:
        TargetObject|contains: '\InprocServer32'
        Details|contains:
            - '\AppData\Roaming\'
            - '\AppData\Local\Temp\'
            - '\Users\Public\'
            - '\ProgramData\'
    condition: selection
level: high

Well-Known Hijackable CLSIDs

CLSIDLegitimate DLLLoaded by
{BCDE0395-E52F-467C-8E3D-C4579291692E}MMDevAPI.dllVarious audio apps
{B196B286-BAB4-101A-B69C-00AA00341D07}oleaut32.dllMany processes
{CF4CC405-E2C5-4DDD-B3CE-5E7582D8C9FA}wlanapi.dllNetwork processes
MLANG-related CLSIDsmlang.dllIE/Office processes
In the wild

COM hijacking was used by APT groups including APT19, APT32, and Mustang Panda for persistence. Because it runs as the current user (no new accounts, no services), it blends with normal user activity. Process Monitor-based discovery is used both by attackers looking for targets and by defenders hunting for established hijacks.

Q & A

Q: A COM hijack DLL is in AppData — but Sysmon Event 7 (ImageLoad) isn't firing for it. Why?

Sysmon Event 7 only fires for DLL loads if the configuration explicitly includes an ImageLoad rule for that path or pattern. Default Sysmon configurations often don't log all DLL loads — the volume is enormous. To catch COM hijack DLLs: add a Sysmon rule for ImageLoad where Image contains AppData or Temp, or add a RegistryValueSet rule for HKCU\Software\Classes\CLSID paths (which fires when the hijack is installed, not when the DLL is loaded). The registry approach is more practical — it detects the hijack at installation time rather than requiring you to catch each load.

Q: How does a UAC bypass via COM hijack differ from a regular COM hijack in terms of what's detectable?

Regular COM hijack: the malicious DLL runs in the same integrity level as the triggering process — user-level persistence. UAC bypass: the triggering process is auto-elevated (high integrity), so the hijacked DLL runs at high integrity. The detectable difference: Event 4673 (privilege use) or Event 4688 showing a process with high mandatory label spawned from an auto-elevated parent (eventvwr.exe, msconfig.exe, etc.) without a UAC consent prompt Event 4703. The child process's integrity level can be checked — if a child of eventvwr.exe shows up as high-integrity but was not explicitly elevated by the user, that's the signal. Sysmon Event 1 includes IntegrityLevel for exactly this use case.