DNS Tunneling: An Invisible Threat That Passes Through Corporate Networks

(To Alessandro Rugolo)
03/02/25

In the context of cybersecurity, monitoring and defending against threats from network traffic are crucial to protecting corporate and government infrastructure. Among the advanced attack techniques, the DNS tunneling represents one of the most insidious ways to evade traditional defense systems, exploiting the DNS protocol to channel malicious data through firewall and detection systems or to exfiltrate confidential or sensitive data.

Normally used to translate domain names into IP addresses, DNS can be manipulated to exfiltrate sensitive information or inject malicious commands, going undetected even in the most secure networks.

This article explores the vulnerabilities inherent in the DNS protocol, its potential applications in APT attacks (Advanced Persistent Threat) and the most effective countermeasures to detect and counter these types of threats. Through the analysis of real-world examples and the latest monitoring techniques, we will examine the tools needed to protect modern networks from sophisticated attacks that use DNS as the primary vector.

The technique of DNS tunneling has emerged as a significant threat with the evolution of cyber attacks. A famous example is related to the group APT28, a group associated with compromising government networks, which has often used this attack to exfiltrate data without being detected. Similarly, campaigns of malware how FeederBot and Dnscat2 have exploited this technique to establish persistent communications with command and control (C2) servers.

These attacks demonstrate how DNS, essential to the functioning of the Internet, can become a dangerous channel if used improperly.

Technical explanation of the attack

A DNS tunneling attack exploits the DNS protocol, which is primarily designed for domain name resolution, to transport malicious data or exfiltrate sensitive data in an unauthorized manner.

The DNS protocol, typically used over UDP protocol (User Datagram Protocol), has a structure composed of a header (12 bytes) and several sections, including "Query" and "Answer". The "Name" field in the Query Section and the "Resource Data" field in the Answer Section They are often used to encapsulate data.

The total size of a standard UDP DNS packet is limited to 512 bytes, but a significant portion is occupied by protocol metadata. Therefore, the data that can be transported in a single packet is approximately 200-255 bytes. If DNS over TCP is used (a less common option), the maximum size can be up to 65.535 bytes, but at the cost of increased detection risk.

DNS packet structure:

-----------------------------------

Header : 96 bit

-----------------------------------

Question Section : Variable length

----------------------------------

Answer Section : Variable length

----------------------------------

Authority : Variable length

----------------------------------

Additional : Variable length

----------------------------------

The amount of data transported depends on the packet rate and the transport capacity per packet. In one hour, an attack DNS tunneling A low-intensity attack that sends 10 packets per second can exfiltrate about 7-10 MB of data. More aggressive attacks that increase the number of packets transmitted can transfer up to tens of megabytes, but risk attracting the attention of monitoring systems.

The ability to encode data within DNS traffic, combined with compression and obfuscation techniques, makes DNS tunneling difficult to detect, requiring advanced countermeasures to identify and block it.

In addition to DNS over UDP and DNS over TCP, there are some variants and features of the DNS protocol that allow for larger sizes, such as EDNS (Extension mechanisms for DNS).

With the introduction of EDNS (RFC 6891), it is possible to overcome the 512 byte limit for UDP as well, allowing larger packets (up to 4096 bytes or more, depending on the configuration). This is intended to support advanced features, such as DNSSEC (Domain Name System Security Extensions, security extension), but can be exploited by attackers to increase the data transport capacity of the tunneling without resorting to TCP.

Of course, network configurations, the firewall and advanced monitoring systems can be set up to detect and mitigate anomalous traffic associated with these techniques.

Security implications and how to mitigate the risk

Il DNS tunneling It represents a serious threat to the security of organizations, in fact thanks to its characteristics it allows:

  • data exfiltration: sensitive information can be stolen without warning;
  • bypass defenses: firewall and monitoring systems often do not analyze DNS traffic deeply, which can allow malicious code to be injected into the system;
  • low detectability: DNS Tunneling uses encrypted or obfuscated communications, making it difficult to distinguish legitimate traffic from malicious traffic.

The complexity of the attack means that effective protection requires a combination of tools and best practices, including:

  • advanced monitoring: analyze DNS traffic to identify anomalous patterns, such as excessive request volumes or suspicious domain names;
  • deep inspection: implement DNS packet inspection systems, looking for long domain names or unusual structures;
  • DNS filtering: block requests to unauthorized or unknown DNS servers;
  • specific training of technical staff.

Let’s look at some of these best practices in detail.

Advanced monitoring

Advanced DNS traffic monitoring is critical to detect and mitigate DNS tunneling. To analyze and block suspicious activity, you need to combine specialized tools with strategic approaches. Solutions such as Security Information and Event Management (SIEM) allow you to collect and analyze large volumes of data to identify anomalies while security technologies Network Traffic Analysis (NTA) can detect unusual patterns in DNS traffic, such as excessive requests or anomalous domain names.

Using intrusion detection systems (IDS) with DNS analysis capabilities can add an additional layer of security. DNS-specific protection solutions also offer reputation-based filtering and block requests to suspicious or unknown domains. Integrating tools machine learning algorithm  enables the identification of malicious behaviors based on adaptive models.

Another approach is the adoption of DNS Security Firewall, devices that allow you to filter and block requests to suspicious domains, preventing communications with command and control (C2) servers. These tools allow you to analyze DNS queries in detail, detecting anomalies in traffic.

Effective monitoring also depends on accurate baseline and alert configuration and regular log review.

Deep DNS packet inspection

L'Deep DNS packet inspection (DPI) is an essential technique for detecting the DNS tunneling and other DNS traffic-related threats. It is called this to differentiate it from traditional traffic analysis techniques, which do not inspect the contents of packets, but simply check the header. Best practices for effective DPI include monitoring the size of the Query and Answer sections, as abnormal or oversized packets may hide malicious data.

Another important step is analyzing domain names, since domains used in tunneling often have strange patterns or lengths that exceed standard limits.

Training of technical staff is crucial to mitigate the risk of attacks DNS tunneling. Network and system administrators need training focused on DNS traffic monitoring tools, anomaly detection techniques, and DNS traffic management policies. Their training should include the implementation of DNS filters and the use of intrusion detection systems (IDS). Targeted administrator training, combined with general awareness, is an effective strategy to reduce the risk of DNS attacks and improve overall security.

Conclusions

Il DNS tunneling represents one of the most insidious and difficult to detect threats in today's cybersecurity landscape. By taking advantage of the traditional trust placed in DNS traffic, attackers are able to evade traditional defenses, exfiltrate sensitive data, and establish persistent communications without raising suspicion. Technical understanding of DNS tunneling and awareness of its methods are critical to protecting corporate and government networks from these advanced attacks.

To effectively counter this threat, it is essential to adopt a proactive approach that integrates advanced monitoring, in-depth inspection and continuous training of personnel. Only a multi-layered defense strategy can guarantee effective protection against the increasingly sophisticated techniques of DNS tunneling.

Cybersecurity is an ever-evolving process, and in a rapidly evolving environment, constantly updating your defenses is the only way to stay ahead of the attackers.

To learn more:

- https://support.huawei.com/enterprise/en/doc/EDOC1100174721/f917b5d7/dns

- https://www.fortinet.com/it/resources/cyberglossary/dns-security

- https://flashstart.com/it/dns-security-perche-e-fondamentale-per-protegg...

- https://www.akamai.com/it/glossary/what-is-a-dns-firewall