// 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 | Command | Purpose | Example |
|---|---|---|
| search | Filter events | EventCode=4625 |
| stats | Aggregate data | stats count by user |
| eval | Create/modify fields | eval hour=strftime(_time,'%H') |
| rex | Extract fields with regex | rex field=msg '(?P |
| lookup | Enrich with external data | lookup threat_intel src_ip OUTPUT reputation |
| join | Combine two searches | join src_ip [search index=proxy] |
| timechart | Time-series charting | timechart span=1h count by EventCode |
| transaction | Group related events | transaction 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, successessplunk — 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 Name | MITRE Technique |
|---|---|---|
| 1 | Failed Logins Spike | T1110 — Brute Force |
| 2 | PowerShell EncodedCommand | T1059.001 — PowerShell |
| 3 | New Scheduled Task | T1053.005 — Scheduled Task |
| 4 | New Service Installation | T1543.003 — Windows Service |
| 5 | LSASS Access (Mimikatz) | T1003.001 — LSASS Memory |
| 6 | Kerberoasting (RC4 TGS) | T1558.003 — Kerberoasting |
| 7 | Shadow Copy Deletion | T1490 — Inhibit System Recovery |
| 8 | Mass File Rename | T1486 — Data Encrypted for Impact |
| 9 | DNS Beaconing | T1048.003 — DNS Exfiltration |
| 10 | Lateral Movement via PsExec | T1021.002 — SMB/Admin Shares |
| 11 | New Local Admin Created | T1136.001 — Local Account |
| 12 | Outbound on Uncommon Port | T1571 — Non-Standard Port |
| 13 | DLL Side-Loading | T1574.002 — DLL Side-Loading |
| 14 | WMI Remote Execution | T1047 — WMI |
| 15 | Data Staging to Temp Dir | T1074.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