All posts

Automating DNS Threat Detection with Splunk

๐Ÿš€ 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:

  1. Extracts DNS queries from pfSense logs
  2. Uses regex to filter domains
  3. Ignores known safe domains using a cloudflare-radar.csv lookup
  4. 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 #

  1. Save the Query โ†’ Click Save As โ†’ Alert
  2. 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

๐Ÿ’ฌ 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 #

  1. Enable Slack in Splunk (Settings โ†’ Integrations โ†’ Slack)
  2. Set up the webhook URL in Alert Actions
  3. 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! ๐Ÿš€