Slide 1

Slide 1 text

COM/DCOM: Forgotten Knowledge Vladislav Burtsev

Slide 2

Slide 2 text

2 COM/DCOM basics Advanced capabilities Tools & API Attacks: Direct COM/DCOM usage Attacks: COM Hijacking Detection Agenda 2

Slide 3

Slide 3 text

History 3 Aimed to solve compatibility and sharing problems Introduced in 1990s and related with OLE, ActiveX, DCOM, COM+, MTS, etc COM/DCOM Basics

Slide 4

Slide 4 text

4 COM/DCOM Basics - Terms COM Interface A set of methods with defined binary layout COM Object An instance of a COM Class COM Component (COM Server) PE file with one or more COM Classes DLL Class Class Instance COM Class Implements one or more COM Interfaces

Slide 5

Slide 5 text

5 COM/DCOM Basics – IN- and OUT-of-process COM Server IN-process OUT-OF-process DLL Class Instance 1 Instance 2 Client Process Server Process Proxy to Instance 1 Instance 1 Stub marshal unmarshal

Slide 6

Slide 6 text

6 COM/DCOM Basics – IUnknown interface IUnknown COM Object HRESULT QueryInterface(const IID& riid, void** ppv); ULONG AddRef(); ULONG Release();

Slide 7

Slide 7 text

7 COM/DCOM Basics – Invocation same host Client Application SCM 1. Request with CLSID Registry 2. Lookup in registry COM Object Server process 3. Instantiates COM Object 4. Passes pointer to Object 5. Call COM Method (default) %SystemRoot%\System32\RtCOM64.dll

Slide 8

Slide 8 text

8 COM/DCOM Advanced capabilities – Invocation another host Registry Client SCM Proxy RPC SCM COM Object RPC Stub Application

Slide 9

Slide 9 text

9 COM/DCOM Advanced capabilities – Invocation another host PowerShell Empire ShellBrowserWindow ShellWindows MMC20.Application Excel.Application GetTypeFromCLSID GetTypeFromProgID DCOM ServiceStart ShellExecute ExecuteShellCommand RegisterXLL DDEInitiate

Slide 10

Slide 10 text

10 COM/DCOM Advanced capabilities – Multiple Languages C# C/C++ PowerShell VBA Server XML HTTP 6.0 open() send() … New-Object -ComObject Msxml2.ServerXMLHTTP.6.0 [activator]::CreateInstance([type]::GetTypeFromCLSID(…)) Dim myObj As Object Set myObj = CreateObject(“MSXML2.ServerXMLHTTP”) MSXML2.ServerXMLHTTP myObj = new ServerXMLHTTP(); hr = CoCreateInstance(CLSID, NULL, CLSCTX_ALL, IID_Interface, reinterpret_cat(&iface))

Slide 11

Slide 11 text

11 COM/DCOM Tools & API – Instance Creation CoInitializeEx() CoCreateInstance() Initialize COM for the thread (put it into the apartment of given type) Create an instance of a given class and return a requested interface pointer to the new object. CoGetClassObject() CLSCTX_INPROC_SERVER CLSCTX_LOCAL_SERVER CLSCTX_REMOTE_SERVER Context Trying to get a pointer to IClassFactory interface ClassFactoryObject -> CreateInstance()

Slide 12

Slide 12 text

12 COM/DCOM Tools & API – Instance Creation CoGetClassObject(rclsid, dwClsContext, pServerInfo, riid, ppv) DLL EXE Service 1. Locate CLSID in HKEY_CLASSES_ROOT 2. Load DLL from InprocServer32 key CoLoadLibrary() 3. Call GetProcAddress() for DllGetClassObject() 4. Call DllGetClassObject() 5. Return Class Factory to caller 1. Locate CLSID in a global table that maps CLSID to its associated Class Factory. This map is managed by DCOMLaunch (hosted in svchost.exe) 2. If not found, locate CLSID in HKEY_CLASSES_ROOT 3. Launch executable from LocalServer32 key where Command Line is stored. DCOMLaunch uses CreateProcess() 4. Created process registers itself in the DCOMLaunch table by calling CoRegisterClassObject() 5. Once registered, client receives a proxy object to the class factory 1. Locate CLSID in a global table that maps CLSID to its associated Class Factory. This map is managed by DCOMLaunch (hosted in svchost.exe) 2. If not found, locate CLSID in HKEY_CLASSES_ROOT 3. Launch executable from AppID key where Launch permissions and service name is stored. DCOMLaunch contacts SCM 4. Created process registers itself in the DCOMLaunch table by calling CoRegisterClassObject() 5. Once registered, client receives a proxy object to the class factory

Slide 13

Slide 13 text

13 COM/DCOM Advanced capabilities – regsvr32.exe LoadLibrary() GetProcAddress() DllRegisterServer()

Slide 14

Slide 14 text

14 COM/DCOM – AMSI PowerShell Windows Script Host JavaScript VBScript Office VBA source: https://learn.microsoft.com/en-us/windows/win32/amsi/how-amsi-helps

Slide 15

Slide 15 text

15 COM/DCOM – Attacks: Direct COM/DCOM Usage impacket : : dcomexec.py PowerShell Empire

Slide 16

Slide 16 text

16 COM/DCOM – Attacks: Direct COM/DCOM Usage

Slide 17

Slide 17 text

17 COM/DCOM – Attacks: Direct COM/DCOM Usage process_creation BitsDownload.exe file_event C:\Users\script.ps1 Svchost.exe process_creation cmd.exe process_creation whoami.exe file_event C:\Users\info.txt

Slide 18

Slide 18 text

18 COM/DCOM – Attacks: COM Hijacking HKEY_CLASSES_ROOT File extension associations COM class registrations Virtualized registry root for UAC

Slide 19

Slide 19 text

The per-user class registration data in HKCU\SOFTWARE\Classes mapped to %SYSTEMROOT%\AppData\Local\Microsoft\Windows\Usrclass.dat 19 COM/DCOM – Attacks: COM Hijacking HKEY_CLASSES_ROOT Systemwide class registration data in HKLM\SOFTWARE\Classes = +

Slide 20

Slide 20 text

20 COM/DCOM – Abandoned COM keys

Slide 21

Slide 21 text

21 COM/DCOM – Attacks: COM Hijacking - ThreatAs

Slide 22

Slide 22 text

22 COM/DCOM – Attacks: COM Hijacking - ScriptletURL rundll32.exe –sta {GUID}

Slide 23

Slide 23 text

23 COM/DCOM – Attacks: COM Hijacking - ScriptletURL source: https://github.com/enigma0x3/windows-operating-system-archaeology/blob/master/Evasion/slmgr_COM_hijack.reg

Slide 24

Slide 24 text

24 COM/DCOM – Attacks: COM Hijacking - EoP source: https://github.com/hfiref0x/UACME

Slide 25

Slide 25 text

25 COM/DCOM – Detection GetTypeFromCLSID GetTypeFromProgID + ServiceStart ShellExecute ExecuteShellCommand RegisterXLL DDEInitiate EventID 4104/AMSI

Slide 26

Slide 26 text

26 COM/DCOM – Detection title: Component Object Model Hijacking via TreatAs description: Detects component object model hijacking via treatas author: Kaspersky status: stable tags: - attack.persistence - attack.privilege_escalation - attack.t1546.015 - attack.defense_evasion - attack.t1112 logsource: category: registry_set product: windows detection: selection: EventType: SetValue TargetObject|endswith: - 'Classes\CLSID\*\TreatAs' - 'Classes\CLSID\*\ScriptletURL' filter: Image|endswith: - 'program files\common files\microsoft shared\clicktorun\updates\*\officeclicktorun.exe' - 'windows\winsxs\amd64_microsoft-windows-servicingstack_*\tiworker.exe' condition: selection and not filter falsepositives: - level: high

Slide 27

Slide 27 text

27 COM/DCOM – Detection title: Component Object Model Hijacking via rundll32.exe description: Detects COM server start via rundll32. It's likely a hijacked COM component. author: Kaspersky status: stable tags: - attack.persistence - attack.privilege_escalation - attack.t1546.015 - attack.t1548.002 - attack.defense_evasion - attack.t1218.011 logsource: category: process_creation product: windows detection: selection1: Image|endswith: '\rundll32.exe' selection2: CommandLine|contains: - '-sta ' - '/sta ' CommandLine|contains|all: - '{' - '}' selection3: CommandLine|contains: '-localserver ' condition: selection1 and (selection2 or selection3) falsepositives: Legitimate soft (rare) level: high

Slide 28

Slide 28 text

Thank you! Vladislav Burtsev Threat Intelligence analyst @vladburch www.linkedin.com/in/vladislav-burtsev