T1221 Splunk · SPL

Detect Template Injection in Splunk

Adversaries abuse template references embedded in Office Open XML (OOXML) documents and RTF files to conceal and deliver malicious payloads. DOCX, XLSX, and PPTX files are ZIP archives containing an XML relationship file (word/_rels/document.xml.rels) that can reference an external template URL via an attachedTemplate relationship. When the document is opened, the Office application fetches the remote template, which may deliver VBA macros, exploits, or shellcode that are absent from the original lure document — bypassing static file analysis. RTF files can be modified to include a \*\template control word pointing to a remote URL, triggering a fetch on open. Both vectors are used to deliver malicious macros (APT28 remote template macro delivery), execute exploits (Confucius, WarzoneRAT via RTF exploit embedding), or capture NTLM credentials by injecting SMB UNC paths that trigger forced authentication (Dragonfly, DarkHydrus/Phishery). Real-world campaigns frequently deliver these lures via phishing (T1566) or tainted shared content (T1080). The technique is effective because the initial document contains no traditional indicators — no embedded VBA, no OLE streams, no scripts — making gateway scanning and sandboxes that do not perform dynamic network fetching ineffective.

MITRE ATT&CK

Tactic
Defense Evasion
Technique
T1221 Template Injection
Canonical reference
https://attack.mitre.org/techniques/T1221/

SPL Detection Query

Splunk (SPL)
spl
index=wineventlog sourcetype="XmlWinEventLog:Microsoft-Windows-Sysmon/Operational"
(
  (
    EventCode=3
    (Image="*\\winword.exe" OR Image="*\\excel.exe" OR Image="*\\powerpnt.exe" OR Image="*\\mspub.exe" OR Image="*\\msaccess.exe" OR Image="*\\visio.exe")
    (DestinationPort=80 OR DestinationPort=443 OR DestinationPort=445 OR DestinationPort=8080 OR DestinationPort=8443)
  )
  OR
  (
    EventCode=1
    (ParentImage="*\\winword.exe" OR ParentImage="*\\excel.exe" OR ParentImage="*\\powerpnt.exe" OR ParentImage="*\\mspub.exe" OR ParentImage="*\\msaccess.exe" OR ParentImage="*\\visio.exe")
    (Image="*\\cmd.exe" OR Image="*\\powershell.exe" OR Image="*\\pwsh.exe" OR Image="*\\wscript.exe" OR Image="*\\cscript.exe" OR Image="*\\mshta.exe" OR Image="*\\rundll32.exe" OR Image="*\\regsvr32.exe" OR Image="*\\certutil.exe" OR Image="*\\bitsadmin.exe" OR Image="*\\wmic.exe" OR Image="*\\msiexec.exe")
  )
)
| eval EventType=case(
    EventCode=3, "NetworkConnection",
    EventCode=1, "ProcessCreate",
    true(), "Unknown"
  )
| eval IsForcedAuth=if(EventCode=3 AND DestinationPort=="445", 1, 0)
| eval IsRemoteFetch=if(EventCode=3 AND (DestinationPort=="80" OR DestinationPort=="443" OR DestinationPort=="8080" OR DestinationPort=="8443"), 1, 0)
| eval IsChildExec=if(EventCode=1, 1, 0)
| eval MicrosoftInfra=if(EventCode=3 AND (
    match(DestinationHostname, "(?i)(microsoft\.com|office\.com|live\.com|microsoftonline\.com|windows\.net|sharepoint\.com|officecdn\.microsoft\.com|msecnd\.net|azure\.com|bing\.com|msn\.com|skype\.com)")
  ), 1, 0)
| where NOT (IsRemoteFetch=1 AND MicrosoftInfra=1)
| eval AlertType=case(
    IsForcedAuth=1, "ForcedAuthSMB_NTLMCapture",
    IsRemoteFetch=1, "RemoteTemplateFetch",
    IsChildExec=1, "OfficeChildProcess_PostTemplateExec",
    true(), "Unknown"
  )
| eval OfficeProcess=coalesce(Image, ParentImage)
| eval TargetOrChild=coalesce(DestinationHostname, CommandLine)
| eval RiskScore=IsForcedAuth*90 + IsRemoteFetch*60 + IsChildExec*75
| table _time, host, User, EventType, AlertType, OfficeProcess, TargetOrChild,
         DestinationIp, DestinationPort, DestinationHostname,
         CommandLine, ParentImage, ParentCommandLine, RiskScore
| sort - RiskScore, - _time
high severity high confidence

Unified SPL detection for T1221 Template Injection combining Sysmon EventCode=3 (Network Connection) and EventCode=1 (Process Creation). Detects three key signals: (1) Office applications (winword, excel, powerpnt, mspub, msaccess, visio) making outbound HTTP/HTTPS connections to non-Microsoft infrastructure — indicating a remote template being fetched; (2) Office applications initiating SMB (port 445) connections — indicating a Forced Authentication attack via an injected UNC path; (3) Child processes spawned by Office applications — indicating successful macro/exploit execution from a fetched remote template. A RiskScore weights each alert type for prioritization. Microsoft infrastructure domains are excluded via regex to suppress telemetry noise.

Data Sources

Network Traffic: Network Connection CreationProcess: Process CreationSysmon Event ID 3 (Network Connection)Sysmon Event ID 1 (Process Creation)

Required Sourcetypes

XmlWinEventLog:Microsoft-Windows-Sysmon/Operational

False Positives & Tuning

  • Corporate document management and template servers on-premises — add their hostnames to the MicrosoftInfra exclusion regex
  • Office automation workflows that legitimately spawn cmd.exe or wscript.exe via VBA macros for approved business processes — baseline and allowlist by ParentCommandLine pattern
  • Office Click-to-Run (C2R) servicing and update processes making external connections to CDN infrastructure — validate DestinationHostname against known Microsoft ranges
  • Third-party Office add-ins that use COM automation causing Office to spawn helper processes — inventory add-ins and build exclusions by ChildProcess+ParentCmdLine tuple
  • VPN or proxy configurations that route SMB traffic through unusual endpoints — validate DestinationIp against known infrastructure
Download portable Sigma rule (.yml)

Other platforms for T1221


Testing Methodology

Validate this detection against 5 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.

  1. Test 1OOXML Remote Template Injection — DOCX with External attachedTemplate

    Expected signal: When document is opened in Word: Sysmon Event ID 3 with Image=winword.exe, DestinationIp=127.0.0.1, DestinationPort=8080. Sysmon Event ID 22 (DNS Query) if a FQDN is used instead of localhost. DeviceNetworkEvents in MDE will show InitiatingProcessFileName=winword.exe with RemoteIP=127.0.0.1 and RemotePort=8080. The connection will be refused (no listener) but the event fires before the TCP RST.

  2. Test 2RTF Template Injection — \*\template Control Word with HTTP URL

    Expected signal: When opened in Word: Sysmon Event ID 3 with Image=winword.exe, DestinationIp=127.0.0.1, DestinationPort=8080. DeviceFileEvents may show the RTF file being read from its download location. The RTF \*\template control word triggers the same network fetch mechanism as the OOXML attachedTemplate relationship.

  3. Test 3Forced Authentication via SMB UNC Template Reference

    Expected signal: Sysmon Event ID 3 with Image=winword.exe, DestinationPort=445, DestinationIp=127.0.0.1. On a real attack with an external IP: Security Event ID 4648 (explicit credential use) or 4624 (NTLM logon type 3) on the domain controller. Sysmon Event ID 22 may show DNS lookup if a hostname is used instead of IP. DeviceNetworkEvents in MDE shows InitiatingProcessFileName=winword.exe, RemotePort=445.

  4. Test 4Phishery-style Template URL Injection into Existing DOCX

    Expected signal: File creation events (Sysmon EventCode=11) for both the original and injected DOCX in %TEMP%. When the injected DOCX is opened: Sysmon EventCode=3 from winword.exe to 127.0.0.1:8080. The manipulation of the ZIP archive using System.IO.Compression is visible as PowerShell process events (Sysmon EventCode=1) before the Office network event — the chain of PowerShell→file creation→Office network connection is the full kill chain telemetry.

  5. Test 5Verify Template Injection Document Structure — Manual Inspection

    Expected signal: PowerShell process creation (Sysmon EventCode=1) with command line containing System.IO.Compression.ZipFile. No network events — this is static analysis only. The script outputs the injected URL to the console, confirming the template injection payload is present before any execution occurs.

Unlock Pro Content

Get the full detection package for T1221 including response playbook, investigation guide, and atomic red team tests.

Response PlaybookInvestigation GuideHunting QueriesAtomic Red Team TestsTuning Guidance

Related Detections