Skip to content
Threat Feed
medium advisory

Detection of DNS Tunneling via Long and Unique Subdomains

This detection logic identifies potential DNS tunneling activity by monitoring for a high volume of unique, unusually long DNS subdomains directed to the same registered domain within a short timeframe.

DNS tunneling is a technique employed by adversaries to bypass network security controls by encoding data within DNS query labels, enabling covert command-and-control (C2) communication or unauthorized data exfiltration. Because DNS queries are frequently permitted through firewalls and proxies, they provide an ideal covert channel for attackers. This detection strategy focuses on identifying the behavioral artifacts associated with this activity, specifically the generation of numerous, unique, and unusually long subdomains (50+ characters) directed at a single registered apex domain within a five-minute window.

Defenders must differentiate this malicious pattern from legitimate traffic, as cloud-based services, content delivery networks (CDNs), and telemetry reporting mechanisms often utilize dynamic and lengthy hostnames. Effective implementation requires baseline tuning to exclude known-good infrastructure while prioritizing investigations of workstation-to-resolver traffic that demonstrates the characteristic high ratio of unique queries.

Impact

Successful DNS tunneling allows attackers to maintain persistent C2 access and exfiltrate sensitive data while remaining invisible to traditional network monitoring that focuses on common protocols like HTTP or HTTPS. If left undetected, this technique can lead to long-term environment compromise, unauthorized data egress, and the establishment of reliable backdoors that are difficult to disrupt without impacting legitimate DNS resolution services.

Recommendation

  • Deploy the ESQL detection logic provided below to Elastic environments observing endpoint-to-resolver DNS traffic.
  • Establish baselines for internal DNS usage to identify and exclude legitimate traffic from CDNs, cloud providers, and internal network appliances.
  • Investigate alerts by pivoting on Esql.client_ip and Esql.dns_registered_domain to determine if the activity originates from a single workstation or a shared recursive resolver.
  • Inspect Esql.dns_question_type_values for high counts of TXT, NULL, CNAME, or MX records, which are frequently used in tunneling implementations.

Immediate actions

Deploy the ESQL query to identify potential DNS tunneling artifacts

Detection Engineering 72h

Threat Hunt

Search for high-volume, long-label DNS queries from internal workstations

T1071.004 high high confidence hunt now

Data: DNS query logs

Enrichment needed

  • Domain reputation for apex domains flagged by the rule (CTI) Reduce false positives from legitimate cloud services

Mitigations

Implement blocklists for confirmed malicious apex domains

medium_term IT Operations

T1071.004