T1071.004 Microsoft Sentinel · KQL

Detect DNS in Microsoft Sentinel

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/

KQL Detection Query

Microsoft Sentinel (KQL)
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

Detects DNS tunneling by identifying queries with abnormally long domain names, high subdomain counts, and large numbers of unique subdomains to the same parent domain. DNS tunneling tools (iodine, dnscat2, dns2tcp) and C2 frameworks (Cobalt Strike, Sliver, Mythic) encode data in the subdomain portion of DNS queries, resulting in long, high-entropy domain names. Also flags TXT and NULL record queries commonly used for DNS-based data transfer.

Data Sources

Network Traffic: Network Traffic ContentNetwork Traffic: Network Traffic FlowDNS Logs

Required Tables

DnsEvents

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
Download portable Sigma rule (.yml)

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.

  1. 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.

  2. 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.

  3. 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.

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