COM Hijacking via TreatAs
Overview
COM resolves a class identifier to an implementation by walking the registry, and it checks the
per-user hive before the machine hive. A TreatAs value under a CLSID tells COM “when anyone asks
for this class, give them that one instead” — a redirection primitive that needs no administrative
rights and no file in a protected directory.
The result is persistence that executes inside whichever signed process next instantiates the hijacked class, with no autorun entry and no scheduled task to enumerate.
Abandoned CLSIDs — classes referenced by a task or shell extension but no longer registered — are the quieter target. Nothing breaks when you claim one, because nothing was answering before.
The call chain
- 1pick a frequently instantiated CLSIDAnything the shell, a scheduled task or Explorer resolves on a predictable trigger.
- 2write HKCU\Software\Classes\CLSID\{...}\TreatAsPer-user hive wins over HKLM and needs no administrative rights.
- 3register the substitute InprocServer32Point the replacement CLSID at a DLL under a user-writable path.
- 4(wait for the trigger)The next CoCreateInstance for the original CLSID loads the substitute inside a signed host.
Reference implementation
Windows Registry Editor Version 5.00
; redirect a system CLSID to one we control — HKCU beats HKLM
[HKEY_CURRENT_USER\Software\Classes\CLSID\{0358B920-0AC7-461F-98F4-58E32CD89148}\TreatAs]
@="{D20A0000-0000-0000-C000-000000000046}"
[HKEY_CURRENT_USER\Software\Classes\CLSID\{D20A0000-0000-0000-C000-000000000046}\InprocServer32]
@="C:\\Users\\analyst\\AppData\\Local\\Temp\\payload.dll"
"ThreadingModel"="Apartment"Windows Registry Editor Version 5.00
; redirect a system CLSID to one we control — HKCU beats HKLM
[HKEY_CURRENT_USER\Software\Classes\CLSID\{0358B920-0AC7-461F-98F4-58E32CD89148}\TreatAs]
@="{D20A0000-0000-0000-C000-000000000046}"
[HKEY_CURRENT_USER\Software\Classes\CLSID\{D20A0000-0000-0000-C000-000000000046}\InprocServer32]
@="C:\\Users\\analyst\\AppData\\Local\\Temp\\payload.dll"
"ThreadingModel"="Apartment"Detection
This is an inventory problem rather than a memory problem. Snapshot the user hive’s Classes\CLSID
subtree on a schedule and alert on additions that shadow a machine-hive class — the legitimate rate
of change on a managed endpoint is close to zero.