Module 16 · SIEM and Log Management · Lesson 47 of 75
Searching and correlating: SPL, KQL and detection logic
Write searches in Splunk SPL and Microsoft KQL, build correlation logic for brute force followed by success, and practise the same logic in Python.
In this lesson · about 45 minutes
- Read and write basic SPL and KQL searches
- Use counts, time windows and thresholds in a detection
- Build a 'brute force then success' correlation
Splunk SPL
index=wineventlog EventCode=4625 earliest=-1h
| stats count AS failures, dc(TargetUserName) AS users BY src_ip
| where failures > 20
| sort - failures
Pipes pass results along, like Bash. stats count BY groups; dc() is a distinct count (many users from one IP suggests password spraying).
Microsoft KQL (Sentinel, Defender)
SigninLogs
| where TimeGenerated > ago(1h) and ResultType != "0"
| summarize failures = count(), users = dcount(UserPrincipalName) by IPAddress
| where failures > 20
| order by failures desc
Correlation: brute force, then success
Failures alone are noise; a success right after many failures from the same source is a likely compromise:
SigninLogs
| where TimeGenerated > ago(1h)
| summarize fails = countif(ResultType != "0"),
wins = countif(ResultType == "0") by UserPrincipalName, IPAddress, bin(TimeGenerated, 10m)
| where fails >= 5 and wins >= 1
Other common detections
- New user added to a privileged group (4728/4732/4756).
- Security log cleared (1102).
- Office app spawning a shell (Sysmon event 1, parent image winword.exe).
- Impossible travel (two logins too far apart for the time between them).
- Large outbound transfer to a new destination.
- Rare process making network connections; first-time admin logon to a server.
Hands-on lab (simulated terminal)
Lab: hunt in Splunk
You are in the Splunk search bar of a lab SIEM loaded with a day of simulated Windows logs. Type each search on one line. Results are simulated.
Step 1 of 3. Type each command and press Enter. Nothing runs on your computer.
1. Find failed logons (EventCode 4625) in index wineventlog and count them by src_ip, highest first.
Exercise
Write the correlation in Python
events is a list of login events (time in seconds, user, ip, result). Write compromised(events, threshold) that returns a sorted list of users who had at least threshold failures and then a success from the same IP.
Code that runs before yours
events = [
{"t": 100, "user": "jsmith", "ip": "203.0.113.45", "result": "fail"},
{"t": 104, "user": "jsmith", "ip": "203.0.113.45", "result": "fail"},
{"t": 109, "user": "jsmith", "ip": "203.0.113.45", "result": "fail"},
{"t": 113, "user": "jsmith", "ip": "203.0.113.45", "result": "fail"},
{"t": 118, "user": "jsmith", "ip": "203.0.113.45", "result": "fail"},
{"t": 121, "user": "jsmith", "ip": "203.0.113.45", "result": "success"},
{"t": 300, "user": "aokafor", "ip": "198.51.100.7", "result": "fail"},
{"t": 305, "user": "aokafor", "ip": "198.51.100.7", "result": "success"},
{"t": 900, "user": "mtanaka", "ip": "192.0.2.15", "result": "fail"},
{"t": 902, "user": "mtanaka", "ip": "192.0.2.15", "result": "fail"},
{"t": 905, "user": "mtanaka", "ip": "192.0.2.15", "result": "fail"},
{"t": 909, "user": "mtanaka", "ip": "192.0.2.15", "result": "fail"},
{"t": 912, "user": "mtanaka", "ip": "192.0.2.15", "result": "fail"},
]Check your understanding0 of 3 correct
Quiz score: 0 of 3
Exercises solved: 0 of 1
Written by Noviq Academy in its own words. All labs are simulations: no real systems are touched, and every name, address, password and hash is made up. The offensive techniques taught here are for defending systems and for authorised testing only; never scan, access or test a system without the owner's written permission. Tool and product names belong to their owners, and command output may differ slightly from yours. Read-aloud uses your device's built-in voices.