DNS
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.
let TimeWindow = 24h;
let DomainLengthThreshold = 50;
let SubdomainEntropyThreshold = 3.5;
// Detect DNS tunneling via high-entropy, long subdomain queries
DnsEvents
| where TimeGenerated > ago(TimeWindow)
| where QueryType in ("TXT", "NULL", "CNAME", "MX", "A", "AAAA")
| extend DomainLength = strlen(Name)
| extend SubdomainParts = countof(Name, ".")
| extend TopDomain = tostring(split(Name, ".")[-2])
| where DomainLength > DomainLengthThreshold or SubdomainParts > 5
| summarize
QueryCount = count(),
UniqueSubdomains = dcount(Name),
AvgDomainLength = avg(DomainLength),
MaxDomainLength = max(DomainLength),
QueryTypes = make_set(QueryType),
FirstSeen = min(TimeGenerated),
LastSeen = max(TimeGenerated)
by ClientIP, TopDomain
| where QueryCount > 20 and UniqueSubdomains > 10
| where AvgDomainLength > 40
| extend TunnelConfidence = case(
UniqueSubdomains > 100 and AvgDomainLength > 60, "high",
UniqueSubdomains > 50 and AvgDomainLength > 50, "high",
"medium")
| project LastSeen, ClientIP, TopDomain, QueryCount, UniqueSubdomains, AvgDomainLength, MaxDomainLength, QueryTypes, TunnelConfidence
| sort by QueryCount desc Data Sources
Required Tables
False Positives
- 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
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.