T1071.004 Elastic Security · Elastic

Detect DNS in Elastic Security

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/

Elastic Detection Query

Elastic Security (Elastic)
eql
FROM logs-network_traffic.dns-*, logs-zeek.dns-*, logs-dns-*
| WHERE event.category == "network" AND network.protocol == "dns"
| WHERE dns.question.type IN ("TXT", "NULL", "CNAME", "MX", "A", "AAAA")
| EVAL domain_length = LENGTH(dns.question.name)
| EVAL subdomain_parts = MV_COUNT(SPLIT(dns.question.name, "."))
| WHERE domain_length > 50 OR subdomain_parts > 5
| STATS
    query_count = COUNT(*),
    unique_subdomains = COUNT_DISTINCT(dns.question.name),
    avg_domain_length = AVG(domain_length),
    max_domain_length = MAX(domain_length),
    query_types = VALUES(dns.question.type),
    first_seen = MIN(@timestamp),
    last_seen = MAX(@timestamp)
    BY source.ip
| WHERE query_count > 20 AND unique_subdomains > 10 AND avg_domain_length > 40
| EVAL tunnel_confidence = CASE(
    unique_subdomains > 100 AND avg_domain_length > 60, "high",
    unique_subdomains > 50 AND avg_domain_length > 50, "high",
    "medium"
  )
| SORT query_count DESC
high severity medium confidence

Detects DNS tunneling (T1071.004) using Elastic ES|QL aggregation over DNS log events. Identifies source IPs generating high volumes of anomalously long DNS queries with high subdomain name uniqueness — characteristic of DNS C2 beaconing or data exfiltration via TXT, CNAME, or NULL record tunneling. Run as a scheduled ES|QL detection rule or in Discover over a sliding 24h window. Requires DNS log ingestion via Elastic Agent, Zeek, or Packetbeat.

Data Sources

Elastic Agent Network Packet Capture (DNS)Zeek DNS logs via FilebeatPacketbeat DNS moduleWindows DNS Debug Logs via Elastic Agent

Required Tables

logs-network_traffic.dns-*logs-zeek.dns-*logs-dns-*

False Positives & Tuning

  • CDN providers such as Akamai, Cloudflare, and Fastly use long base64-encoded subdomains for origin selection and TLS routing — filter on known CDN apex domains (e.g., akamaiedge.net, cloudfront.net) using an allowlist enrichment step
  • Software update services and antivirus cloud lookups (Windows Update, Symantec LiveUpdate, CrowdStrike) generate high-frequency queries to vendor domains with embedded device or version identifiers encoded in subdomains
  • Internal Kubernetes or Consul service mesh DNS resolution produces many unique FQDN queries per source IP as pods resolve service names — especially during deployment scaling or rolling restarts
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