[Blog] Marshalling to SYSTEM - An analysis of CVE-2018-0824
Microsoft COM for Windows failed to properly validate serialized objects during custom unmarshalling, so a crafted stream could cause the COM runtime to create an arbitrary moniker and call BindToObject on it. An attacker who could get a victim to open a crafted file or script could run code, and the author demonstrated privilege escalation to SYSTEM by targeting a service that allows custom marshalling.
code-white.com
Published on code-white.com
In May 2018 Microsoft patched an interesting vulnerability (CVE-2018-0824) which was reported by Nicolas Joly of Microsoft’s MSRC:
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the unmarshalling code read a class identifier from the attacker-controlled stream and created and bound that object without validating it, allowing an arbitrary moniker to be instantiated.
Impact
An attacker could achieve remote code execution, and the author demonstrated privilege escalation to SYSTEM; the exploit required a target COM server that allows custom marshalling, as BITS did not.
What the attacker needed
Victim opens a crafted file or script; target COM server allows custom marshalling; attacker can place a file on disk
The fix
Microsoft patched it by checking a flag from thread-local storage so the unmarshalling method exits early without reading from the stream when the flag is not set.
How it was found
- Create a fake COM object implementing the IStorage and IMarshal interfaces.
- Return the GUID of the QC Marshal Interceptor class from GetUnmarshalClass so the runtime uses it for unmarshalling.
- In MarshalInterface, write bytes to the stream that satisfy the checks in the interceptor's unmarshalling code.
- Compose a File Moniker and a New Moniker to build a Script Moniker, since the Script Moniker class could no longer be created directly.
- Place a scriptlet file on disk and activate a target COM server running as SYSTEM that allows custom marshalling.
- Call CoGetInstanceFromIStorage to trigger serialisation of the fake object and observe the script running as SYSTEM.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
COM is a Windows system that lets programs reuse each other's code by asking for objects by a long identifier. When one program passes an object to another process, the object is packed into a stream and unpacked on the other side, and this report shows that the unpacking trusted the stream too much. By controlling the stream, an attacker could make Windows load and run a chosen object, which in the demonstrated case ran a program with the highest Windows privileges.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.