Automation February 2025 12 min read

Splunk SPL for SOC Analysts: A Field Guide

A practical reference for writing effective Splunk SPL queries in a SOC context — from basic search syntax through advanced correlation, macros, and the 15 queries every analyst should know by heart.

Published
Author: Sid Faza Category: Automation
// 01

SPL Basics — Search Fundamentals

Splunk Processing Language (SPL) is the query language for searching, analysing, and visualising data in Splunk. Every SOC query starts with a search command, then pipes data through transformation commands.

splunk — Basic Syntax Pattern
| Basic search structure:
index= sourcetype=  =
| command1 
| command2 

| Example: Find all failed logins on Windows in last 24h
index=windows EventCode=4625 earliest=-24h
| stats count by src_ip, user, ComputerName
| sort -count
| head 20
CommandPurposeExample
searchFilter eventsEventCode=4625
statsAggregate datastats count by user
evalCreate/modify fieldseval hour=strftime(_time,'%H')
rexExtract fields with regexrex field=msg '(?P\d+\.\d+\.\d+\.\d+)'
lookupEnrich with external datalookup threat_intel src_ip OUTPUT reputation
joinCombine two searchesjoin src_ip [search index=proxy]
timechartTime-series chartingtimechart span=1h count by EventCode
transactionGroup related eventstransaction src_ip maxspan=5m
// 02

Working with Fields

splunk — Field Extraction & Manipulation
| Extract IP from free-text message field
index=firewall action=blocked
| rex field=_raw "src=(?P\d{1,3}(\.\d{1,3}){3})"

| Calculate session duration in minutes
index=vpn action=connected
| eval duration_min=round((disconnect_time - connect_time)/60, 2)

| Categorise by time of day
| eval hour=tonumber(strftime(_time, "%H"))
| eval period=case(hour>=8 AND hour<18,"business","after-hours")

| Rename and clean up output
| rename src_ip AS "Source IP", user AS "Username"
| fields "Source IP", Username, ComputerName, duration_min
// 03

Stats, Aggregation & Top Commands

splunk — Aggregation Examples
| Count events by multiple fields
index=windows EventCode=4624
| stats count, dc(src_ip) AS unique_ips, values(LogonType) AS logon_types by user

| Find statistical outliers — 3x standard deviation from mean
index=proxy
| stats avg(bytes) AS avg_bytes, stdev(bytes) AS sd by dest_host
| eval threshold = avg_bytes + (3 * sd)
| where bytes > threshold

| Percentage of events by category
index=firewall
| stats count by action
| eventstats sum(count) AS total
| eval pct = round(count/total*100, 1)
// 04

Time-Based Analysis

splunk — Time Window Hunting
| Compare this week vs last week
index=windows EventCode=4625
| timechart span=1d count AS this_week
| appendcols
  [search index=windows EventCode=4625 earliest=-14d latest=-7d
   | timechart span=1d count AS last_week]

| Find activity outside business hours (before 8am, after 8pm)
index=windows EventCode=4624
| eval hour=tonumber(strftime(_time,"%H"))
| where hour < 8 OR hour >= 20
| stats count by user, ComputerName, hour
| sort -count
// 05

Correlation Queries

splunk — Failed then Successful Login (Brute Force)
| Detect: 5+ failures followed by success from same IP
index=windows EventCode=4625 earliest=-1h
| stats count AS failures by src_ip, user
| where failures >= 5
| join src_ip
  [search index=windows EventCode=4624 earliest=-1h
   | stats count AS successes by src_ip, user]
| where successes >= 1
| table src_ip, user, failures, successes
splunk — Beaconing Detection (Regular C2 Intervals)
| Find: connections to same external IP at regular intervals
index=proxy earliest=-24h
| bucket _time span=1h
| stats count by _time, dest_host, src_ip
| stats count AS intervals, stdev(count) AS regularity by dest_host, src_ip
| where intervals >= 18 AND regularity < 2
| Low stdev = very regular intervals = beaconing pattern
// 06

15 Essential SOC Queries

#Query NameMITRE Technique
1Failed Logins SpikeT1110 — Brute Force
2PowerShell EncodedCommandT1059.001 — PowerShell
3New Scheduled TaskT1053.005 — Scheduled Task
4New Service InstallationT1543.003 — Windows Service
5LSASS Access (Mimikatz)T1003.001 — LSASS Memory
6Kerberoasting (RC4 TGS)T1558.003 — Kerberoasting
7Shadow Copy DeletionT1490 — Inhibit System Recovery
8Mass File RenameT1486 — Data Encrypted for Impact
9DNS BeaconingT1048.003 — DNS Exfiltration
10Lateral Movement via PsExecT1021.002 — SMB/Admin Shares
11New Local Admin CreatedT1136.001 — Local Account
12Outbound on Uncommon PortT1571 — Non-Standard Port
13DLL Side-LoadingT1574.002 — DLL Side-Loading
14WMI Remote ExecutionT1047 — WMI
15Data Staging to Temp DirT1074.001 — Local Data Staging
💡 Pro Tip

Save all 15 queries as Splunk saved searches with scheduled alerts. This gives you a permanent detection baseline while you build more sophisticated correlation rules.

// 07

Performance Tips

  • Always specify the index — searching `index=*` is 10–100x slower
  • Use the most restrictive filter first — EventCode before keyword searches
  • Use tstats for high-volume aggregation — 5–10x faster than stats for index-level metadata
  • Avoid rex on high-volume searches — extract fields at index time with props.conf transforms
  • Joins are expensive — use lookup or appendcols where possible instead of join
  • Set realistic time windows — if hunting the last 7 days, don't search 90 days by accident