Rule : Unusually Fast Process Bursts with Diverse Commands
Execution Rapid Process Bursts
Query
let lookback = 24h;
let window = 1m;
DeviceProcessEvents
| where Timestamp > ago(lookback)
| where FileName in~ ("powershell.exe","pwsh.exe","cmd.exe","curl.exe","python.exe","python3","bash","sh","net.exe","net1.exe","whoami.exe","nltest.exe","dsquery.exe","ldapsearch","aws","az")
| summarize Events=count(), DistinctTools=dcount(FileName), DistinctCommands=dcount(ProcessCommandLine), Examples=make_set(strcat(FileName, ": ", substring(ProcessCommandLine,0,160)), 8), FirstSeen=min(Timestamp), LastSeen=max(Timestamp) by DeviceId, DeviceName, AccountName, bin(Timestamp,window)
| where Events >= 12 and DistinctTools >= 3 and DistinctCommands >= 8
| extend SecondsBetween= datetime_diff('second',LastSeen,FirstSeen)
| project Timestamp, DeviceId, DeviceName, AccountName, Events, DistinctTools, DistinctCommands, SecondsBetween, Examples
| order by Events descAbout this query
Explanation
This query is designed to detect unusual, rapid bursts of command executions on a device by a single account, which might indicate automated or scripted activity rather than typical human interaction. Here's a simplified breakdown:
-
Purpose: The query aims to identify instances where a single account on a device executes a large number of distinct commands very quickly, using various command-line tools. This behavior is unusual for a human and might suggest automated processes or potential malicious activity.
-
Detection Criteria:
- The query looks at command executions over the past 24 hours.
- It focuses on specific command-line tools like
powershell,cmd,python,bash, and cloud command-line interfaces likeawsandaz. - It groups activity into 1-minute intervals for each device and account.
- An alert is triggered if, within a 1-minute window, there are:
- 12 or more command executions,
- At least 3 different tools used,
- At least 8 distinct command lines executed.
-
Data Source: The query uses data from the
DeviceProcessEventstable, which logs process activities on devices. -
Output: The query provides details such as the timestamp, device ID, device name, account name, number of events, distinct tools and commands used, and examples of the commands executed.
-
False Positives and Tuning:
- The query might flag legitimate automated processes like build systems or continuous integration (CI) tools.
- It's recommended to exclude known benign sources and adjust the thresholds based on normal activity patterns before setting up alerts.
-
Investigation Steps:
- Examine the examples of commands executed to determine if they form a coherent attack sequence or are just routine operations.
- Identify the parent process that initiated the burst of activity.
- Verify if the account typically logs into the device in question.
-
Note: The detection of rapid command execution is an inference of potential automation, not definitive proof of malicious AI activity. The thresholds are initial suggestions and should be refined through testing and observation.