T1221 IBM QRadar · QRadar

Detect Template Injection in IBM QRadar

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/

QRadar Detection Query

IBM QRadar (QRadar)
sql
SELECT
  DATEFORMAT(devicetime, 'YYYY-MM-dd HH:mm:ss') AS EventTime,
  LOGSOURCETYPENAME(devicetype) AS LogSourceType,
  CATEGORYNAME(category) AS EventCategory,
  sourceip,
  destinationip,
  destinationport,
  username,
  "Image" AS OfficeProcess,
  "ParentImage" AS ParentProcess,
  "CommandLine" AS CommandLine,
  "ParentCommandLine" AS ParentCommandLine,
  "DestinationHostname" AS DestinationHostname,
  CASE
    WHEN destinationport = 445
      THEN 'ForcedAuthSMB_NTLMCapture'
    WHEN destinationport IN (80, 443, 8080, 8443)
      THEN 'RemoteTemplateFetch'
    ELSE 'OfficeChildProcess_PostTemplateExec'
  END AS AlertType,
  CASE
    WHEN destinationport = 445 THEN 90
    WHEN destinationport IN (80, 443, 8080, 8443) THEN 60
    ELSE 75
  END AS RiskScore
FROM events
WHERE
  LOGSOURCETYPENAME(devicetype) ILIKE '%sysmon%'
  AND (
    (
      QIDNAME(qid) ILIKE '%Network connection%'
      AND "Image" IMATCHES '(?i).*(winword|excel|powerpnt|mspub|msaccess|visio)\.exe'
      AND (
        (
          destinationport IN (80, 443, 8080, 8443)
          AND NOT "DestinationHostname" IMATCHES
            '(?i).*(microsoft\.com|office\.com|live\.com|microsoftonline\.com|windows\.net|sharepoint\.com|officecdn\.microsoft\.com|officecdna\.microsoft\.com|azure\.com|azurefd\.net|bing\.com|msecnd\.net|skype\.com|trafficmanager\.net|msftncsi\.com)'
        )
        OR destinationport = 445
      )
    )
    OR (
      QIDNAME(qid) ILIKE '%Process Create%'
      AND "ParentImage" IMATCHES '(?i).*(winword|excel|powerpnt|mspub|msaccess|visio)\.exe'
      AND "Image" IMATCHES '(?i).*(cmd|powershell|pwsh|wscript|cscript|mshta|rundll32|regsvr32|certutil|bitsadmin|wmic|msiexec)\.exe'
    )
  )
  AND devicetime > NOW() - 86400000
ORDER BY RiskScore DESC, devicetime DESC
high severity medium confidence

QRadar AQL detection for T1221 Template Injection querying Sysmon log source events normalised by the QRadar Sysmon DSM. Covers three detection branches: Office processes initiating outbound HTTP/HTTPS connections to non-Microsoft external hosts (remote template fetch, risk 60), Office processes connecting to SMB port 445 indicating forced NTLM credential capture via UNC path template reference (risk 90), and Office processes spawning known LOLBin child processes post-template-load (risk 75). Requires the QRadar Sysmon DSM installed and the following custom properties extracted and indexed: Image, ParentImage, CommandLine, ParentCommandLine, DestinationHostname. The QIDNAME filter on 'Network connection' and 'Process Create' maps to Sysmon EventID 3 and EventID 1 QIDs respectively.

Data Sources

QRadar Sysmon DSMWindows Sysmon via WinCollect agentWindows Sysmon via Universal DSM

Required Tables

events

False Positives & Tuning

  • Corporate-managed Office templates hosted on external CDNs, partner portals, or internal SharePoint with a non-Microsoft custom domain — the DestinationHostname IMATCHES exclusion must be extended to include all approved internal and partner template-hosting domains to avoid alert fatigue
  • Office automation scripts used by business intelligence and reporting platforms (SSRS, Crystal Reports, Tableau) that invoke Office COM objects and subsequently spawn PowerShell or CMD processes for data export or format conversion — correlate CommandLine and ParentCommandLine to distinguish automated pipeline invocations from interactive macro execution
  • Security assessment tooling or endpoint monitoring agents that inject into Office process space and generate synthetic network events or child processes as part of their monitoring hooks — cross-reference against the endpoint asset inventory and known security tool deployment records
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