#Why this matters
Once a SIEM normalizes and indexes incoming logs, SOC analysts spend most of their shift writing queries to validate alerts, hunt hidden threats, and build timelines. Splunk and Elastic Security dominate enterprise SOCs, and although their storage architectures differ, both rely on the same analytical workflow: narrow the dataset early, group events across time, and surface anomalous entities.
Learning how to translate one threat hypothesis across Splunk's Search Processing Language (SPL) and Elastic's Kibana Query Language (KQL) and Event Query Language (EQL) makes you effective in almost any blue-team environment.
#Splunk Search Processing Language (SPL)
SPL works like a Unix command pipeline. Everything to the left of the first pipe (|) selects raw or indexed events; each piped command transforms or aggregates the results passed to it.
- Selectindex=auth_logs sourcetype=... EventCode=4625
- Bucketbin _time span=5m
- Aggregatestats count dc(TargetUserName) by _time, IpAddress
- Filterwhere failed_attempts >= 15 OR distinct_users >= 5
- Ranksort - failed_attempts
Always filter as specifically as possible before the first pipe. Specifying index, sourcetype, and exact field-value pairs avoids reading unrelated gigabytes from disk.
| SPL command | Purpose | Common example |
|---|---|---|
bin |
Round timestamps into fixed buckets | bin _time span=5m |
stats |
Group and aggregate events | stats count dc(user) by src_ip |
timechart |
Build a time-series table for charts | timechart span=1h count by action |
eval |
Create or transform a calculated field | eval mb=round(bytes/1048576, 2) |
where |
Filter after aggregation or using expressions | where failed_attempts >= 15 |
table / sort |
Select columns and order results | sort - count |
Consider hunting Windows logon failures (EventCode=4625) in SPL. Counting total failures catches noisy brute force against one account, while dc(TargetUserName) (distinct count) catches password spraying where an attacker tries one password against dozens of accounts:
index=auth_logs sourcetype="WinEventLog:Security" EventCode=4625
| bin _time span=5m
| stats count AS failed_attempts dc(TargetUserName) AS distinct_users values(TargetUserName) AS users BY _time, IpAddress
| where failed_attempts >= 15 OR distinct_users >= 5
| sort - failed_attemptsIf 198.51.100.42 fails 40 times against alice, failed_attempts triggers the alert. If 203.0.113.18 tries 12 usernames once each, distinct_users catches it even though per-account lockouts never fired.
#Elastic Security: KQL and EQL
Elastic Security splits querying into two complementary languages built on top of Elastic Common Schema (ECS) fields:
- KQL (Kibana Query Language) filters documents in Discover, Dashboards, and threshold rules. It uses
field: valuepairs, boolean operators (and,or,not), parentheses, and wildcards (*). - EQL (Event Query Language) matches ordered sequences and relationships across events over time. Unlike KQL, EQL tracks state across multiple events sharing a common key.
In Discover, an analyst isolates external failed logins while excluding an authorized lab scanner (192.0.2.50) using KQL:
event.category: "authentication" and event.outcome: "failure" and not source.ip: 192.0.2.50When you need to prove an attacker did not just knock on the door, but actually got in, switch to EQL. The sequence below matches two failed authentications followed by a success from the same source.ip and targeting the same user.name within 5 minutes:
sequence by source.ip, user.name with maxspan=5m
[authentication where event.outcome == "failure"]
[authentication where event.outcome == "failure"]
[authentication where event.outcome == "success"]EQL uses the event category (authentication, process, network, file) directly inside square brackets and joins steps using the fields listed after sequence by.
| Language | Primary role | Grouping or state | Best suited for |
|---|---|---|---|
| Splunk SPL | Search, transform, and aggregate | stats ... by / bin |
Ad-hoc hunting, baselines, dashboards |
| Elastic KQL | Fast document filtering | None (filter only) | Triage in Discover, simple alert filters |
| Elastic EQL | Stateful event correlation | sequence by ... with maxspan |
Brute force then success, suspicious process chains |
#Common mistakes
- Filtering late in SPL: running
index=* | search EventCode=4625forces Splunk to retrieve all indexes before discarding unwanted events. Putindex,sourcetype, and static field filters before the first pipe. - Confusing
countanddc: relying solely oncountmisses low-and-slow password spraying, where each username sees only one failed attempt per hour. - Forgetting
bykeys in EQL: omitting the join entity aftersequencelets step 1 match host A and step 2 match host B, producing nonsensical false positives. - Leading wildcards in KQL: queries like
process.command_line: *encoded*force expensive substring scans across unindexed fragments; prefer structured ECS fields or exact tokens whenever available.
#Summary
- Splunk SPL pipes events left-to-right from index selection through time bucketing (
bin), aggregation (stats), and post-aggregation filtering (where). - Distinct counts (
dcin SPL) separate single-account brute force from multi-account password spraying and credential stuffing. - Elastic Security pairs KQL for fast document filtering with EQL for stateful, time-bounded
sequencedetection across shared entities. - Placing strict filters early in SPL and specifying accurate join keys in EQL keeps queries fast and alerts high-signal.