T1071.004

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.

Microsoft Sentinel / Defender
kusto
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
critical severity high confidence

Data Sources

Network Traffic: Network Traffic Content Network Traffic: Network Traffic Flow DNS Logs

Required Tables

DnsEvents

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

Unlock Pro Content

Get the full detection package for T1071.004 including response playbook, investigation guide, and atomic red team tests.

Response PlaybookInvestigation GuideHunting QueriesAtomic Red Team TestsTuning Guidance

Related Detections