๐ Automating DNS Threat Detection with Splunk #
Introduction #
Monitoring DNS traffic is a crucial aspect of network security. Malicious actors often use DNS tunneling, command-and-control (C2) domains, and suspicious lookups to evade detection.
In this guide, youโll learn how to create a Splunk search that:
โ
Extracts all DNS queries from pfSense logs
โ
Filters out reputable domains (from Cloudflare Radar)
โ
Displays only questionable domains
โ
Sends daily alerts via Slack and Email
๐ Splunk Search to Detect Questionable DNS Queries #
We will build a Splunk query that:
- Extracts DNS queries from
pfSenselogs - Uses regex to filter domains
- Ignores known safe domains using a
cloudflare-radar.csvlookup - Sorts and displays the most queried questionable domains
๐ Splunk Query #
index=pfsense sourcetype=unbound "query"
| rex field=_raw "query\s(?<domain>[\w.-]+)\.\s(?<query_type>\w+)\sIN$"
| eval base_domain=lower(replace(domain, "^(?:.*\.)?([^.]+\.[^.]+)$", "\1"))
| lookup cloudflare-radar.csv domain AS base_domain OUTPUT domain AS is_reputable
| where isnull(is_reputable)
| stats count by domain
| sort - count
| head 20
| eval formatted_output="๐น *Domain:* " . domain . " | ๐ *Count:* " . count
๐ Explanation of Query #
- Extracts queried domains using regex (
rex) - Removes subdomains, keeping only base domains
- Filters out known safe domains using a lookup table (Cloudflare Radar list)
- Displays only questionable domains
- Sorts by the most frequently queried domains
๐ Creating a Splunk Alert #
Now, let’s set up a Splunk alert that runs daily at 23:05 and sends results via Slack and Email.
๐ Steps to Create the Alert #
- Save the Query โ Click Save As โ Alert
- Set the Trigger Conditions:
- Cron Schedule:
5 23 * * *(Runs daily at 11:05 PM) - Trigger When: Number of Results > 0
- Send To: Slack, Email
- Attach Results: Include top 20 domains
- Cron Schedule:
๐ฌ Sending Alert to Slack #
To format the Slack alert, we use Splunk’s alert actions:
๐ Slack Message Body #
{
"text": "๐จ *[ALERT] Daily Top 20 Questionable DNS Queries* ๐จ\n\nThe following domains were queried frequently but are NOT in our reputable list (cloudflare-radar.csv):\n\n%result%\n\n๐ *Action Required:*\nInvestigate these domains and take necessary action.\n\nCheck Splunk for more details: [Insert Dashboard Link]"
}
๐ Setting Up Slack Integration #
- Enable Slack in Splunk (Settings โ Integrations โ Slack)
- Set up the webhook URL in Alert Actions
- Use the above message format for structured alerts
๐ง Email Alert Configuration #
For email notifications, use the following message:
๐ Email Subject #
๐จ [ALERT] Daily Top 20 Questionable DNS Queries ๐จ
๐ Email Body #
Hello Team,
Here is the daily report of the top 20 most queried questionable domains detected on the network:
%result%
These domains were queried but are NOT listed in our reputable domains list (cloudflare-radar.csv). Please review the list and investigate if necessary.
๐ Need More Details?
Check Splunk Dashboard โ [Insert Dashboard Link]
Best,
Security Operations Team
๐ฏ Final Thoughts #
By automating DNS monitoring in Splunk, you can:
โ
Detect malicious queries before they cause harm
โ
Ignore known good traffic (reducing false positives)
โ
Receive daily alerts via Slack & Email
โ
Quickly investigate suspicious activity
๐ Next Steps #
- Add threat intelligence feeds to cross-check domains
- Automate response actions (block, notify admins)
- Visualize DNS query trends in Splunk dashboards
๐ Stay Secure & Keep Monitoring! ๐