Detect Office Template Macros in Elastic Security
Adversaries abuse Microsoft Office templates (Normal.dotm for Word, PERSONAL.XLSB for Excel) to obtain persistence. Malicious VBA macros inserted into base templates execute every time the Office application starts. Adversaries may also hijack the GlobalDotName registry key to point Word to an arbitrary template location, enabling stealth persistence that fires on every Word launch.
MITRE ATT&CK
- Tactic
- Persistence
- Technique
- T1137 Office Application Startup
- Sub-technique
- T1137.001 Office Template Macros
- Canonical reference
- https://attack.mitre.org/techniques/T1137/001/
Elastic Detection Query
sequence by host.name with maxspan=5m
[
any where (
(
event.category == "file" and event.action in ("creation", "modification") and
(
file.name in~ ("Normal.dotm", "PERSONAL.XLSB", "NormalEmail.dotm") or
file.path like~ "*\\AppData\\Roaming\\Microsoft\\Templates\\*" or
file.path like~ "*\\AppData\\Roaming\\Microsoft\\Excel\\XLSTART\\*" or
file.path like~ "*\\AppData\\Roaming\\Microsoft\\Word\\STARTUP\\*" or
file.path like~ "*\\Program Files (x86)\\Microsoft Office\\root\\*"
) and
not process.name in~ ("winword.exe", "excel.exe", "powerpnt.exe", "outlook.exe", "MicrosoftEdgeUpdate.exe", "OfficeClickToRun.exe")
) or
(
event.category == "registry" and event.action in ("modification", "creation") and
(
registry.path like~ "*Microsoft*Word*GlobalDotName*" or
registry.value like~ "*GlobalDotName*"
)
)
)
] by process.entity_id
// Supplemental: Office spawning suspicious child
sequence by host.name with maxspan=1m
[
process where event.type == "start" and
process.parent.name in~ ("winword.exe", "excel.exe", "powerpnt.exe") and
process.name in~ ("cmd.exe", "powershell.exe", "wscript.exe", "cscript.exe", "mshta.exe", "rundll32.exe", "regsvr32.exe", "certutil.exe", "bitsadmin.exe", "msiexec.exe")
] Detects T1137.001 Office Template Macro persistence via three behavioral signals: (1) writes to Office template files (Normal.dotm, PERSONAL.XLSB) by non-Office processes, (2) modification of the GlobalDotName registry key used to hijack Word template loading, and (3) Office applications spawning suspicious child processes indicative of macro execution.
Data Sources
Required Tables
False Positives & Tuning
- Legitimate Office add-in installers or macro-enabled template deployment tools writing to XLSTART or Templates directories during managed software deployment
- IT administrators using scripts to deploy standardized Word/Excel templates across the organization, which may trigger the non-Office process writing to template paths
- Antivirus or DLP software scanning and touching Office template files as part of scheduled scans may appear as unexpected file modifications
Other platforms for T1137.001
Testing Methodology
Validate this detection against 3 adversary techniques from Atomic Red Team. Each test below lists the behaviour to exercise and the telemetry you should expect to see. Executable commands and cleanup steps are available with Pro.
- Test 1Modify Normal.dotm via PowerShell (Simulated Template Backdoor)
Expected signal: Sysmon Event ID 11: FileCreate with TargetFilename ending in Normal.dotm.bak, Image=powershell.exe. Security Event ID 4663 (if object access auditing enabled) on the template file.
- Test 2Set GlobalDotName Registry Key
Expected signal: Sysmon Event ID 13: RegistryValueSet with TargetObject containing 'Office\16.0\Word\Options\GlobalDotName' and Details='C:\Users\Public\evil.dotm'. Security Event ID 4657 (Registry value modified) if registry auditing is enabled.
- Test 3Drop File in Word STARTUP Folder
Expected signal: Sysmon Event ID 11: FileCreate with TargetFilename containing '\\Word\\STARTUP\\df00tech-test.dotm' and Image=powershell.exe.
References (7)
- https://attack.mitre.org/techniques/T1137/001/
- https://www.221bluestreet.com/post/office-templates-and-globaldotname-a-stealthy-office-persistence-technique
- https://enigma0x3.net/2014/01/23/maintaining-access-with-normal-dotm/comment-page-1/
- http://www.hexacorn.com/blog/2017/04/19/beyond-good-ol-run-key-part-62/
- https://github.com/redcanaryco/atomic-red-team/blob/master/atomics/T1137.001/T1137.001.md
- https://docs.microsoft.com/en-us/office/vba/api/overview/library-reference/library-reference-object-model
- https://github.com/nicowillis/office-macro-analysis
Unlock Pro Content
Get the full detection package for T1137.001 including response playbook, investigation guide, and atomic red team tests.