Detecting Command Line Interpreters Launched via Scheduled Tasks
KQL Queries:
KQL query to discover command line interpreters launched via scheduled tasks:
Explanation:
Pattern Matching: The
CommandLineInterpreters
dynamic array contains common command line interpreters.Filtering: The
where
clauses filter theDeviceProcessEvents
table to retain only events where command line interpreters were launched via scheduled tasks.Summarisation: The
summarise
statement aggregates the data to count the number of devices and list the devices for each command line.Ordering: The results are ordered by the number of devices in descending order.
Projection: The
project
statement selects the relevant columns for the final output.
Splunk Queries:
To detect Command Line Interpreters launched via Scheduled Tasks in Splunk using the sysmon
index, you can use the following SPL (Search Processing Language) query. It leverages Sysmon Event IDs, processes commonly associated with command-line interpreters, and their execution context.
Explanation of the Query:
Index and Event Filtering:
index=sysmon
filters to only events within thesysmon
index.EventCode=1
focuses on process creation events.
Parent Process Check (Scheduled Tasks):
ParentImage="*\\taskeng.exe"
orParentImage="*\\svchost.exe"
indicates the process is potentially related to Scheduled Tasks.CommandLine="schtasks*"
captures executions directly involvingschtasks
.
Command-Line Interpreter Filtering:
Filters for commonly abused command-line interpreters, including
cmd.exe
,powershell.exe
,wscript.exe
,cscript.exe
,pwsh.exe
, andbash.exe
.
Conditional Evaluation and Final Filtering:
Uses
eval
to tag events based on parent process or interpreter usage.Filters only events where
is_scheduled_task
andis_interpreter
are both true.
Tabular Results:
Displays relevant fields:
Interpreter
,Parent Process
,CommandLine
,User
,ComputerName
, and_time
.
Sorting:
Sort results by timestamp for analysis.
Last updated