Scripting
Adversaries may use scripts to aid in operations and perform multiple actions that would otherwise be manual. This deprecated technique (now superseded by T1059 Command and Scripting Interpreter) covered adversary use of scripting languages including VBScript, JavaScript, Windows Script Host, batch scripts, and macro-enabled Office documents. Scripts can be used to speed up operations, bypass process monitoring by interacting with the OS at an API level, and enable execution via spearphishing attachments containing malicious macros. Common attack patterns include VBScript/JScript execution via wscript.exe or cscript.exe, malicious Office macros spawning child processes, and batch scripts performing reconnaissance or lateral movement.
let SuspiciousScriptPatterns = dynamic([
"invoke-expression", "iex(", "downloadstring", "downloadfile",
"net.webclient", "invoke-webrequest", "start-bitstransfer",
"cmd /c", "cmd/c", "/c powershell", "wscript.shell",
"createobject", "shell.application", "shellexecute",
"certutil", "bitsadmin", "regsvr32", "mshta",
"http://", "https://", "ftp://"
]);
let OfficeApps = dynamic(["winword.exe", "excel.exe", "powerpnt.exe", "outlook.exe", "onenote.exe", "access.exe", "visio.exe"]);
let ScriptInterpreters = dynamic(["wscript.exe", "cscript.exe", "mshta.exe", "cmd.exe", "powershell.exe", "pwsh.exe"]);
// Branch 1: Office applications spawning script interpreters (macro execution)
let OfficeMacroExecution = DeviceProcessEvents
| where Timestamp > ago(24h)
| where InitiatingProcessFileName has_any (OfficeApps)
| where FileName has_any (ScriptInterpreters)
| extend DetectionType = "OfficeMacroSpawn"
| project Timestamp, DeviceName, AccountName, FileName, ProcessCommandLine,
InitiatingProcessFileName, InitiatingProcessCommandLine, DetectionType;
// Branch 2: Script interpreters with suspicious arguments
let SuspiciousScriptExec = DeviceProcessEvents
| where Timestamp > ago(24h)
| where FileName in~ ("wscript.exe", "cscript.exe")
| where ProcessCommandLine has_any (SuspiciousScriptPatterns)
or ProcessCommandLine matches regex @"(?i)\.(vbs|vbe|js|jse|wsf|wsh|hta)\b"
| extend DetectionType = "SuspiciousScriptInterpreter"
| project Timestamp, DeviceName, AccountName, FileName, ProcessCommandLine,
InitiatingProcessFileName, InitiatingProcessCommandLine, DetectionType;
// Branch 3: MSHTA executing remote content or VBScript inline
let MshtaAbuse = DeviceProcessEvents
| where Timestamp > ago(24h)
| where FileName =~ "mshta.exe"
| where ProcessCommandLine has_any ("vbscript:", "javascript:", "http://", "https://", "//", "\\\\")
| extend DetectionType = "MshtaRemoteExecution"
| project Timestamp, DeviceName, AccountName, FileName, ProcessCommandLine,
InitiatingProcessFileName, InitiatingProcessCommandLine, DetectionType;
// Branch 4: Cmd.exe spawned by Office apps or running obfuscated batch commands
let CmdBatchAbuse = DeviceProcessEvents
| where Timestamp > ago(24h)
| where FileName =~ "cmd.exe"
| where InitiatingProcessFileName has_any (OfficeApps)
or (ProcessCommandLine has_any ("^^", "&&", "||")
and ProcessCommandLine has_any ("http", "certutil", "bitsadmin", "powershell", "wscript", "cscript"))
| extend DetectionType = "SuspiciousBatchCmd"
| project Timestamp, DeviceName, AccountName, FileName, ProcessCommandLine,
InitiatingProcessFileName, InitiatingProcessCommandLine, DetectionType;
union OfficeMacroExecution, SuspiciousScriptExec, MshtaAbuse, CmdBatchAbuse
| sort by Timestamp desc Data Sources
Required Tables
False Positives
- Legitimate software installers that use VBScript (wscript.exe) for install/uninstall automation, particularly older enterprise applications
- IT administration scripts run via Group Policy or SCCM that use cscript.exe or wscript.exe for inventory or configuration tasks
- Office add-ins and COM automation tools that legitimately spawn child processes from Word or Excel (e.g., mail-merge workflows, report generators)
- Help desk and remote support tools (ConnectWise, TeamViewer) that may spawn cmd.exe or scripts from unusual parent processes
- Security scanners and vulnerability assessment tools that invoke mshta.exe or script interpreters during active scanning
References (11)
- https://attack.mitre.org/techniques/T1064/
- https://attack.mitre.org/techniques/T1059/
- https://www.uperesia.com/analyzing-malicious-office-documents
- https://blog.crowdstrike.com/deep-thought-chinese-targeting-national-security-think-tanks/
- https://github.com/redcanaryco/atomic-red-team/blob/master/atomics/T1064/T1064.md
- https://learn.microsoft.com/en-us/windows/security/threat-protection/auditing/event-4688
- https://learn.microsoft.com/en-us/sysinternals/downloads/sysmon
- https://github.com/SigmaHQ/sigma/tree/master/rules/windows/process_creation
- https://www.fireeye.com/blog/threat-research/2019/10/staying-hidden-on-the-endpoint-evading-detection-with-shellcode.html
- https://lolbas-project.github.io/lolbas/Binaries/Mshta/
- https://github.com/mandiant/OfficeMalScanner
Unlock Pro Content
Get the full detection package for T1064 including response playbook, investigation guide, and atomic red team tests.