When a program starts
Office Persistence: Office Test Key and Add-ins
How the Office test registry key, COM add-ins loaded at startup and Excel OPEN add-ins run code each time Office starts, and how to find and remove them.
- Tactics
- Persistence
- Runs
- When a program starts
- Set up by
- Users and administrators
- Locations
- HKCU\Software\Microsoft\Office test\Special\Perf
- HKLM\SOFTWARE\Microsoft\Office test\Special\Perf
- HKCU\Software\Microsoft\Office\Outlook\Addins
- HKLM\SOFTWARE\Microsoft\Office\Word\Addins
- HKCU\Software\Microsoft\Office\16.0\Excel\Options
- %APPDATA%\Microsoft\Excel\XLSTART
- %APPDATA%\Microsoft\Word\STARTUP
How it works
Office applications load code from several registry locations each time they start, as the user running them. None of it needs a macro.
The Office test key. At start, Office applications read the default value of Software\Microsoft\Office test\Special\Perf, in the user's hive and in HKLM, and load the DLL it names. The key looks like a leftover from Microsoft's own performance testing. It is not documented as a feature, Office does not list it among add-ins, and it applies to Word, Excel, PowerPoint and Outlook alike. A 32-bit Office on 64-bit Windows reads the machine-wide copy under WOW6432Node.
COM add-ins. Each Office application lists its COM and VSTO add-ins under Software\Microsoft\Office\<Application>\Addins\<ProgID>, per user and machine-wide. The ProgID leads to a COM class whose DLL (or a .NET or VSTO manifest) Office loads into its process. LoadBehavior decides when:
LoadBehavior | Meaning |
|---|---|
| 0, 2 | Not loaded (2: set to load at startup, but currently unloaded) |
| 3 | Loaded at every start of the application |
| 8, 9 | Loaded on demand (9: currently loaded) |
| 16 | Loaded at the next start, then on demand |
Office sets LoadBehavior from 3 to 2 when it soft-disables an add-in that failed at start.
Excel OPEN values. Software\Microsoft\Office\<version>\Excel\Options holds OPEN, OPEN1, OPEN2… values, one per add-in Excel opens at start, sometimes prefixed with a switch such as /R. A .xlam or .xla add-in is a workbook with VBA; an .xll is a native DLL whose xlAutoOpen export Excel calls. Version 16.0 covers Office 2016, 2019, 2021 and Microsoft 365.
Office also opens files from its startup folders: templates in %APPDATA%\Microsoft\Word\STARTUP and workbooks in %APPDATA%\Microsoft\Excel\XLSTART. These are trusted locations by default, so their macros run without a prompt. That is the template technique, close to this one.
Where it lives
| Location | Default | Who can write it |
|---|---|---|
HKCU\Software\Microsoft\Office test\Special\Perf | Absent | The user |
HKLM\SOFTWARE\Microsoft\Office test\Special\Perf, and under WOW6432Node | Absent | Administrators |
HKCU\Software\Microsoft\Office\<Application>\Addins\<ProgID> | Add-ins installed for the user | The user |
HKLM\SOFTWARE\Microsoft\Office\<Application>\Addins\<ProgID>, and under WOW6432Node | Add-ins installed for all users | Administrators |
HKCU\Software\Microsoft\Office\16.0\Excel\Options (OPEN*) | Present only for add-ins the user enabled | The user |
%APPDATA%\Microsoft\Word\STARTUP, %APPDATA%\Microsoft\Excel\XLSTART | Empty | The user |
Click-to-Run installations keep part of their machine-wide registry in a virtual hive under HKLM\SOFTWARE\Microsoft\Office\ClickToRun\REGISTRY\MACHINE, which can hold add-in registrations too.
Add-ins are common on business machines: the Teams meeting add-in for Outlook, PDF tools, CRM and e-signature plug-ins. The Office test key has no legitimate use on a production machine.
How attackers use it
The Office test key needs one per-user value and no rights:
reg add "HKCU\Software\Microsoft\Office test\Special\Perf" /ve /t REG_SZ /d "C:\Users\alice\AppData\Roaming\Microsoft\Office\perfmon.dll" /f
Palo Alto Networks Unit 42 reported Sofacy (APT28) using it in 2016; the DLL then loaded each time the victim opened any Office application. ATT&CK lists the technique as Office Test.
A malicious COM add-in registers a class in the user's hive (see COM hijacking for where that lives) and an add-in key with LoadBehavior 3:
reg add "HKCU\Software\Microsoft\Office\Outlook\Addins\Contoso.MailHelper" /v LoadBehavior /t REG_DWORD /d 3 /f
Outlook is the favourite target: it often runs all day, and an add-in inside it can read, send and hide mail. An XLL dropped in AppData and listed in OPEN runs native code each time Excel starts:
reg add "HKCU\Software\Microsoft\Office\16.0\Excel\Options" /v OPEN /t REG_SZ /d "\"C:\Users\alice\AppData\Roaming\Microsoft\AddIns\report.xll\"" /f
Names imitate real add-ins, and FriendlyName and Description copy a vendor's wording. Because Office loads the code, the process tree shows only WINWORD.EXE, EXCEL.EXE or OUTLOOK.EXE.
How to check a host
In each Office application, File > Options > Add-ins lists active, inactive and disabled COM and Excel add-ins with their file paths. It does not show the Office test DLL. From a prompt:
reg query "HKCU\Software\Microsoft\Office test" /s
reg query "HKLM\SOFTWARE\Microsoft\Office test" /s
reg query "HKLM\SOFTWARE\WOW6432Node\Microsoft\Office test" /s
Get-Item 'HKCU:\Software\Microsoft\Office\*\Addins\*', 'HKLM:\SOFTWARE\Microsoft\Office\*\Addins\*' -ErrorAction SilentlyContinue | Get-ItemProperty | Select-Object PSPath, FriendlyName, LoadBehavior, Manifest
Get-ItemProperty 'HKCU:\Software\Microsoft\Office\16.0\Excel\Options' | Select-Object OPEN*
Autoruns lists add-ins on its Office tab. For each add-in, follow the ProgID to its CLSID and DLL, or the Manifest value to the VSTO files, and check the signer and folder.
Offline, read each user's NTUSER.DAT at Software\Microsoft\Office test, Software\Microsoft\Office\<Application>\Addins and Software\Microsoft\Office\<version>\Excel\Options, and the SOFTWARE hive for the machine-wide keys. Key last-write times date the change; LoadBehavior rewritten by Office also updates them. Collect the startup folders and the add-in files. Trust records under Software\Microsoft\Office\<version>\<Application>\Security\Trusted Documents\TrustRecords show which documents had their content enabled, which often explains how the add-in arrived. Sysmon 7 shows an Office process loading a DLL from a user folder.
Suspicious: any Office test value; an add-in whose DLL sits in AppData, ProgramData or Temp and is unsigned; a ProgID no installed product explains; an XLL listed in OPEN outside the Office installation folder.
What Windows Persistence flags
The tool reads:
- The Office test key, native and
WOW6432Node, in the SOFTWARE hive and in each user'sNTUSER.DAT. A non-empty default value raises Office test DLL (high), plus the command-line rules on the path (Runs from a temporary or public folder, Machine-made name and the others; for the machine-wide key, also System-wide autostart from a writable folder). - Add-ins in each user's
Software\Microsoft\Office\<Application>\Addinsand machine-wide in the SOFTWARE hive (Microsoft\Office\<Application>\Addinsand itsWOW6432Nodetwin), whoseLoadBehaviorhas both bits of 3 set (connected, and loaded at startup). Each entry shows the ProgID, friendly name andLoadBehavior, and names the file Office loads: the VSTOManifestvalue (without its|vstolocalsuffix), or else the DLL found by following the ProgID to its CLSID andInprocServer32, in the user's classes first, then the machine's. An add-in raises no flag of its own. The path rules run on that file, in their system-wide form for machine-wide add-ins (System-wide autostart from a writable folder, Runs from a temporary or public folder…), and a manifest on anhttporhttpsaddress raises Runs from a network share (medium). - Excel
OPENvalues under each user'sSoftware\Microsoft\Office\<version>\Excel\Options. Each raises Excel add-in loaded at start: medium for an.xll, low for workbook add-ins, and only informational for a file in Program Files or Windows' folders, such as the Analysis ToolPak Office ships. The path rules run on the file named.
Across mechanisms, Written date marks a key written in the 7 days before the newest time in the collection, and Inside a Defender exclusion (path) and program also runs from mechanisms apply to every entry with a file path, add-ins included. An add-in whose file sits in Windows' folders and raises no flag is hidden by the "Hide Windows entries" filter; the other Office entries stay visible.
Limits: the tool does not read the Click-to-Run virtual registry, Word's STARTUP folder, Excel's XLSTART folder, Normal.dotm or other templates, PowerPoint add-ins, or Outlook rules, forms and home page settings. A VSTO manifest written as a file:/// address is not turned into a path, so that add-in gets no path rules or cross-checks. A .NET add-in registered through mscoree.dll resolves to the .NET runtime rather than its own assembly (named in CodeBase), so it looks like a Windows file and is hidden by the filter unless something else flags it.
Cleaning up
- Close the Office applications. Preserve the keys with
reg export "HKCU\Software\Microsoft\Office test" C:\IR\office-test.reg(and the add-in andOptionskeys), and copy the DLL, XLL or add-in folder with its hash. - Office test:
reg delete "HKCU\Software\Microsoft\Office test" /f. Office creates nothing under that key, so the whole key can go. - COM add-in: delete the
Addins\<ProgID>key, then the ProgID and CLSID registrations it used in the user's classes, then the files. An add-in installed through an installer is better removed from Programs and Features. - Excel add-in: untick it in Excel's Add-ins dialog, which rewrites the
OPENvalues, then delete the file.
Then check the other users' hives and the startup folders, and look for the same file behind other mechanisms. An add-in inside Outlook could read and send mail as the user: review mailbox rules, forwarding and sent items, and revoke the user's sessions and tokens.
See also
Related techniques
On Windows Forensics
The artifacts behind this technique, in the Windows Forensics reference: