Detect DNS in Splunk
Adversaries may communicate using the Domain Name System (DNS) application layer protocol to avoid detection/network filtering by blending in with existing traffic. Commands to the remote system, and often the results of those commands, will be embedded within the protocol traffic between the client and server. The DNS protocol serves an administrative function in computer networking and thus may be very common in environments. DNS traffic may also be allowed even before network authentication is completed. Often known as DNS tunneling, adversaries may abuse DNS to communicate with systems under their control within a victim network while also mimicking normal, expected traffic. DNS beaconing may be used to send commands to remote systems via DNS queries. The commands may be embedded into different DNS records, for example, TXT or A records.
MITRE ATT&CK
- Tactic
- Command and Control
- Technique
- T1071 Application Layer Protocol
- Sub-technique
- T1071.004 DNS
- Canonical reference
- https://attack.mitre.org/techniques/T1071/004/
SPL Detection Query
index=dns sourcetype IN ("stream:dns", "microsoft:windows:dns", "infoblox:dns", "pi-hole")
(query_type IN ("TXT", "NULL", "CNAME", "MX", "A", "AAAA"))
| eval DomainLength=len(query)
| eval SubdomainParts=mvcount(split(query, "."))
| eval TopDomain=mvindex(split(query, "."), -2)
| where DomainLength > 50 OR SubdomainParts > 5
| stats count as QueryCount, dc(query) as UniqueSubdomains, avg(DomainLength) as AvgDomainLength, max(DomainLength) as MaxDomainLength, values(query_type) as QueryTypes, earliest(_time) as FirstSeen, latest(_time) as LastSeen by src_ip, TopDomain
| where QueryCount > 20 AND UniqueSubdomains > 10 AND AvgDomainLength > 40
| eval TunnelConfidence=case(
UniqueSubdomains > 100 AND AvgDomainLength > 60, "high",
UniqueSubdomains > 50 AND AvgDomainLength > 50, "high",
1=1, "medium")
| eval BytesEstimate=round(UniqueSubdomains * (AvgDomainLength - len(TopDomain) - 1))
| table FirstSeen, LastSeen, src_ip, TopDomain, QueryCount, UniqueSubdomains, AvgDomainLength, MaxDomainLength, QueryTypes, TunnelConfidence, BytesEstimate
| sort - QueryCount Detects DNS tunneling and DNS-based C2 by analyzing query patterns for long domain names, high unique subdomain counts, and excessive query volumes to single parent domains. Estimates data transfer volume based on subdomain encoding capacity. Known malware using DNS C2 includes Cobalt Strike (DNS beacon), Sliver, Anchor, BONDUPDATER, and WellMess. Supports multiple DNS log sources including Sysmon DNS, Infoblox, and Pi-hole.
Data Sources
Required Sourcetypes
False Positives & Tuning
- Content Delivery Networks (CDNs) and anti-DDoS services that use long subdomain strings for routing (e.g., Akamai, Cloudflare)
- Email security services (DKIM, SPF, DMARC) that generate long TXT record queries
- Certificate validation services performing OCSP and CRL checks with encoded certificate data
- Antivirus and threat intelligence services that encode file hashes in DNS queries for reputation lookups
Other platforms for T1071.004
Testing Methodology
Validate this detection against 3 adversary techniques from Atomic Red Team. Each test below lists the behaviour to exercise and the telemetry you should expect to see. Executable commands and cleanup steps are available with Pro.
- Test 1DNS TXT Record Tunneling Simulation
Expected signal: DNS query logs showing 20 TXT record queries to unique subdomains under c2test.localhost with base32-encoded subdomain prefixes. Sysmon Event ID 22 (if available) showing dig process making DNS queries.
- Test 2DNS Beaconing via nslookup
Expected signal: Sysmon Event ID 22: DNS Query for each nslookup execution with QueryName containing COMPUTERNAME and random values under beacon.localhost. Sysmon Event ID 1: nslookup.exe process creation. 10 queries at 5-second intervals.
- Test 3High-Volume DNS Query Burst
Expected signal: DNS query logs showing 100 A record queries to unique 30-character random subdomains under exfil.localhost in rapid succession. Total estimated data capacity: ~3KB encoded in subdomain labels.
References (7)
- https://attack.mitre.org/techniques/T1071/004/
- https://www.paloaltonetworks.com/cyberpedia/what-is-dns-tunneling
- https://medium.com/@galolbardes/learn-how-easy-is-to-bypass-firewalls-using-dns-tunneling-and-also-how-to-block-it-3ed652f4a000
- https://unit42.paloaltonetworks.com/unit42-oilrig-uses-updated-bondupdater-target-middle-eastern-government/
- https://github.com/redcanaryco/atomic-red-team/blob/master/atomics/T1071.004/T1071.004.md
- https://github.com/iagox86/dnscat2
- https://github.com/yarrick/iodine
Unlock Pro Content
Get the full detection package for T1071.004 including response playbook, investigation guide, and atomic red team tests.