Post

COM Internals: From the Binary ABI to Remote Activation

How the Component Object Model works under the hood: the binary interface contract, IUnknown and class factories, in-process servers, apartments, out-of-process activation through RPCSS, the OBJREF wire format and DCOM, with the telemetry and hardening aspects relevant to a defender.

COM Internals: From the Binary ABI to Remote Activation

Introduction

The Component Object Model (COM) is one of the oldest and most pervasive subsystems in Windows. Shell extensions, WMI, the Task Scheduler, Office automation, the Windows Runtime and a large share of the operating system’s own services expose their functionality as COM objects. For a defender, COM matters for two reasons. It is the plumbing behind a great deal of legitimate inter-process and inter-machine communication, and the same plumbing is a well-known vector for persistence and lateral movement.

This article builds COM up from first principles. It starts with the binary contract that lets components written in different languages talk to each other, moves through object creation and threading, then follows an activation request out of the client process, through the RPCSS service and finally across the network. It closes with the telemetry and hardening considerations that follow from the architecture.

COM as an interoperability layer

COM solves a specific problem: letting a component written in one language use a component written in another, without either side knowing how the other was built. A Visual Basic client can drive an object implemented in C++, and a .NET application can consume a component written in C. Figure 1 shows the idea.

flowchart LR
    VB1["Visual Basic"] & C1["C"] & CPP1["C++"] & NET1[".NET"] --> COM
    COM["Component Object Model<br/>(binary contract)"]
    COM --> VB2["Visual Basic"] & C2["C"] & CPP2["C++"] & NET2[".NET"]

Figure 1. COM as an interoperability layer between languages.

To make this possible, COM is not defined in terms of any language. It is defined as a binary contract: a precise description of how an object looks in memory and how its methods are called.1

The common ABI

For two independently compiled components to interoperate, they must agree on an Application Binary Interface (ABI): memory layout, calling convention and argument order. COM’s ABI is deliberately minimal (Figure 2):

  1. A client holds an object pointer.
  2. The first pointer-sized field of the object is the vtable pointer.
  3. The vtable is an array of function pointers, one per method of the interface, in a fixed order.
  4. Whatever follows the vtable pointer is implementation-specific data, invisible to the client.
flowchart LR
    P["Object pointer"] --> O
    subgraph O["Object"]
        direction TB
        V["VTable pointer"]
        D["Implementation-specific data"]
    end
    V --> T
    subgraph T["VTable"]
        direction TB
        M1["method1 ptr"]
        M2["method2 ptr"]
        MN["…"]
    end
    M1 --> F1["method1 code"]
    M2 --> F2["method2 code"]

Figure 2. Memory layout of a COM object as seen by a client.

Every method receives the object pointer as its first argument (the this pointer), and the remaining arguments follow from left to right. On 32-bit x86 COM methods use the __stdcall calling convention, exposed through the STDMETHODCALLTYPE macro. Expressed in plain C, the contract looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
struct ObjectVtbl {
    void (STDMETHODCALLTYPE *SetInt)(struct Object *This, int i);
    int  (STDMETHODCALLTYPE *GetInt)(struct Object *This);
};

struct Object {
    struct ObjectVtbl *lpVtbl;   /* always the first field */
    /* implementation-specific data follows */
};

/* A call through the interface: */
obj->lpVtbl->SetInt(obj, 1234);

This layout is no accident. It is exactly how mainstream C++ compilers on Windows implement classes with virtual functions. A pure-virtual C++ struct therefore produces a COM-compatible vtable with no extra work:

1
2
3
4
5
6
7
8
9
10
11
12
13
struct Interface1 {
    virtual void STDMETHODCALLTYPE A() = 0;
};

struct Interface2 {
    virtual void STDMETHODCALLTYPE B() = 0;
};

class Object : public Interface1, public Interface2 {
public:
    void STDMETHODCALLTYPE A() override {}
    void STDMETHODCALLTYPE B() override {}
};

The casting problem

The C++ mapping brings a problem with it. An object implementing several interfaces contains several vtable pointers, one per base class, at different offsets. Given a pointer to one interface, a C-style cast to another interface does not adjust the offset:

1
2
Interface1 *intf1 = new Object;                 // fine
Interface2 *intf2 = (Interface2 *)intf1;        // wrong: points at Interface1's vtable

intf2->B() would dispatch through the wrong vtable. Within one C++ program the compiler can fix this with static_cast or dynamic_cast. Across a language boundary there is no compiler to help, so COM needs a language-neutral way to move from one interface to another. That mechanism is IUnknown.

IUnknown

Every COM interface derives from IUnknown, which defines three methods:2

1
2
3
4
5
6
// {00000000-0000-0000-C000-000000000046}
struct IUnknown {
    virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject) = 0;
    virtual ULONG   STDMETHODCALLTYPE AddRef() = 0;
    virtual ULONG   STDMETHODCALLTYPE Release() = 0;
};

They provide the two services every COM object must offer:

  • Lifetime management through reference counting. AddRef increments the object’s reference count and Release decrements it. The object destroys itself when the count reaches zero. Clients never free COM objects directly.
  • Interface navigation through QueryInterface. It solves the casting problem. The client asks the object for an interface by identifier, and the object returns a correctly adjusted pointer, or E_NOINTERFACE.

Interfaces are identified by a 128-bit GUID, called an Interface Identifier (IID) in this role. Because the identifier is a value rather than a name, it is unambiguous across languages, compilers and machines. The correct way to move between the interfaces of the previous example becomes:

1
2
3
4
5
6
7
8
struct Interface1 : public IUnknown { /* ... */ };
struct Interface2 : public IUnknown { /* ... */ };

Interface2 *intf2 = nullptr;
if (SUCCEEDED(intf1->QueryInterface(IID_Interface2, (void **)&intf2))) {
    intf2->B();         // safe: pointer adjusted by the object itself
    intf2->Release();   // QueryInterface returned an AddRef'ed pointer
}

Class factories

Interfaces describe how to use an object, but not how to create one. A client in another language cannot call a C++ constructor. COM solves this with the factory idiom: each creatable class, identified by a CLSID, has an associated class object, itself a COM object, that creates instances on the client’s behalf. Class objects normally implement IClassFactory:3

1
2
3
4
5
6
7
8
9
// {00000001-0000-0000-C000-000000000046}
struct IClassFactory : public IUnknown {
    virtual HRESULT STDMETHODCALLTYPE CreateInstance(
        IUnknown *pUnkOuter,     // controlling unknown, for aggregation
        REFIID    riid,          // interface requested on the new instance
        void    **ppvObject) = 0;

    virtual HRESULT STDMETHODCALLTYPE LockServer(BOOL fLock) = 0;
};

Clients obtain a class object with CoGetClassObject, or create an instance in one step with CoCreateInstance or CoCreateInstanceEx. The latter also returns several interfaces at once and accepts information about a remote server:45

1
2
3
4
5
6
7
8
9
10
11
12
13
14
HRESULT CoGetClassObject(
    REFCLSID      rclsid,
    DWORD         dwClsContext,
    COSERVERINFO *pServerInfo,
    REFIID        riid,
    LPVOID       *ppv);

HRESULT CoCreateInstanceEx(
    REFCLSID      rclsid,
    IUnknown     *punkOuter,
    DWORD         dwClsCtx,
    COSERVERINFO *pServerInfo,
    DWORD         dwCount,
    MULTI_QI     *pResults);

The class context argument (CLSCTX) tells COM where the server may run. That choice determines the rest of the activation path:6

Class context Server runs in Server type
CLSCTX_INPROC_SERVER The client process DLL
CLSCTX_INPROC_HANDLER The client process (handler for an out-of-process object) DLL
CLSCTX_LOCAL_SERVER Another process on the same machine EXE (or service)
CLSCTX_REMOTE_SERVER A process on another machine EXE (or service), via DCOM

The following sections walk through these cases in order of increasing distance from the client.

In-process servers

The simplest case is the in-process server: a DLL loaded directly into the client process (Figure 3).

flowchart LR
    subgraph PROC["Client process"]
        direction LR
        C["Client"]
        subgraph DLL["server.dll"]
            direction TB
            CF["Class factory"]
            CI["Class instance"]
        end
    end
    REG[("HKCR\CLSID\{CLSID}\InprocServer32")]
    C -->|"1. CoCreateInstance(CLSID)"| REG
    REG -->|"2. load DLL"| DLL
    C -->|"3. DllGetClassObject()"| CF
    CF -->|"4. CreateInstance()"| CI
    C -.->|"5. method calls through the vtable"| CI

Figure 3. Activation of an in-process server.

  1. COM looks up the CLSID in the registry. The default value of the InprocServer32 subkey holds the path of the server DLL.7
  2. The DLL is loaded into the client process.
  3. COM calls the DLL’s exported DllGetClassObject function to obtain the class object:8

    1
    
    HRESULT DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv);
    
  4. COM calls IClassFactory::CreateInstance on the class object.
  5. The client receives an interface pointer to the new instance and calls its methods directly through the vtable. No marshaling is involved.

The ThreadingModel value of the same InprocServer32 key declares which apartments the class supports. That brings us to the next topic.

COM apartments

COM objects are written by many different developers. Some are thread-safe, many are not. COM therefore does not let arbitrary threads call arbitrary objects. It groups threads and objects into apartments: an apartment delimits the perimeter within which an object may be called directly. Calls that cross that perimeter are intercepted and transferred by COM.9

Each thread chooses its apartment type when it initializes COM:10

1
2
3
HRESULT CoInitializeEx(LPVOID pvReserved, DWORD dwCoInit);
// dwCoInit = COINIT_APARTMENTTHREADED  -> single-threaded apartment (STA)
// dwCoInit = COINIT_MULTITHREADED      -> multithreaded apartment (MTA)

Figure 4 summarizes the possible configurations within one process.

flowchart TB
    subgraph PROC["Process"]
        direction TB
        subgraph TX["Thread X"]
            subgraph STAX["STA X"]
                IX["Instances"]
            end
        end
        subgraph TY["Thread Y"]
            subgraph STAY["STA Y"]
                IY["Instances"]
            end
        end
        subgraph MTA["MTA (one per process)"]
            direction LR
            TA["Thread A"]
            TB["Thread B"]
            IM["Instances"]
        end
    end

Figure 4. Apartments in a process: one STA per thread, a single shared MTA.

Multithreaded apartment (MTA)

A process has at most one MTA, shared by every thread that initialized COM with COINIT_MULTITHREADED. Any thread in the MTA can call any object in the MTA directly. COM performs no synchronization, so objects living in the MTA must be thread-safe.11

flowchart LR
    subgraph PROC["Process"]
        subgraph MTA["MTA"]
            direction LR
            CX["Client X<br/>(Thread X)"]
            I["Instance"]
            CY["Client Y<br/>(Thread Y)"]
        end
    end
    CX -->|"direct call"| I
    CY -->|"direct call"| I

Figure 5. Direct calls inside the MTA.

Since Windows 2000 a third apartment type exists, the neutral apartment (NTA). It has no threads of its own: calls into an object in the NTA run on the calling thread, without a thread switch, while COM still enforces apartment rules.12

Single-threaded apartment (STA)

An STA contains exactly one thread, and only that thread may call the objects that live in it. This lets non-thread-safe objects run safely in a multithreaded process. The price is that every call coming from outside the apartment must be marshaled and handed to the STA thread (Figure 6).13

sequenceDiagram
    autonumber
    box Thread Y (another apartment)
        participant C as Client
        participant P as Proxy
    end
    box Thread X (STA X)
        participant W as STA hidden window
        participant S as Stub
        participant I as Instance
    end
    C->>P: Method call
    P->>W: Marshal arguments, post window message
    W->>S: Message loop dispatches the call
    S->>I: Unmarshal arguments, invoke method
    I-->>S: Return value
    S-->>P: Marshaled reply
    P-->>C: Return value

Figure 6. A cross-apartment call into an STA.

The two halves of the transfer have well-defined roles:

  • The proxy lives in the caller’s apartment and exposes the same interface as the real object. It implements the marshaling side: it packs every argument into a buffer and sends it to the other apartment.
  • The stub lives in the object’s apartment. It unmarshals the buffer, calls the real method and marshals the results back.

For an STA, the transport is the Windows message queue. COM creates a hidden window for every STA thread, and incoming calls are delivered as window messages. An STA thread must therefore run a message loop: an STA that stops pumping messages stops serving calls.13

The proxy/stub pair is the same building block COM uses for every boundary crossing. Only the transport changes: window messages between apartments, ALPC between processes and TCP/IP between machines.

Local server activation

When the class is registered as a local server (CLSCTX_LOCAL_SERVER), the object lives in a separate process. A component in the client process cannot create that process and connect to it by itself. Out-of-process activation is managed by the DCOM activator, which is part of the RPCSS service. Figure 7 shows the steady state once activation is complete.

flowchart LR
    subgraph CP["Client process"]
        subgraph CA["Apartment"]
            direction TB
            C["Client"] --> PX["Proxy"] --> RC["RPC client"]
        end
    end
    subgraph SP["Server process"]
        subgraph SA["Apartment"]
            direction TB
            RS["RPC server"] --> ST["Stub"] --> IN["Instance"]
        end
    end
    RC <-->|"ALPC channel"| RS
    ACT["DCOM activator<br/>(part of RPCSS)"]

Figure 7. A client connected to an object in a local server.

The client’s proxy talks to the server’s stub through local RPC over an ALPC channel. Each COM server process listens on an ALPC port whose name follows the pattern OLE<hex>, reachable through the RPC string binding ncalrpc:[OLE<hex>].

Activation flow

Figure 8 shows how the connection is established.

sequenceDiagram
    autonumber
    participant C as Client process
    participant R as RPCSS (DCOM activator)
    participant S as Server process

    C->>R: Activation request to the system activator
    R->>S: Create the server process (if not already running)
    Note over S: Server initializes COM and<br/>configures its own activator
    S->>R: Register own activator
    R->>S: Activate the object (pass Activation Properties In)
    S->>S: Create the instance
    S-->>R: Marshaled result (Activation Properties Out)
    R-->>C: Pass the result to the client
    C->>S: Connect to the instance (ALPC)

Figure 8. Local server activation flow.

  1. The client calls the system activator, a COM object exposed by RPCSS.
  2. If no suitable server process is running, RPCSS starts one.
  3. The server process initializes COM, which configures the process’s own activator.
  4. The server registers its activator, and with it its class objects, with RPCSS.
  5. RPCSS asks the server’s in-process activator to create the object and passes it the activation request.
  6. The server creates the instance.
  7. The server returns the marshaled interface pointer to RPCSS.
  8. RPCSS forwards the result to the client.
  9. The client unmarshals the result and connects directly to the instance in the server process.

The system activator interface is not publicly documented. As reconstructed in public research,14 it takes the following form:

1
2
3
4
5
6
7
8
9
10
11
// {000001A0-0000-0000-C000-000000000046}
struct ISystemActivator : public IUnknown {
    virtual HRESULT STDMETHODCALLTYPE GetClassObject(
        IActivationPropertiesIn   *pActProperties,
        IActivationPropertiesOut **ppActProperties) = 0;

    virtual HRESULT STDMETHODCALLTYPE CreateInstance(
        IUnknown                  *pUnkOuter,
        IActivationPropertiesIn   *pActProperties,
        IActivationPropertiesOut **ppActProperties) = 0;
};

Its IID is the same one the DCOM protocol specification assigns to the remote activation interface, IRemoteSCMActivator, whose methods RemoteGetClassObject and RemoteCreateInstance mirror the two methods above.15

Activation properties

The two arguments carry the whole state of an activation:

  • Activation Properties In holds all the information needed to activate the class.
  • Activation Properties Out holds all the information the client needs to connect to the created object.

On the wire, both are serialized as a CustomHeader followed by a list of property blobs. The header lists the CLSID and size of each blob that follows:15

flowchart TB
    H["CustomHeader<br/>totalSize, headerSize, destCtx, cIfs,<br/>classInfoClsid, pclsid[], pSizes[]"]
    P1["Property 1"]
    P2["Property 2"]
    PN["Property N"]
    H --> P1 --> P2 --> PN

Figure 9. Serialized activation properties.

The most important input property is InstantiationInfoData:

1
2
3
4
5
6
7
8
9
10
11
struct InstantiationInfoData {
    CLSID      classId;           // CLSID to create
    DWORD      classCtx;          // CLSCTX_* flags
    DWORD      actvflags;         // ACTIVATION_FLAGS
    long       fIsSurrogate;
    DWORD      cIID;              // number of IIDs requested
    DWORD      instFlag;
    IID       *pIID;              // list of IIDs to query for
    DWORD      thisSize;
    COMVERSION clientCOMVersion;
};

actvflags carries activation flags that alter how the server is selected and started. The names observed in public research include ACTVFLAGS_DISABLE_AAA, ACTVFLAGS_ACTIVATE_32_BIT_SERVER, ACTVFLAGS_ACTIVATE_64_BIT_SERVER, ACTVFLAGS_NO_FAILURE_LOG, ACTVFLAGS_WINRT_LOCAL_SERVER, ACTVFLAGS_WINRT_PER_USER_OK and ACTVFLAGS_APPCONTAINER.14

On the output side, PropsOutInfo returns one marshaled interface pointer per requested IID:

1
2
3
4
5
6
7
8
9
10
11
struct PropsOutInfo {
    DWORD               cIfs;
    IID                *piid;
    HRESULT            *phresults;
    MInterfacePointer **ppIntfData;
};

struct MInterfacePointer {
    unsigned long ulCntData;      // size of abData
    byte          abData[];       // an OBJREF
};

The OBJREF: a marshaled interface pointer

The abData buffer of an MInterfacePointer contains an OBJREF, the serialized form of an interface pointer.15 Every OBJREF starts with the same three fields:

Field Size Content
signature 4 bytes 0x574F454D, the ASCII string MEOW in memory
flags 4 bytes OBJREF type: 1 = standard, 2 = handler, 4 = custom, 8 = extended
iid 16 bytes IID of the marshaled interface

The rest of the structure depends on the type.

Standard OBJREF (OBJREF_STANDARD) is the form produced by COM’s own marshaler. It contains a STDOBJREF followed by binding information:

Field Size Content
flags 4 bytes Standard marshaling flags
cPublicRefs 4 bytes Number of references the OBJREF carries
oxid 8 bytes Object Exporter ID (OXID): identifies the apartment hosting the object
oid 8 bytes Object ID (OID): identifies the object
ipid 16 bytes Interface Pointer ID (IPID): identifies the specific interface on the object
saResAddr variable DUALSTRINGARRAY with the binding information for remote access

Custom OBJREF (OBJREF_CUSTOM) hands control to an object-supplied marshaler. It contains the CLSID of the class that will perform the unmarshaling, followed by a size field, a reserved field and an opaque buffer of marshaling data that only that class understands.

Experiment: decoding a standard OBJREF

The following 68 bytes are the abData of an MInterfacePointer returned during an activation:

1
2
3
4
5
00000000  4D 45 4F 57 01 00 00 00 A0 01 00 00 00 00 00 00  MEOW............
00000010  C0 00 00 00 00 00 00 46 00 00 00 00 01 00 00 00  .......F........
00000020  19 14 A0 F8 BF 3D 72 6A D5 41 68 BD 84 C3 08 E7  .....=rj.Ah.....
00000030  03 5C 00 00 38 16 E4 46 37 53 80 9C 87 A9 08 45  .\..8..F7S.....E
00000040  00 00 00 00                                      ....

Applying the layout above:

Offset Bytes Field Decoded value
0x00 4D 45 4F 57 signature MEOW
0x04 01 00 00 00 flags 1: standard OBJREF
0x08 A0 01 … 00 46 iid {000001A0-0000-0000-C000-000000000046}
0x18 00 00 00 00 std.flags 0
0x1C 01 00 00 00 std.cPublicRefs 1
0x20 19 14 … 72 6A std.oxid 0x6A723DBFF8A01419
0x28 D5 41 … 08 E7 std.oid 0xE708C384BD6841D5
0x30 03 5C … 08 45 std.ipid {00005C03-1638-46E4-3753-809C87A90845}
0x40 00 00 00 00 saResAddr Empty: no string or security bindings

All multi-byte integers are little-endian, and GUIDs use the mixed-endian Windows layout. The empty binding array is expected for a local object, because the client resolves the OXID through the local RPCSS, as described next.

Standard unmarshaling

A standard OBJREF identifies an object but does not say how to reach it: the OXID names an apartment, not an endpoint. Turning an OBJREF into a working proxy requires one more hop, through the object resolver (also called the OXID resolver) hosted by RPCSS. Figure 10 shows the situation and the flow.

sequenceDiagram
    autonumber
    participant C as Client process
    participant R as RPCSS (object resolver)
    participant S as Server process

    Note over C: Holds an OBJREF:<br/>OXID, OID, IPID
    C->>R: Where is the apartment with this OXID?
    R-->>C: At ncalrpc:[OLExxxx]
    C->>C: Instantiate a proxy and an RPC client bound to the endpoint
    C->>S: RPC call carrying the IPID
    S->>S: Look up the IPID in the IPID table and invoke the stub
    S-->>C: Reply

Figure 10. Standard unmarshaling.

  1. The client extracts the OXID from the OBJREF and asks the RPCSS object resolver where that apartment can be reached.
  2. The resolver returns the RPC string binding of the server apartment, for a local server an ALPC endpoint of the form ncalrpc:[OLE<hex>].
  3. The client instantiates a proxy and an RPC client bound to that endpoint.
  4. Every call carries the IPID of the target interface.
  5. The server looks up the IPID in its IPID table, finds the stub for that interface and dispatches the call. Conceptually: IPIDTable::Lookup(ipid)->Invoke().

The three identifiers form a hierarchy: the OXID selects the apartment (and through the resolver, the endpoint), the OID the object inside it, and the IPID the specific interface on that object.

Remote server activation

When the server runs on another machine (CLSCTX_REMOTE_SERVER), COM becomes DCOM. The architecture does not change: the client still obtains an OBJREF, resolves the OXID and calls through a proxy. The difference is that the RPCSS involved is the one on the server computer, and the ALPC channel is replaced by a TCP/IP channel (Figure 11).

flowchart LR
    subgraph CC["Client computer"]
        subgraph CP["Client process"]
            direction TB
            C["Client"] --> PX["Proxy"] --> RC["RPC client"]
        end
    end
    subgraph SC["Server computer"]
        subgraph RPCSS["RPCSS"]
            direction TB
            OR["Object resolver"]
            RA["Remote activator"]
        end
        subgraph SP["Server process"]
            direction TB
            RS["RPC server"] --> ST["Stub"] --> IN["Instance"]
        end
    end
    RC -->|"TCP/IP: activation and OXID resolution"| RPCSS
    RC <-->|"TCP/IP: method calls"| RS

Figure 11. Remote server activation.

The remote activator and the object resolver are exposed by RPCSS through the RPC endpoint mapper on TCP port 135. The server process is then reached on a dynamically assigned port, which the client learns from the binding information returned during activation and OXID resolution.15

The client specifies the target machine, and optionally the authentication settings, through COSERVERINFO and COAUTHINFO:1617

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
typedef struct _COSERVERINFO {
    DWORD       dwReserved1;
    LPWSTR      pwszName;       // name or address of the server computer
    COAUTHINFO *pAuthInfo;      // optional authentication settings
    DWORD       dwReserved2;
} COSERVERINFO;

typedef struct _COAUTHINFO {
    DWORD  dwAuthnSvc;
    DWORD  dwAuthzSvc;
    LPWSTR pwszServerPrincName;
    DWORD  dwAuthnLevel;         // e.g. RPC_C_AUTHN_LEVEL_PKT_PRIVACY
    DWORD  dwImpersonationLevel;
    void  *pAuthIdentityData;
    DWORD  dwCapabilities;
} COAUTHINFO;

dwAuthnLevel matters for security. A client can request a stronger authentication level than the default, up to RPC_C_AUTHN_LEVEL_PKT_PRIVACY, which also encrypts the traffic.

Telemetry and hardening

The architecture described above points to a few areas where COM produces useful signals and where configuration choices reduce exposure.

Registry-based activation

In-process activation trusts the registry: whatever DLL the InprocServer32 key points to is loaded into the client. COM merges per-user registrations under HKCU\Software\Classes with machine-wide registrations under HKLM\Software\Classes, and the per-user entries take precedence.18 A per-user registration can therefore redirect a CLSID used by a higher-value process. This technique is catalogued as COM hijacking (MITRE ATT&CK T1546.015).19

Monitoring recommendations:

  • Audit the creation of CLSID\{…}\InprocServer32 and LocalServer32 keys under HKCU\Software\Classes, for example with Sysmon registry events (IDs 12, 13 and 14).20 Legitimate per-user COM registrations exist but are relatively rare and stable.
  • Correlate image load events (Sysmon event ID 7) for DLLs loaded from user-writable paths by processes that do not normally load them.

DCOM as a remote execution surface

Remote activation lets an authenticated client instantiate objects on another machine. Several system classes expose methods that run commands or code, so DCOM is a documented lateral movement channel (MITRE ATT&CK T1021.003).21

  • Restrict network exposure. DCOM requires the endpoint mapper (TCP 135) and the dynamic RPC port range. Workstations rarely need to accept inbound DCOM from arbitrary peers.
  • Enforce strong authentication. Microsoft’s DCOM hardening changes (CVE-2021-26414, KB5004442) raise the minimum authentication level for DCOM activation to RPC_C_AUTHN_LEVEL_PKT_INTEGRITY. They are enforced by default on updated systems, and failures are logged in the System event log.22
  • Watch the server side of activation. On the target, a DCOM-launched server runs as a child of the DCOM launch infrastructure rather than of an interactive shell. Unusual parent-child relationships, for example an Office application or mmc.exe started remotely and spawning a command interpreter, are a strong lateral movement indicator.

Apartment and marshaling boundaries

Every boundary crossing in COM (apartment, process, machine) goes through a proxy and a stub. Defensively, it is worth remembering that:

  • out-of-process COM traffic is local RPC over ALPC, so RPC-level telemetry (for example the Microsoft-Windows-RPC ETW provider) observes it;
  • an OBJREF contains the identifiers (OXID, OID, IPID) that tie a client to a specific server apartment, which helps when reconstructing which process served a given call during an investigation.

Summary

COM is built in layers. At the bottom, a binary ABI (object pointer → vtable → methods) lets components in any language interoperate. IUnknown adds lifetime management and safe interface navigation by IID, and class factories decouple object creation from the client’s language. In-process servers are DLLs located through InprocServer32. Apartments define where an object may be called directly, and proxies and stubs marshal every call that crosses an apartment boundary. Out-of-process and remote objects are activated through RPCSS, which returns a marshaled OBJREF. Its OXID, OID and IPID are resolved to an ALPC or TCP/IP endpoint that the client then calls directly. The same mechanisms that make COM flexible, namely registry-driven activation and network-reachable activation, are the ones a defender needs to monitor and constrain.

References

  1. Microsoft Learn, The Component Object Model. ↩︎

  2. Microsoft Learn, IUnknown interface. ↩︎

  3. Microsoft Learn, IClassFactory interface. ↩︎

  4. Microsoft Learn, CoGetClassObject function. ↩︎

  5. Microsoft Learn, CoCreateInstanceEx function. ↩︎

  6. Microsoft Learn, CLSCTX enumeration. ↩︎

  7. Microsoft Learn, InprocServer32. ↩︎

  8. Microsoft Learn, DllGetClassObject function. ↩︎

  9. Microsoft Learn, Processes, Threads, and Apartments. ↩︎

  10. Microsoft Learn, CoInitializeEx function. ↩︎

  11. Microsoft Learn, Multithreaded Apartments. ↩︎

  12. Microsoft Learn, Neutral Apartments. ↩︎

  13. Microsoft Learn, Single-Threaded Apartments. ↩︎ ↩︎2

  14. James Forshaw, COM in Sixty Seconds, conference talk. The ISystemActivator, CustomHeader, InstantiationInfoData, ACTIVATION_FLAGS, PropsOutInfo and OBJREF diagrams in this article are based on its slides. ↩︎ ↩︎2

  15. Microsoft Open Specifications, [MS-DCOM]: Distributed Component Object Model (DCOM) Remote Protocol. ↩︎ ↩︎2 ↩︎3 ↩︎4

  16. Microsoft Learn, COSERVERINFO structure. ↩︎

  17. Microsoft Learn, COAUTHINFO structure. ↩︎

  18. Microsoft Learn, HKEY_CLASSES_ROOT Key. ↩︎

  19. MITRE ATT&CK, Event Triggered Execution: Component Object Model Hijacking (T1546.015). ↩︎

  20. Microsoft Learn, Sysmon. ↩︎

  21. MITRE ATT&CK, Remote Services: Distributed Component Object Model (T1021.003). ↩︎

  22. Microsoft Support, KB5004442: Manage changes for Windows DCOM Server Security Feature Bypass (CVE-2021-26414). ↩︎

This post is licensed under CC BY 4.0 by the author.