SIEM Query Repository

Quick reference for Microsoft Sentinel (KQL) and Splunk (SPL) detection rules.

1. Basic Filtering & Aggregation

Failed Sign-ins via KQL

Tracks multiple failed authentication events across your environments.

SigninLogs
| where ResultType == "50126"
| summarize Count=count() by UserPrincipalName, IPAddress
| where Count > 5

Windows Process Creation (Event ID 4688)

Used for tracking process execution and command-line activity on Windows endpoints when Defender MDE logs are unavailable.

SecurityEvent
| where TimeGenerated >= ago(24h) and EventID == 4688
| where CommandLine has_any ("-enc", "-EncodedCommand", "-e")
| project TimeGenerated, Computer, Account, CommandLine
Key Learning Points

Failed Logon Aggregations (Event ID 4625)

Identifies potential brute-force targets by counting failed Windows login attempts per user account.

SecurityEvent
| where TimeGenerated >= ago(7d) and EventID == 4625
| summarize FailedCount = count() by Account
| top 5 by FailedCount desc
Key Learning Points

2. Multi-Table & Behavioral Correlation

Correlating Endpoint File Downloads with Identity Sign-ins

Correlates file downloads in user directories with successful cloud sign-ins within the same timeframe.

DeviceFileEvents
| where TimeGenerated >= ago(1d)
| where FolderPath has "Downloads" or FolderPath has "Temp"
| where isnotempty(InitiatingProcessAccountUpn)
| join kind=inner (
    SigninLogs
    | where TimeGenerated >= ago(1d)
    | where ResultType == 0
) on $left.InitiatingProcessAccountUpn == $right.UserPrincipalName
| project TimeGenerated, DeviceName, FileName, UserPrincipalName, IPAddress, Location
Key Learning Points

Detection of Password Spray Attacks

Detects IP addresses attempting logins across multiple unique user accounts with failures (ResultType 50126/50053) that eventually yield at least one successful login (ResultType 0).

let Lookback = 2h;
let FailedThreshold = 10;
// Step 1: Identify IPs targeting multiple unique accounts
let SuspiciousIPs = SigninLogs
    | where TimeGenerated >= ago(Lookback)
    | where ResultType in (50126, 50053)
    | summarize UniqueUsers = dcount(UserPrincipalName) by IPAddress
    | where UniqueUsers >= FailedThreshold
    | project IPAddress;
// Step 2: Match those IPs against successful logins
SigninLogs
| where TimeGenerated >= ago(Lookback) and ResultType == 0
| where IPAddress in (SuspiciousIPs)
| summarize SuccessfulUsers = make_set(UserPrincipalName), TotalSuccesses = count() by IPAddress
Key Learning Points

3. Advanced Analysis & Anomaly Detection

Time-Series Anomaly Detection

Uses built-in machine learning functions to detect sudden spikes in process executions against a 14-day baseline.

let StartTime = ago(14d);
let EndTime = now();
let Step = 1h;
DeviceProcessEvents
| where TimeGenerated between (StartTime .. EndTime)
| make-series ProcessCount = count() default=0 on TimeGenerated from StartTime to EndTime step Step by FileName
| extend (Anomalies, Score, Baseline) = series_decompose_anomalies(ProcessCount, 2.5)
| mv-expand TimeGenerated to typeof(datetime), ProcessCount to typeof(long), Anomalies to typeof(long), Baseline to typeof(long)
| where Anomalies == 1
| project TimeGenerated, FileName, ProcessCount, Baseline, Anomalies
Key Learning Points

4. Schema Discovery & Environment Optimization

Identify Active Log Tables

Lists all tables actively ingesting logs in your environment alongside total row counts.

union withsource=TableName *
| where TimeGenerated >= ago(24h)
| summarize Count=count() by TableName
| order by Count desc
Key Learning Points

Inspect Table Schema & Column Names

Reveals all column names and data types for a given table without executing large scans.

DeviceProcessEvents
| getschema
Key Learning Points

Locate Tables Containing Specific Keywords

Finds which security log tables store a specific term (e.g., "powershell").

search in (SecurityEvent, DeviceProcessEvents, CommonSecurityLog, SigninLogs) "powershell"
| where TimeGenerated >= ago(2h)
| summarize Count=count() by $table
Key Learning Points

Legacy Reference Queries

Brute Force Detection via Splunk (SPL) - Event ID 4625

Monitors Windows Security Event ID 4625 for potential target attacks.

index=security sourcetype="WinEventLog:Security" EventCode=4625
| stats count by user, src_ip
| where count > 10