Courses3 levels
Level 1 · Foundations11 courses
Level 2 · Core5 courses
Level 3 · Advanced5 courses
Labs8 topics
Library Practice exams AI Range Pricing Start free

Practice library / Security operations basics

Lab · Medium · 1.5 hoursFree account

Threat Detection with Splunk

Write SPL queries, build dashboards, and create detection rules in Splunk.

  • splunk
  • spl
  • siem
  • detection
  • windows-logs
On this page 13 sections
  1. ·Prerequisites
  2. ·Lab Setup
  3. 1Install Splunk and create an index
  4. 2Build the sample dataset and load it
  5. Locked: Find the password spray
  6. Locked: Join the spray to a successful logon
  7. Locked: Find Kerberoasting
  8. Locked: Find an Office program that starts PowerShell
  9. Locked: Find account changes and a cleared log
  10. Locked: Save the correlation search as an alert
  11. Locked: Defence and Detection
  12. Locked: Check Your Work
  13. Locked: Clean-up

A SIEM stores logs by the billion, but only a precise SPL search finds the attacker inside them. Splunk pays off when an analyst can shape events into the right question: one source against many accounts, one account against many service tickets, Word launching a shell. You load a small Windows dataset with a hidden intrusion, write the searches that catch each stage, and save the best one as a scheduled alert.

What You'll Learn

  • Install Splunk Enterprise on a lab VM, create an index and load a sample dataset
  • Write SPL searches that find a password spray, Kerberoasting and an Office macro attack
  • Join two searches with a subsearch to find a successful logon from a spraying source
  • Find privileged account changes and a cleared audit log
  • Save a search as a scheduled alert with a threshold and throttling

A SIEM is only as good as its searches. Splunk stores the logs, but you must ask the right question. This lab walks you through building a small Windows dataset with one hidden attack in it. You write the searches that find each stage, then turn the best search into an alert.

You work as a defender. You load data into your own Splunk and search it. Nothing in this lab touches a real network.

Prerequisites

Finish the SOC Operations & SIEM workbook first. It explains log sources, alerts and triage.

This lab reads Windows event IDs such as 4625 and 4769. To learn what each event means, use Windows Event Log Analysis. To see the attacks from the attacker side, use Windows Attacks & Defence.

Lab Setup

Use a lab VM that you control. Your own Kali machine works. You need:

  1. Splunk Enterprise 9.x or later for Linux (.tgz package). Download it from the Splunk website. A free Splunk account is required.
  2. About 2 GB of free disk space and 4 GB of RAM.
  3. A web browser on the same VM.

Splunk Enterprise runs in trial mode for 60 days and indexes up to 500 MB per day. The lab data is a few kilobytes.

The dataset is synthetic. You build it in Step 2 from a script. It uses the lab domain CORP.LOCAL and the network 10.0.0.0/8. The attack happens on 12 November 2026.

Use this Splunk only for the lab data. Do not run a trial Splunk as a production service. On a real network, Splunk runs under a service account, and you need written permission to read the logs of other people.

Step 1: Install Splunk and create an index

1

Start Splunk and make an index for the lab

An index is a store of events. A separate index for the lab keeps its data apart from anything else. Splunk uses port 8000 for the web interface and port 8089 for the management API.

Unpack the package into /opt. Replace the file name with the name of your download.

cd ~/Downloads
sudo tar -xzf splunk-*-linux-amd64.tgz -C /opt
sudo chown -R "$USER" /opt/splunk
/opt/splunk/bin/splunk start --accept-license

Splunk asks you to create an administrator name and password. Use admin and a password that you do not use anywhere else. Example output at the end of the start:

Waiting for web server at http://127.0.0.1:8000 to be up...
The Splunk web interface is at http://kali:8000

Create the index.

/opt/splunk/bin/splunk add index winlab -auth admin

Example output:

Password:
Index "winlab" added.

Open http://127.0.0.1:8000 in the browser and sign in. Then set the time zone, so that your times match the times in this lab. Select your name, then Preferences, then set Time zone to UTC.

Step 2: Build the sample dataset and load it

2

Create 55 Windows events and index them

The script writes one event per line. Each line starts with an ISO 8601 time, followed by key=value pairs. Splunk finds the time and the fields by itself. Most of the events are normal work on 11 November. A few events are the attack on 12 November.

Create the folder and the file with the normal events first.

mkdir -p ~/splunk-lab && cd ~/splunk-lab
: > winsec.log
users=(alice bob carol dave)
for i in $(seq 0 19); do
  u=${users[$((i % 4))]}
  printf '2026-11-11T%02d:%02d:00Z Computer=WS01 EventCode=4624 Account_Name=%s Source_Network_Address=10.0.0.%d Logon_Type=%d\n' \
    $((8 + i / 3)) $(((i * 7) % 60)) "$u" $((21 + i % 4)) $((2 + i % 2)) >> winsec.log
done
echo '2026-11-11T09:14:30Z Computer=DC01 EventCode=4625 Account_Name=bob Source_Network_Address=10.0.0.22 Logon_Type=3' >> winsec.log
for i in 1 2 3 4 5 6; do
  printf '2026-11-11T10:%02d:00Z Computer=DC01 EventCode=4769 Account_Name=%s Service_Name=fileserver$ Ticket_Encryption_Type=0x12\n' \
    $((i * 5)) "${users[$((i % 4))]}" >> winsec.log
done

Add four normal process events.

cat >> winsec.log <<'EOT'
2026-11-11T08:05:12Z Computer=WS01 EventCode=4688 Account_Name=alice Process_Name="C:\Windows\explorer.exe" Parent_Process_Name="C:\Windows\System32\userinit.exe" Command_Line="C:\Windows\explorer.exe"
2026-11-11T08:20:41Z Computer=WS01 EventCode=4688 Account_Name=alice Process_Name="C:\Program Files\Google\Chrome\chrome.exe" Parent_Process_Name="C:\Windows\explorer.exe" Command_Line="chrome.exe --profile-directory=Default"
2026-11-11T09:02:03Z Computer=WS01 EventCode=4688 Account_Name=bob Process_Name="C:\Windows\System32\cmd.exe" Parent_Process_Name="C:\Windows\explorer.exe" Command_Line="cmd.exe"
2026-11-11T09:02:20Z Computer=WS01 EventCode=4688 Account_Name=bob Process_Name="C:\Windows\System32\ipconfig.exe" Parent_Process_Name="C:\Windows\System32\cmd.exe" Command_Line="ipconfig /all"
EOT

Add the attack events. Do not read them yet. You find them with SPL in the next steps.

for round in 1 2; do
  n=0
  for u in admin administrator backup svc_backup sqlsvc helpdesk; do
    printf '2026-11-12T01:58:%02dZ Computer=DC01 EventCode=4625 Account_Name=%s Source_Network_Address=10.0.0.50 Logon_Type=3\n' \
      $(((round - 1) * 12 + n * 2)) "$u" >> winsec.log
    n=$((n + 1))
  done
done
cat >> winsec.log <<'EOT'
2026-11-12T02:00:02Z Computer=DC01 EventCode=4624 Account_Name=svc_backup Source_Network_Address=10.0.0.50 Logon_Type=3
2026-11-12T02:01:15Z Computer=DC01 EventCode=4769 Account_Name=svc_backup Service_Name=MSSQLSvc/db01.corp.local:1433 Ticket_Encryption_Type=0x17
2026-11-12T02:01:16Z Computer=DC01 EventCode=4769 Account_Name=svc_backup Service_Name=HTTP/web01.corp.local Ticket_Encryption_Type=0x17
2026-11-12T02:01:16Z Computer=DC01 EventCode=4769 Account_Name=svc_backup Service_Name=CIFS/files01.corp.local Ticket_Encryption_Type=0x17
2026-11-12T02:01:17Z Computer=DC01 EventCode=4769 Account_Name=svc_backup Service_Name=FTP/ftp01.corp.local Ticket_Encryption_Type=0x17
2026-11-12T02:01:17Z Computer=DC01 EventCode=4769 Account_Name=svc_backup Service_Name=MSSQLSvc/db02.corp.local:1433 Ticket_Encryption_Type=0x17
2026-11-12T02:03:10Z Computer=WS01 EventCode=4688 Account_Name=svc_backup Process_Name="C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" Parent_Process_Name="C:\Program Files\Microsoft Office\root\Office16\WINWORD.EXE" Command_Line="powershell.exe -nop -w hidden -enc RwBlAHQALQBEAGEAdABlAA=="
2026-11-12T02:03:15Z Computer=WS01 EventCode=4688 Account_Name=svc_backup Process_Name="C:\Windows\System32\whoami.exe" Parent_Process_Name="C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" Command_Line="whoami /all"
2026-11-12T02:03:20Z Computer=WS01 EventCode=4688 Account_Name=svc_backup Process_Name="C:\Windows\System32\net.exe" Parent_Process_Name="C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" Command_Line="net group Domain Admins /domain"
2026-11-12T02:06:30Z Computer=DC01 EventCode=4720 Subject_Account_Name=svc_backup Target_Account_Name=helpdesk2
2026-11-12T02:06:45Z Computer=DC01 EventCode=4732 Subject_Account_Name=svc_backup Target_Account_Name=helpdesk2 Group_Name=Administrators
2026-11-12T02:10:00Z Computer=DC01 EventCode=1102 Subject_Account_Name=svc_backup Message="The audit log was cleared"
EOT
wc -l winsec.log

Example output:

55 winsec.log

Load the file into the winlab index. Use a new source type name, winsec_lab.

/opt/splunk/bin/splunk add oneshot ~/splunk-lab/winsec.log -index winlab -sourcetype winsec_lab -auth admin

Example output:

Password:
Oneshot '/home/kali/splunk-lab/winsec.log' added

Open Search & Reporting in the browser. Set the time range picker to All time. Run this search to count the events by event ID.

index=winlab | stats count by EventCode | sort - count

Example output:

EventCode   count
4624        21
4625        13
4769        11
4688        7
1102        1
4720        1
4732        1

The total is 55, the same as wc -l. If a number is different, the load is wrong: look at Settings, then Indexes, and check the event count of winlab. To load again, run splunk clean eventdata -index winlab -f (Splunk must be stopped first) and repeat the add oneshot command.

In the Fields list on the left, find Account_Name, Computer and Source_Network_Address. Splunk made them from the key=value pairs.

Sign in to continue

9 more sections are for signed-in members. It is free: sign in with Google.

Related

This lab is extra practice for the course Security operations basics. Do the lessons first.Open the course