โญ Day 14 โ Log Enrichment, Field Extraction & Metadata
Today students learn how to transform raw logs โ structured data โ security meaning in Splunk.
This is VERY important because:
- SIEM alerts depend on correct fields
- Threat hunting depends on good field extraction
- Dashboards depend on structured data
- MITRE mapping depends on knowing what each field means
๐ง 1. What Is Log Enrichment? (Simple Explanation)
Log Enrichment = adding extra security context to raw logs.
Before enrichment:
IP=192.168.1.50
After enrichment:
IP=192.168.1.50
GeoLocation=India
Reputation=Malicious
User=tom
DeviceType=Windows10
This makes detection and hunting much easier.
๐ฅ 2. Why Field Extraction Matters?
Field Extraction = splitting raw logs into readable fields.
Example raw log:
Failed password for root from 10.0.0.5 port 4588
Splunk extracts:
- user = root
- src_ip = 10.0.0.5
- port = 4588
- action = failed password
This allows queries like:
stats count by src_ip
๐งฑ 3. Three Types of Fields Every SOC Analyst Must Know
A. Source
Where logs came from.
Examples:
- WinEventLog:Security
- /var/log/auth.log
- firewall logs
B. Sourcetype
What type of log it is.
Examples:
- WinEventLog:System
- linux_secure
- Sysmon
C. Fields
Actual extracted data:
- user
- IP
- port
- status
- command
- EventCode
Understanding these transforms raw logs into security detection.
๐ 4. Splunk Tools for Field Extraction
โ Field Extractor (UI tool)
Go to:
Settings โ Fields โ Field Extractions
Upload sample logs โ highlight โ Splunk generates regex.
โ Field Discovery
In search bar:
index=*
Then click on Fields (left side)
โ Shows auto-detected fields.
โ Rex Command
Manual extraction:
| rex "Failed password for (?<user>\w+) from (?<src_ip>\d+\.\d+\.\d+\.\d+)"
This creates user and src_ip fields.
โ๏ธ 5. Sample Field Extraction for Linux Logs
Raw log:
Failed password for root from 10.0.0.5 port 4588
Splunk rex:
| rex "Failed password for (?<user>\w+) from (?<src_ip>\S+) port (?<port>\d+)"
Now you can run:
stats count by src_ip
โ๏ธ 6. Sample Field Extraction for Windows Logs
Windows logs already have fields, such as:
- Account_Name
- Workstation_Name
- Logon_Type
- IpAddress
But you can extract extra fields.
Example:
| rex "Account Name:\s+(?<account>\S+)"
๐งฉ 7. Log Enrichment Techniques
โ Add GeoIP info
| iplocation IpAddress
Adds:
- City
- Country
- Region
- Latitude/Longitude
โ Add threat intel reputation
If you have threat feeds:
| lookup bad_ips ip OUTPUT reputation
โ Add device type
| lookup device_inventory host OUTPUT device_type
Useful for:
- identifying servers
- identifying critical systems
๐ 8. Hands-On Lab (Day 14)
Task 1 โ Extract Linux fields
index=* "Failed password"
| rex "Failed password for (?<user>\w+) from (?<ip>\S+)"
| stats count by user, ip
Task 2 โ Extract Windows fields manually
index=* EventCode=4624
| rex "Logon Type:\s+(?<logtype>\d+)"
| stats count by logtype
Task 3 โ Add GeoIP enrichment
index=* IpAddress=*
| iplocation IpAddress
| table IpAddress Country City
Task 4 โ Create enriched dashboard panel
Panel shows:
- IP
- Country
- City
- Count
index=* IpAddress=*
| iplocation IpAddress
| stats count by IpAddress, Country, City
Task 5 โ Extract suspicious PowerShell commands
index=* powershell "EncodedCommand"
| rex "CommandLine:\s+(?<cmd>.+)"
| table _time user cmd
๐ค Trainer Script
Say this:
โField extraction converts raw logs into intelligence.
Enrichment adds context โ country, device type, risk.
A SOC analyst must understand fields to build detections and dashboards.โ
๐ Homework (Day 14)
Students must extract:
- IP
- User
- Port
- Action
From one log of their choice, AND:
- Write MITRE technique
- Write one enriched dashboard query
Leave a comment