T1064 Microsoft Sentinel · KQL

Detect Scripting in Microsoft Sentinel

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.

MITRE ATT&CK

Tactic
Defense Evasion Execution
Canonical reference
https://attack.mitre.org/techniques/T1064/

KQL Detection Query

Microsoft Sentinel (KQL)
kusto
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
high severity medium confidence

Detects scripting-based attack patterns using Microsoft Defender for Endpoint DeviceProcessEvents. Covers four major vectors: (1) Office applications spawning script interpreters indicating macro execution, (2) wscript.exe/cscript.exe executing scripts with suspicious patterns such as download cradles or shell invocations, (3) mshta.exe running remote or inline VBScript/JavaScript content, and (4) cmd.exe spawned by Office apps or executing obfuscated batch commands. Union query returns all variants with a DetectionType tag for analyst triage.

Data Sources

Process: Process CreationCommand: Command ExecutionMicrosoft Defender for Endpoint

Required Tables

DeviceProcessEvents

False Positives & Tuning

  • 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
Download portable Sigma rule (.yml)

Other platforms for T1064


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 1VBScript Download Cradle via wscript.exe

    Expected signal: Sysmon Event ID 1: Process Create with Image=wscript.exe, CommandLine referencing df00tech_test.vbs. Sysmon Event ID 3: Network connection attempt to 127.0.0.1:8080 from wscript.exe (connection will fail). Sysmon Event ID 11: File creation of df00tech_test.vbs in %TEMP%.

  2. Test 2JScript Execution via cscript.exe with Shell Command

    Expected signal: Sysmon Event ID 1: Process Create for cscript.exe with CommandLine referencing df00tech_shell.js. Sysmon Event ID 1 (child): cmd.exe spawned by cscript.exe with 'whoami' command. Sysmon Event ID 11: Output file creation in %TEMP%.

  3. Test 3MSHTA Remote HTA Execution

    Expected signal: Sysmon Event ID 1: Process Create with Image=mshta.exe, CommandLine='mshta.exe http://127.0.0.1:8080/df00tech_test.hta'. Sysmon Event ID 3: Network connection attempt to 127.0.0.1:8080 (will fail — no listener). The process creation event fires regardless of connection success.

  4. Test 4Simulated Office Macro Child Process (cmd.exe spawned from Word context)

    Expected signal: Sysmon Event ID 1: powershell.exe process create followed by cmd.exe child process. Security Event ID 4688 (if command line auditing enabled) for both processes. To fully test the OfficeMacroSpawn detection branch, the test would need to originate from a running winword.exe process — this simulation exercises the cmd.exe execution and output paths.

  5. Test 5VBScript Inline Execution via mshta vbscript: Protocol

    Expected signal: Sysmon Event ID 1: Process Create with Image=mshta.exe, CommandLine containing 'vbscript:Execute'. A dialog box will appear briefly — dismiss it. No network connections or file writes are expected for this test variant.

Unlock Pro Content

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

Response PlaybookInvestigation GuideHunting QueriesAtomic Red Team TestsTuning Guidance

Related Detections