Join our Newsletter — 33% off our NHI Course
Home› Guides› MITRE ATT&CK T1221 Template Injection: Detecting Evasion
Guide SOC & Detection Engineering

MITRE ATT&CK T1221 Template Injection: Detecting Evasion

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, edited by Lalit Choda Updated 12 November 2026 13 min read
On this page

A document with no macro inside it can still fetch one: template injection hides the malicious part of an Office or RTF file on a remote server, so the attachment that reaches the user looks clean to static scanning. MITRE ATT&CK T1221 Template Injection sits in the Stealth tactic (TA0005) in ATT&CK v20 and applies to Windows. Adversaries create or modify template references in Office Open XML documents (.docx, .xlsx, .pptx) or the \template control word in RTF files so that, when the file opens, Office retrieves content from an attacker-controlled location. The same trick can point the template at an SMB or credential-prompting URL to trigger T1187 Forced Authentication. This guide covers how groups use the technique, what to detect and where, the four ATT&CK mitigations and the practical controls that make them work. It is for detection engineers, email and endpoint security owners and SOC analysts. This is not server-side template injection in web applications, which is a different problem covered in the Server-Side Template Injection (SSTI) Guide.

Key takeaways

  • The payload is not in the file. The document carries a reference, and the dangerous content arrives only when Office resolves it, which is why attachment scanning often passes it.
  • Two outcomes, one mechanism. A remote template can deliver a macro-enabled template (.dotm) or exploit, or it can point at an SMB path so Windows sends NTLM authentication to the attacker.
  • The detection point is Office talking to the network. ATT&CK v20 analytic AN1564 looks for winword.exe and similar processes making outbound connections for templates, followed by unusual child processes.
  • Macro blocking narrows it but does not close it. ATT&CK notes that disabling macros may not stop the Forced Authentication variant, so outbound SMB filtering matters as much as Office policy.
  • Long-running and current. ATT&CK v20 links the technique to APT28, Gamaredon Group, Dragonfly, DarkHydrus, MirrorFace, Inception, Confucius and Tropic Trooper, and to Lazarus Group activity in Operation Dream Job.

How template injection works

ATT&CK describes OOXML files as ZIP archives of XML parts. Properties in those parts can reference shared resources by URL; a template property, for example, points to a pre-formatted document blueprint that Office fetches when the document loads. An adversary who writes or edits that reference can make an innocent-looking document pull a malicious template at open time. In RTF files, the legitimate \template control word names a template file to retrieve and load; adversaries alter the bytes of an existing RTF file to insert a template control word that points at a remote resource.

VariantWhere the reference livesWhat the fetch deliversRelated techniques
OOXML remote templateRelationship target in the document's settings part (Chaes changed the template target in settings.xml)Macro-enabled template (.dotm) or other content that runs when loadedT1566.001 Spearphishing Attachment, T1204.002 Malicious File
RTF template control word\template control word inserted into the RTF bytesRemote payload retrieved and loaded on openT1566.001, T1204.002
Forced authenticationTemplate target set to an SMB path or another credential-prompting URLNTLM authentication attempt sent to the attacker's serverT1187 Forced Authentication
Shared contentTemplate reference in a document left on a file share or collaboration siteAny of the above, for every user who opens itT1080 Taint Shared Content

The attraction for the adversary is timing and separation. The first-stage file can be benign at the moment it passes the mail gateway, and the server hosting the template can choose what to serve, or serve nothing to a sandbox. For delivery context, see MITRE ATT&CK T1566 Phishing; for the credential angle, see MITRE ATT&CK T1187 Forced Authentication.

How adversaries use it: cases from ATT&CK v20

Every procedure below is a procedure example on the ATT&CK T1221 page, with the source ATT&CK cites.

Group, software or campaignReported useSource cited by ATT&CK
APT28 (G0007)Weaponised Word documents abusing the remote template function to retrieve a malicious macroUnit 42, Sofacy, December 2018
Dragonfly (G0035)Injected SMB URLs into Word spearphishing attachments to start Forced AuthenticationUS-CERT alert TA18-074A
DarkHydrus (G0079)Used the open-source Phishery tool to inject remote template URLs into Word documents for Forced AuthenticationUnit 42, August 2018
Gamaredon Group (G0047)DOCX files that download malicious DOT templates, and RTF template injection to download payloadsProofpoint; Trend Micro, April 2020
MirrorFace (G1054)Remote template injection to retrieve payloads from command and controlITOCHU, LODEINFO, January 2024
Operation Dream Job (C0022)Lazarus Group used DOCX files to retrieve a malicious DOTM templateClearSky and McAfee, 2020
Chaes (S0631)Changed the template target in settings.xml to the URL of the next payloadCybereason, November 2020
WarzoneRAT (S0670)Installed through a malicious DLL embedded in a template RTF inside a Word documentUptycs, Confucius, January 2021

Two patterns stand out. First, the technique serves both espionage groups and financially motivated malware, so it should be treated as a common delivery primitive rather than a rare tradecraft marker. Second, the Forced Authentication variant (Dragonfly, DarkHydrus) needs no code execution at all: the win for the adversary is a captured NTLM exchange that can be cracked offline or relayed. That links this technique to the NTLM work covered in the NTLM Relay Guide and the NTLM Deprecation and Elimination Guide.

What to detect and where

ATT&CK v20 maps one detection strategy, DET0566 Template Injection Detection - Windows, with one analytic, AN1564. It describes Office or document viewer processes such as winword.exe initiating network connections to remote templates, or running scripts because of a manipulated template reference in .docx, .rtf or .dotm files, followed by suspicious child processes such as PowerShell.

SignalData component (v20)Log sourceTuning notes
Office process creates an outbound connection shortly after a document opensNetwork Connection CreationSysmon Event ID 3 (network connection), Sysmon Event ID 22 (DNS query)Baseline legitimate template hosts (corporate SharePoint, template servers); alert on new external domains and raw IP addresses
Office process starts a scripting engine or LOLBinProcess CreationSysmon Event ID 1, Security Event ID 4688 with command linewinword.exe, excel.exe or powerpnt.exe as parent of powershell.exe, cmd.exe, mshta.exe, rundll32.exe or wscript.exe is rarely legitimate
Office process connects outbound on TCP 445 or uses WebDAVNetwork Connection CreationSysmon Event ID 3, firewall logsAny SMB from a workstation to the internet should be blocked and alerted; this is the Forced Authentication variant
Template URL inside an attachmentFile inspection (gateway or sandbox)Mail gateway, detonation sandbox verdictsExtract relationship targets from OOXML parts and \template values from RTF; flag external targets

Building the sequence

  1. Anchor on the document open: file creation by the mail client or browser (Sysmon Event ID 11) followed by an Office process start with that file in its command line.
  2. Look for the fetch within seconds: a DNS query and network connection from the same Office process ID to a domain outside your template allowlist.
  3. Look for consequences: a child process, a new file written to a user-writable path, or an outbound SMB attempt. Alert on the sequence; the single network event alone is noisy in organisations that use cloud-hosted templates.
  4. Enrich: attach the sender, the attachment hash and the template URL to the alert so the analyst can pivot to every recipient of the same message.

Where Microsoft Defender attack surface reduction (ASR) rules are in use, the advanced hunting action types AsrOfficeChildProcessAudited and AsrOfficeChildProcessBlocked show the rule "Block all Office applications from creating child processes" firing, which often catches the second stage. See the Sysmon Guide for collecting Event IDs 1, 3, 11 and 22.

Mitigations

ATT&CK v20 lists four mitigations for T1221. The second column is the ATT&CK guidance; the third is how NHI Mgmt Group recommends making it concrete.

MitigationATT&CK guidanceNHI Mgmt Group recommendation
M1042 Disable or Remove Feature or ProgramConsider disabling Office macros and active content; this may not mitigate the Forced Authentication useKeep the Microsoft 365 Apps policy "Block macros from running in Office files from the Internet" enabled for Word, Excel and PowerPoint; allow only signed macros from trusted publishers. See the Office Macro Blocking Guide
M1049 Antivirus/AntimalwareHost and network prevention, antivirus and detonation chambers can stop documents fetching or executing payloadsDetonate Office and RTF attachments with network access enabled, so the template fetch is observed, and record the remote target
M1031 Network Intrusion PreventionSame as above, at the network layerBlock outbound TCP 445 and 139 at the perimeter; restrict Office processes to known template hosts where a proxy allows per-process policy
M1017 User TrainingTrain users to spot social engineering and spearphishing that deliver malicious documentsTeach that "Enable content" and "Unblock" prompts on unexpected documents are the moment to stop and report

Office macro policy specifics

  • Default behaviour: Microsoft documents that Office on Windows blocks VBA macros in files carrying Mark of the Web (zone 3 Internet or 4 Restricted sites) and shows a Security Risk banner with no Enable content button.
  • Policy path: the policy is per application, for example User Configuration\Policies\Administrative Templates\Microsoft Word 2016\Word Options\Security\Trust Center, setting "Block macros from running in Office files from the Internet".
  • Coverage gaps to close: Mark of the Web applies only to files on NTFS, so documents that arrive through containers or file systems that drop it lose the protection. Policies are available with Microsoft 365 Apps for enterprise.
  • Alternative: "VBA Macro Notification Settings" set to disable all except digitally signed macros, with signing by a trusted publisher required.

Microsoft also documents ASR rules relevant to the second stage: "Block all Office applications from creating child processes" (d4f940ab-401b-4efc-aadc-ad5f3c50688a), "Block Office applications from creating executable content" (3b576869-a4ec-4529-8536-b80a7769e899), "Block Office applications from injecting code into other processes" (75668c1f-73b5-4cf0-bb93-3ecf5cb7cc84) and "Block Win32 API calls from Office macros" (92e97fa1-2edf-4476-bdd6-9dd0b4dddc7b). Run each in audit mode first, review hits for line-of-business add-ins, then move to block by pilot ring.

Rolling out controls without breaking templates

  1. Inventory legitimate template sources: list the internal and cloud locations that host corporate templates, including Workgroup templates set by policy.
  2. Turn on telemetry first: collect Sysmon Event IDs 1, 3 and 22 for Office processes and build the template host allowlist from two to four weeks of data.
  3. Block outbound SMB: deny TCP 445 and 139 to the internet at the perimeter and on host firewalls. This is low risk and removes the Forced Authentication variant's main route.
  4. Enforce macro policy: confirm "Block macros from running in Office files from the Internet" is in force across channels; pilot the signed-macros-only notification setting with finance and operations teams who use macros.
  5. Enable ASR rules in audit, then block: one ring at a time, with an exclusion process that names an owner and expiry for each exception.
  6. Rollback: each control is a policy setting that can be reverted per ring; keep the previous GPO or Intune profile version so a broken add-in can be restored within one policy refresh.

How to test

  • Benign template fetch: in a lab, create a document whose template points at an internal web server you control that serves an empty template, then confirm the Office network event and DNS query are collected and correlated to the document open.
  • SMB egress check: from a pilot workstation, confirm an outbound connection attempt to an external host on TCP 445 is blocked and logged at the firewall.
  • Sandbox verdict: send the benign test document through the mail gateway and confirm the detonation report records the external template reference.
  • Alert path: confirm the SOC receives the sequence alert with the sender, hash and template URL attached, and that the triage runbook covers pulling the same message from other mailboxes.

Use authorised, benign test content only; ATT&CK-based emulation plans and the published procedure examples above are enough to define realistic test cases without live payloads.

Measuring it

  • Telemetry coverage: percentage of Windows endpoints sending Sysmon Event IDs 1, 3 and 22 for Office processes.
  • Outbound SMB blocked: count of hosts able to reach TCP 445 on the internet (target zero).
  • Macro policy compliance: percentage of devices with "Block macros from running in Office files from the Internet" applied for each Office application.
  • Template allowlist drift: number of new external template hosts seen per week, each reviewed.
  • Time to purge: median time from the first alert on a malicious template document to its removal from all mailboxes.

Common failure patterns

  • Trusting a clean static scan: the attachment has no macro and no exploit, so it passes, and the payload arrives from the template host after delivery.
  • Sandboxes without network access: detonation with networking disabled never sees the fetch and returns a benign verdict.
  • Macro blocking treated as complete: the Forced Authentication variant needs no macro, so NTLM hashes still leave the network if SMB egress is open.
  • Mark of the Web lost in transit: Mark of the Web applies only on NTFS, so documents that pass through other file systems lose the zone marker and the default macro block with it.
  • Alerting on Office network events alone: cloud-hosted templates and add-ins create constant noise, analysts tune the rule off, and the real fetch is missed. Correlate with the document open and child process.

Framework mapping

FrameworkReferenceHow it applies
MITRE ATT&CK v20T1221 (TA0005 Stealth); related T1566.001, T1204.002, T1187, T1080Technique, delivery and follow-on behaviour
ATT&CK mitigationsM1042, M1049, M1031, M1017Mitigations listed on the T1221 page
NIST SP 800-53 Rev 5SI-3 Malicious Code Protection, SI-4 System Monitoring, SC-7 Boundary Protection, CM-7 Least Functionality, AT-2 Literacy Training and AwarenessScanning, monitoring, egress control, macro restriction, user awareness
NIST CSF 2.0DE.CM-09, DE.CM-01, PR.PS-01Endpoint and network monitoring, configuration management of Office policy

Practitioner checklist

  • Collect Sysmon Event IDs 1, 3, 11 and 22 for Office processes on all Windows endpoints.
  • Build and maintain an allowlist of legitimate template hosts; alert on new external hosts contacted by Office.
  • Block outbound TCP 445 and 139 to the internet at the perimeter and on host firewalls.
  • Enforce "Block macros from running in Office files from the Internet" for every Office application in use.
  • Run ASR Office rules in audit, review, then block by ring with owned, expiring exclusions.
  • Detonate Office and RTF attachments with network access and record template targets.
  • Write a correlation rule for document open, template fetch and child process, not the fetch alone.
  • Add the template URL and sender to the triage runbook so all recipients can be found and purged.

Standards and references

Related NHI Mgmt Group resources: Macro Malware Guide · Office Macro Blocking Guide · MITRE ATT&CK T1566 Phishing · ATT&CK Stealth and Defense Impairment Tactics Guide · NTLM Relay Guide

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Researched and written by the NHI Mgmt Group editorial team using AI tools, under the editorial direction of Lalit Choda. Facts are drawn from the sources listed on this page and checked by our automated quality process. Last updated 12 November 2026. Spotted an error? Use our contact page.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM and Agentic AI security. nhimg.org

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick the PDF box to continue.