TExcelTAD
Home › Defensive Security: SOC, SIEM, Detection Engineering & Threat Hunting › SIEM Search and Correlation: SPL, KQL and EQL

SIEM Search and Correlation: SPL, KQL and EQL

A SIEM (security information and event management system) stores normalised events from every source, lets analysts search them, and runs detection rules on a schedule or on the stream. Products differ in price, scale and query language, but every SIEM query is built from the same few operations, and every correlation rule is one of a handful of patterns. Learn the operations and the patterns once; the syntax is a lookup. This lesson defines both, shows the same detection in Splunk SPL, Elastic ES|QL and EQL, and Microsoft Sentinel KQL, and runs its logic in pandas so you can see exactly what it computes.

The operations of a search

Operation What it does SPL Sentinel KQL ES|QL pandas
time range restrict to a window earliest=-15m where TimeGenerated > ago(15m) WHERE @timestamp > NOW() - 15 minutes df[df.t > now - 15min]
filter keep matching events action=failure where ResultType != "0" WHERE event.outcome == "failure" boolean mask
aggregate count, distinct count, sum by keys stats count dc(user) by src summarize count(), dcount(User) by IP STATS COUNT(*), COUNT_DISTINCT(user.name) BY source.ip groupby().agg()
time buckets aggregate per interval bin _time span=5m / timechart bin(TimeGenerated, 5m) BUCKET(@timestamp, 5 minutes) pd.Grouper(freq="5min")
join / lookup add data from another table lookup assets ip / join join kind=inner / lookup LOOKUP JOIN / ENRICH merge
threshold keep groups over a limit where count >= 10 where n >= 10 WHERE n >= 10 mask on the aggregate

Elastic has several languages: KQL (Kibana Query Language) is a filter syntax only (event.category:authentication and event.outcome:failure), ES|QL is a piped language with aggregation, and EQL (Event Query Language) specialises in ordered sequences. Microsoft's KQL (Kusto Query Language) used by Sentinel shares only the acronym with Kibana's.

The patterns of a correlation rule

Pattern Question Example
Single event does this one event match? a member added to Domain Admins
Threshold do N matching events occur within W for one key? 10 failed logons for one account in 5 minutes
Distinct count does one key touch many different values? one source fails on 5 accounts (spraying)
Sequence do events A then B happen in order for the same entity within W? 5 failures then a success (Brute Force Followed by Success)
Join across sources do two sources agree on an entity in a time window? a VPN login from abroad and a badge swipe in the office
First seen / rare has this value never (or rarely) been seen for this entity? a new admin, a rare process (New Admins and Rare Processes)
Absence did an expected event fail to happen? no heartbeat from the DC agent for 10 minutes
Statistical is this value far from the entity's baseline? upload volume 6 standard deviations above normal (Baselining)

One detection in four languages

Detection: in the last 15 minutes, a source IP with at least 10 failed sign-ins or failures on at least 5 different accounts. These are query snippets shown for comparison (not run here); field names follow each product's usual schema.

Splunk SPL:

text
index=auth action=failure earliest=-15m
| stats count AS failures, dc(user) AS accounts, values(user) AS users BY src_ip
| where failures >= 10 OR accounts >= 5

Microsoft Sentinel KQL, on the Entra ID SigninLogs table (ResultType "0" is success):

text
SigninLogs
| where TimeGenerated > ago(15m) and ResultType != "0"
| summarize failures = count(), accounts = dcount(UserPrincipalName), users = make_set(UserPrincipalName) by IPAddress
| where failures >= 10 or accounts >= 5

Elastic ES|QL on ECS fields:

text
FROM logs-*
| WHERE @timestamp > NOW() - 15 minutes AND event.category == "authentication" AND event.outcome == "failure"
| STATS failures = COUNT(*), accounts = COUNT_DISTINCT(user.name) BY source.ip
| WHERE failures >= 10 OR accounts >= 5

Elastic EQL for the related sequence (failures, then a success for the same user within 10 minutes):

text
sequence by user.name with maxspan=10m
  [authentication where event.outcome == "failure"] with runs=5
  [authentication where event.outcome == "success"]

The same logic, run

The pandas version below runs the threshold and distinct-count query on a synthetic quarter-hour of normalised sign-ins, so you can check what the snippets above compute.

python · try it yourself
import pandas as pd

now = pd.Timestamp("2026-01-15 10:15:00")
rows = []
rows += [("10:01:10", "203.0.113.50", "admin", "failure")] * 12                      # brute force on one account
rows += [(f"10:0{i}:30", "198.51.100.23", u, "failure")                              # spray: one try per account
         for i, u in enumerate(["alice", "bob", "carol", "dave", "erin", "frank"])]
rows += [("10:05:00", "10.10.0.22", "alice", "failure"), ("10:05:20", "10.10.0.22", "alice", "success"),
         ("09:50:00", "203.0.113.77", "ken", "failure")]                             # typo; one too old
ev = pd.DataFrame(rows, columns=["t", "src_ip", "user", "outcome"])
ev["t"] = pd.to_datetime("2026-01-15 " + ev.t)

q = (ev[(ev.t > now - pd.Timedelta("15min")) & (ev.outcome == "failure")]          # time range + filter
     .groupby("src_ip")                                                             # BY src_ip
     .agg(failures=("user", "size"), accounts=("user", "nunique"),                  # count, dc(user)
          users=("user", lambda s: ",".join(sorted(set(s))))))                      # values(user)
print(q.to_string())
print("\nALERTS")
print(q[(q.failures >= 10) | (q.accounts >= 5)].to_string())                        # where ...
               failures  accounts                            users
src_ip                                                            
10.10.0.22            1         1                            alice
198.51.100.23         6         6  alice,bob,carol,dave,erin,frank
203.0.113.50         12         1                            admin

ALERTS
               failures  accounts                            users
src_ip                                                            
198.51.100.23         6         6  alice,bob,carol,dave,erin,frank
203.0.113.50         12         1                            admin

Two sources trip the rule for different reasons: 203.0.113.50 by volume on one account, 198.51.100.23 by breadth across six. The typo from 10.10.0.22 does not, and 203.0.113.77 fell outside the 15-minute range. The query languages differ, but every one of them expresses exactly these steps.

How rules are scheduled, and what that misses

Most SIEM rules run on a schedule ("every 5 minutes, look back 15 minutes"). Two details decide whether they catch attacks:

  • Look-back ≥ interval + ingestion delay. A rule every 5 minutes with a 5-minute look-back misses events that arrive 2 minutes late; overlapping windows fix it, and alert deduplication removes the resulting repeats.
  • Windows cut bursts. A brute force split across two fixed windows may never reach the threshold in either; sliding windows (as in the brute-force-detect lab) or overlapping look-backs avoid that.

Streaming engines evaluate rules on each event as it arrives, which avoids the scheduling gaps but costs memory for every open window.

Pitfalls

  • Searching raw text instead of fields. "failed" matches log lines about failed backups too; filter on normalised fields.
  • dc() and dcount() are approximate at large scale in some products (they use sketches such as HyperLogLog); fine for thresholds, not for exact reporting.
  • Copying a query between products without checking the schema. The same field name can mean different things (src may be a host name in one source and an IP in another).
  • Unbounded searches. A query without a time range scans everything and may be stopped by the SIEM; always set one.

Practice

1. Modify the pandas query to also require that the source is external (not in 10.0.0.0/8). Which line changes?

Add & ~ev.src_ip.str.startswith("10.") to the filter. In SPL: | where NOT cidrmatch("10.0.0.0/8", src_ip); in Sentinel KQL: | where not(ipv4_is_in_range(IPAddress, "10.0.0.0/8")); in ES|QL: | WHERE NOT CIDR_MATCH(source.ip, "10.0.0.0/8").

2. Which correlation pattern is "a user's VPN sign-in from 203.0.113.9 while their badge was used in the office ten minutes earlier"?

A join across two sources (VPN logs and physical access logs) on the user, with a time window. It is a variant of impossible travel (Impossible Travel).

3. A rule runs every 10 minutes with a 10-minute look-back; events arrive up to 4 minutes late. What do you change?

Look back at least 14 minutes (10 + 4), better 15 to 20, so late events fall into some run; then deduplicate alerts on the key (e.g. src_ip) so the overlap does not create duplicates.

Test yourself

Which Elastic language specialises in ordered sequences of events?

  1. Kibana KQL
  2. EQL
  3. Lucene
  4. SQL only

Which correlation pattern detects password spraying?

  1. Single event
  2. Distinct count: one source failing on many accounts
  3. Absence
  4. First seen

In the program, why does 203.0.113.77 not appear in the result?

  1. It is internal
  2. Its failure at 09:50 is outside the 15-minute range
  3. It succeeded
  4. It used the wrong user

A scheduled rule runs every 5 minutes. What look-back avoids missing events that arrive 3 minutes late?

  1. 5 minutes exactly
  2. At least 8 minutes
  3. 1 minute
  4. None is needed