Query Details
let query_frequency = 1h;
let query_period = 14d;
let _ExpectedServiceCommandsRegex = toscalar(
_GetWatchlist("Activity-ExpectedSignificantActivity")
| where Activity == "ServiceCreation"
| summarize RegEx = strcat(@"^(", strcat_array(make_list(Auxiliar), "|"), @")$")
);
IdentityDirectoryEvents
| where TimeGenerated > ago(query_period)
| where ActionType == "Service creation"
| extend
ServiceName = tostring(AdditionalFields["ServiceName"]),
ServiceCommand = tostring(AdditionalFields["ServiceCommand"]),
Count = toint(AdditionalFields["Count"])
| where not(ServiceCommand matches regex _ExpectedServiceCommandsRegex)
| summarize arg_min(TimeGenerated, *) by Protocol, ServiceName, ServiceCommand, AccountName, AccountSid
| where TimeGenerated > ago(query_frequency)
| project
TimeGenerated,
Application,
ActionType,
Protocol,
AccountDisplayName,
AccountUpn,
AccountSid,
ServiceName,
ServiceCommand,
TargetDeviceName,
Count,
AdditionalFields,
ReportId
This KQL query is designed to monitor and identify unusual service creation activities within a specified time frame. Here's a simplified breakdown of what the query does:
Define Time Frames:
query_frequency is set to 1 hour, meaning the query will focus on the most recent hour of data.query_period is set to 14 days, which is the overall period the query will examine for historical data.Expected Commands:
Filter Events:
IdentityDirectoryEvents that occurred within the last 14 days.ActionType is "Service creation".Extract and Filter Data:
ServiceName, ServiceCommand, and Count from the event's additional fields.ServiceCommand does not match the expected commands pattern.Summarize and Identify:
Project Results:
In essence, this query helps identify potentially suspicious or unexpected service creation activities by comparing them against a predefined list of expected commands and focusing on recent occurrences.

Jose Sebastián Canós
Released: April 16, 2025
Tables
Keywords
Operators