> For the complete documentation index, see [llms.txt](https://nk0.gitbook.io/dfir/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://nk0.gitbook.io/dfir/windows/investigation/malware-analysis/macros-analysis.md).

# Macros Analysis

### OLE Office Documents

Object Linking & Embedding is a proprietary technology developed by Microsoft that allows embedding and linking to documents and other objects. If you ever run into files with extensions like XLS, XSLM, DOCX, DOCM, etc. These were created using OLE technology.&#x20;

### Zip Rename

Since Office files are essentially ZIP archives (PK magic bytes), you can give them .zip extensions and unzip them. Doing so deflates the archive and reveals the files that make up the malicious office document. One of the files is the `document.xml` which is where the main document body text goes and `vbaProject.bin` containing the evil macros themselves:

<figure><img src="https://3278866189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu4e057u3LTRKJEHFetwE%2Fuploads%2FW10tBkTtyn7966ACkSpG%2Fimage.png?alt=media&amp;token=9378758f-2756-41a2-a74f-52a4e5d4ae3e" alt=""><figcaption></figcaption></figure>

### Template Injection and .docx vs .docm

Files with .docm extensions are macro enabled Office documents. This leads people to believe only .docm files are malicious. In reality, .docx files can be used to download a .docm Office template with malicious macros and execute them.&#x20;

<figure><img src="https://3278866189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu4e057u3LTRKJEHFetwE%2Fuploads%2FYW9lx1Y3LfdIg3ElvUlE%2Fimage.png?alt=media&amp;token=16eba403-7a78-4660-a84e-a2d09250db00" alt=""><figcaption><p>Navigate to _rels Directory</p></figcaption></figure>

<figure><img src="https://3278866189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu4e057u3LTRKJEHFetwE%2Fuploads%2FSeIpl7eLAanyJN6QQDXM%2Fimage.png?alt=media&amp;token=541eec21-7aee-4756-9e0f-d4dddf4a80c9" alt=""><figcaption><p>Open Settings with Text Editor</p></figcaption></figure>

The target variable points to a place in C:\Users\USERNAME\Documents. This is where the template file is downloaded (or in this case the malicious .docm file).

<figure><img src="https://3278866189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu4e057u3LTRKJEHFetwE%2Fuploads%2F1WBT5offofyEIZMOj2kS%2Fimage.png?alt=media&amp;token=37f6f2a8-be0b-4585-b81b-8e83d5d3b742" alt=""><figcaption><p>Target Template</p></figcaption></figure>

{% embed url="<http://blog.redxorblue.com/2018/07/executing-macros-from-docx-with-remote.html>" %}
Reference
{% endembed %}

{% embed url="<https://www.ired.team/offensive-security/initial-access/phishing-with-ms-office/inject-macros-from-a-remote-dotm-template-docx-with-macros>" %}
Reference
{% endembed %}
