Potential DNS Tunneling via Long and Unique Subdomains

Last updated 7 days ago on 2026-08-20
Created 7 days ago on 2026-08-20

About

Identifies a client generating many unique, unusually long DNS query names to the same registered domain within a five-minute window. Malware DNS tunnels and DNS command-and-control commonly encode data in lengthy subdomain portions under one apex domain.
Tags
Domain: NetworkUse Case: Threat DetectionUse Case: Network Security MonitoringRule Type: ESQLTactic: Command and ControlTactic: ExfiltrationData Source: Network Packet CaptureData Source: Network TrafficData Source: ZeekLanguage: esql
Severity
medium
Risk Score
47
MITRE ATT&CK™

Command and Control (TA0011)(external, opens in a new tab or window)

Exfiltration (TA0010)(external, opens in a new tab or window)

False Positive Examples
CDN, cloud load-balancer, software-update, and telemetry hostnames can be long and change often. Recursive resolvers, forwarders, NAT gateways, and localhost DNS listeners can also combine queries from many endpoints under one client address. Validate the apex domain and whether the source is an endpoint before treating the activity as tunneling.
License
Elastic License v2(external, opens in a new tab or window)

Definition

Integration Pack
Prebuilt Security Detection Rules
Related Integrations

network_traffic(external, opens in a new tab or window)

zeek(external, opens in a new tab or window)

Query
text code block:
from logs-network_traffic.dns-*, logs-zeek.dns-*, packetbeat-* | where ( data_stream.dataset in ("network_traffic.dns", "zeek.dns") or event.dataset == "dns" ) and dns.question.name is not null and dns.question.registered_domain is not null | eval Esql.client_ip = COALESCE(client.ip, source.ip), Esql.dataset = COALESCE(data_stream.dataset, event.dataset), Esql.dns_question_name = TO_LOWER(dns.question.name), Esql.dns_registered_domain = TO_LOWER(dns.question.registered_domain), Esql.dns_question_type = TO_LOWER(dns.question.type), Esql.subdomain_length = LENGTH(Esql.dns_question_name) - LENGTH(Esql.dns_registered_domain) - 1 | where Esql.client_ip is not null and Esql.subdomain_length >= 50 and (Esql.dns_question_type is null or Esql.dns_question_type != "ptr") and not ENDS_WITH(Esql.dns_question_name, ".arpa") | eval Esql.time_window = DATE_TRUNC(5 minutes, @timestamp) | stats Esql.count_queries = COUNT(*), Esql.count_distinct_names = COUNT_DISTINCT(Esql.dns_question_name), Esql.max_subdomain_length = MAX(Esql.subdomain_length), Esql.avg_subdomain_length = AVG(Esql.subdomain_length), Esql.dns_question_type_values = MV_SLICE(VALUES(Esql.dns_question_type), 0, 9), Esql.destination_ip_values = MV_SLICE(VALUES(destination.ip), 0, 4), Esql.sample_names = MV_SLICE(VALUES(Esql.dns_question_name), 0, 4), Esql.dataset_values = MV_SLICE(VALUES(Esql.dataset), 0, 9), Esql.observer_name_values = MV_SLICE(VALUES(observer.name), 0, 19), Esql.first_seen = MIN(@timestamp), Esql.last_seen = MAX(@timestamp) by Esql.time_window, Esql.client_ip, Esql.dns_registered_domain | where Esql.count_queries >= 25 and Esql.count_distinct_names >= 15 | eval Esql.unique_name_ratio = TO_DOUBLE(Esql.count_distinct_names) / Esql.count_queries | keep Esql.*

Install detection rules in Elastic Security

Detect Potential DNS Tunneling via Long and Unique Subdomains in the Elastic Security detection engine by installing this rule into your Elastic Stack.

To setup this rule, check out the installation guide for Prebuilt Security Detection Rules(external, opens in a new tab or window).