Detection: Detect Use of cmd exe to Launch Script Interpreters

Description

The following detects the execution of cscript.exe or wscript.exe processes spawned by cmd.exe, leveraging Endpoint Detection and Response (EDR) telemetry mapped to the Endpoint data model, with additional contextual filtering to improve fidelity and reduce false positives. It focuses on executions originating from user-writable directories such as Users, AppData, Temp, and Downloads, which are commonly abused by attackers to stage and execute malicious scripts, while excluding trusted system paths like C:\Windows\System32\ and C:\Program Files\ that are typically associated with legitimate activity. The detection also filters out service accounts (e.g., accounts ending with $ or known naming conventions) to minimize noise from automated processes and incorporates command-line context to better assess script execution patterns and identify potentially suspicious behavior.

 1
 2| tstats `security_content_summariesonly`
 3  count min(_time) as firstTime
 4        max(_time) as lastTime
 5
 6FROM datamodel=Endpoint.Processes WHERE
 7
 8Processes.parent_process_name="cmd.exe"
 9(
10    Processes.process_name IN ("cscript.exe", "wscript.exe")
11    OR
12    Processes.original_file_name IN ("cscript.exe", "wscript.exe")
13)
14NOT Processes.process IN (
15    "* \"C:\\Program Files (x86)\\*",
16    "* \"C:\\Program Files\\*",
17    "* \"C:\\Windows\\System32\\*",
18    "* \"C:\\Windows\\SysWOW64\\*",
19    "* C:\\Program Files (x86)\\*",
20    "* C:\\Program Files\\*",
21    "* C:\\Windows\\System32\\*",
22    "* C:\\Windows\\SysWOW64\\*"
23)
24NOT Processes.user="*$"
25BY Processes.action Processes.dest Processes.original_file_name
26   Processes.parent_process Processes.parent_process_exec
27   Processes.parent_process_guid Processes.parent_process_id
28   Processes.parent_process_name Processes.parent_process_path
29   Processes.process Processes.process_exec Processes.process_guid
30   Processes.process_hash Processes.process_id Processes.process_integrity_level
31   Processes.process_name Processes.process_path Processes.user
32   Processes.user_id Processes.vendor_product
33
34| `drop_dm_object_name("Processes")`
35
36| `security_content_ctime(firstTime)`
37
38| `security_content_ctime(lastTime)`
39
40| `detect_use_of_cmd_exe_to_launch_script_interpreters_filter`

Data Source

Name Platform Sourcetype Source
CrowdStrike ProcessRollup2 Other 'crowdstrike:events:sensor' 'crowdstrike'
Sysmon EventID 1 Windows icon Windows 'XmlWinEventLog' 'XmlWinEventLog:Microsoft-Windows-Sysmon/Operational'
Windows Event Log Security 4688 Windows icon Windows 'XmlWinEventLog' 'XmlWinEventLog:Security'

Macros Used

Name Value
security_content_ctime convert timeformat="%Y-%m-%dT%H:%M:%S" ctime($field$)
detect_use_of_cmd_exe_to_launch_script_interpreters_filter search *
detect_use_of_cmd_exe_to_launch_script_interpreters_filter is an empty macro by default. It allows the user to filter out any results (false positives) without editing the SPL.

Annotations

Default Configuration

This detection is configured by default in Splunk Enterprise Security to run with the following settings:

Setting Value
Disabled true
Cron Schedule 0 * * * *
Earliest Time -70m@m
Latest Time -10m@m
Schedule Window auto
Creates Risk Event True
This configuration file applies to all detections of type anomaly. These detections will use Risk Based Alerting.

Implementation

The detection is based on data that originates from Endpoint Detection and Response (EDR) agents. These agents are designed to provide security-related telemetry from the endpoints where the agent is installed. To implement this search, you must ingest logs that contain the process GUID, process name, and parent process. Additionally, you must ingest complete command-line executions. These logs must be processed using the appropriate Splunk Technology Add-ons that are specific to the EDR product. The logs must also be mapped to the Processes node of the Endpoint data model. Use the Splunk Common Information Model (CIM) to normalize the field names and speed up the data modeling process.

Known False Positives

This detection may still generate alerts from legitimate administrative or enterprise activity, particularly in environments that rely on logon scripts, software deployment tools (e.g., SCCM, Intune), legacy applications, or IT automation frameworks that execute scripts via cmd.exe. Some organizations may also have internally developed scripts that run from user-writable directories, which can appear suspicious but are benign. Additionally, environments with non-standard application installations or portable tools may trigger this detection.

Associated Analytic Story

Risk Based Analytics (RBA)

Risk Message:

cmd.exe launched a script interpreter [$process_name$] with CommandLine [$process$] on [$dest$]

Risk Object Risk Object Type Risk Score Threat Objects
dest system 20 process

References

Detection Testing

Test Type Status Dataset Source Sourcetype
Validation Passing N/A N/A N/A
Unit Passing Dataset XmlWinEventLog:Microsoft-Windows-Sysmon/Operational XmlWinEventLog
Integration ✅ Passing Dataset XmlWinEventLog:Microsoft-Windows-Sysmon/Operational XmlWinEventLog

Replay any dataset to Splunk Enterprise by using our replay.py tool or the UI. Alternatively you can replay a dataset into a Splunk Attack Range


Source: GitHub | Version: 14