> For the complete documentation index, see [llms.txt](https://kwcsec.gitbook.io/the-red-team-handbook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kwcsec.gitbook.io/the-red-team-handbook/techniques/persistence/ms-office.md).

# MS Office

## Trusted Locations

Add-ins that are placed in trusted locations are automatically ran when Office is opened despite any configured security settings like ignoring macros or add-ins from GPO.

Add-ins are just DLLs renamed with a WLL extension.&#x20;

You can find trusted locations based on this query, note that you have to change the version to match up with the version of Office installed

```
 Get-ChildItem "hkcu:\Software\Microsoft\Office\16.0\Word\Security\Trusted Locations"
```

This will give you multiple registry key values which are trusted locations.

To achieve code execution we have to add a WLL file to these files. You can make a simple DLL shellcode execution and but it in the folder. For example:&#x20;

```
copy payload.dll %APPDATA%\Microsoft\Word Startup\WordPresistence.wll
```

## Templates

Template macros are similar to add-ins in the fact that they get executed when Word is opened.  templates are used to customise Office documents and by default a base template exists under the %APPDATA%\Microsoft\Templates\Normal.dotm path for Word and %APPDATA%\Microsoft\Excel\XLSTART\PERSONAL.XLSB for Excel:

Depending on the security settings, it may execute without any prompts if it is in a trusted location.

To abuse this for persistence, simply modify the template files to execute your payload.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://kwcsec.gitbook.io/the-red-team-handbook/techniques/persistence/ms-office.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
