Detect Office apps spawning shells (KQL)
When Word, Excel, Outlook or another Office app launches cmd.exe, powershell.exe, wscript.exe or a living-off-the-land binary, it usually means a malicious macro, a weaponised document or a phishing attachment has executed. This DeviceProcessEvents query matches processes whose initiating process is an Office application and whose image is a shell, scripting host or common LOLBin.
It is one of the most productive endpoint detections for user-driven initial access and execution.
The query
DeviceProcessEvents
| where Timestamp > ago(7d)
| where InitiatingProcessFileName in~ (
"winword.exe", "excel.exe", "powerpnt.exe", "outlook.exe",
"mspub.exe", "onenote.exe", "msaccess.exe", "visio.exe")
| where FileName in~ (
"cmd.exe", "powershell.exe", "pwsh.exe", "wscript.exe", "cscript.exe",
"mshta.exe", "regsvr32.exe", "rundll32.exe", "bitsadmin.exe", "certutil.exe")
| project Timestamp, DeviceName, AccountName,
InitiatingProcessFileName, FileName,
ProcessCommandLine, InitiatingProcessCommandLine
| sort by Timestamp descLine-by-line explanation
| where InitiatingProcessFileName in~ ("winword.exe", "excel.exe", ...)Requires the parent to be an Office application — the pivot that makes this suspicious rather than ordinary scripting.
| where FileName in~ ("cmd.exe", "powershell.exe", "mshta.exe", ...)Keeps only child processes that are shells, scripting hosts or LOLBins — the tools a malicious document reaches for.
project ... ProcessCommandLine, InitiatingProcessCommandLineSurfaces both command lines so an analyst can see what the document ran and which file opened it.
Required tables and columns
InitiatingProcessFileNameThe parent image; an Office application here.FileNameThe spawned child process image (shell, scripting host or LOLBin).ProcessCommandLineWhat the child process was told to do — the payload.InitiatingProcessCommandLineThe Office command line, often showing the opened document path.
MITRE ATT&CK mapping
- Tactic
- ExecutionTA0002
- Technique
- T1204.002· User Execution: Malicious File
Tuning and false positives
- Exclude known-good add-ins and automation that legitimately shell out (some enterprise templates do), scoped by command-line pattern.
- Promote to critical when the child command line contains download or encoded-execution indicators.
Limitations
- Malware that injects into a trusted process or uses COM to run code without a direct child process will not appear as an Office child.
- Legitimate but unusual business macros can match; baseline per environment.
Related queries
References
Last reviewed 2026-11-18.