Detecting Exfiltration over DNS with Zeek
Overview
DNS tunneling and exfiltration is a technique used by attackers to bypass firewalls and DLP controls by encoding stolen data into DNS query subdomains. Legitimate DNS queries have predictable entropy and length patterns, while exfiltration queries contain encoded data with high Shannon entropy, unusually long subdomain labels, and high volumes of unique subdomains per parent domain.
This skill analyzes Zeek dns.log files (TSV format) to detect exfiltration indicators. The agent computes Shannon entropy for each subdomain component, identifies queries exceeding the 63-character DNS label limit, counts unique subdomains per parent domain, and flags domains that exceed configurable thresholds. These techniques detect tools like dnscat2, iodine, dns2tcp, and custom DNS tunneling implementations.
When to Use
Trigger phrases:
"detecting exfiltration over dns with zeek"
"Detect DNS-based data exfiltration by analyzing Zeek dns"
When investigating security incidents that require detecting exfiltration over dns with zeek
When building detection rules or threat hunting queries for this domain
When SOC analysts need structured procedures for this analysis type
When validating security monitoring coverage for related attack techniques
When NOT to Use
- When you lack proper authorization for testing
- For production systems without change management
- When the task requires legal or compliance expertise beyond technical scope
Prerequisites
- Python 3.9 or later with math and collections modules (stdlib)
- Zeek dns.log files in TSV format with standard field headers
- Network capture data processed by Zeek 5.0+ or later
- Understanding of DNS protocol structure and query types
Steps
Parse Zeek dns.log headers: Read the TSV file, extract the #fields header line to identify column positions for ts, id.orig_h, query, qtype_name, rcode_name, and answers.
Extract and decompose queries: For each DNS query, split the FQDN into subdomain labels and parent domain. Skip queries to known safe domains and internal zones.
Compute Shannon entropy: Calculate the information entropy of each subdomain label. Legitimate subdomains typically have entropy below 3.5, while encoded/encrypted data produces entropy above 4.0.
Detect long labels: Flag DNS labels exceeding 52 characters (approaching the 63-character maximum). Long labels are a strong indicator of data tunneling.
Count unique subdomains per domain: Track how many distinct subdomains each parent domain receives. Domains with more than 50 unique subdomains within the log window are suspicious.
Identify query volume anomalies: Calculate queries-per-minute per source IP per domain. Exfiltration tools generate sustained high-volume query streams that differ from normal browsing.
Score and rank domains: Combine entropy, label length, uniqueness count, and query volume into a composite risk score. Rank domains by score and output the top suspicious domains.
Generate detection report: Produce a JSON report with flagged domains, their evidence indicators, originating source IPs, and recommended response actions.
Expected Output
{
"analysis_summary": {
"total_queries_analyzed": 145832,
"unique_domains": 3421,
"flagged_domains": 3,
"entropy_threshold": 3.5
},
"flagged_domains": [
{
"domain": "data.evil-c2.com",
"unique_subdomains": 892,
"avg_entropy": 4.72,
"max_label_length": 61,
"source_ips": ["10.0.1.45"],
"risk_score": 9.4,
"indicators": ["high_entropy", "long_labels", "high_subdomain_count"]
}
]
}
Red Flags
- Performing actions without explicit written authorization from the asset owner
- Testing against production systems without a defined scope and rules of engagement
- Capturing traffic on networks without authorization or privacy considerations
- Leaving packet captures containing sensitive data unencrypted on disk
- Deploying inline blocking rules without testing for false positives first
Process
- Reconnaissance — Gather target information, identify attack surface, enumerate services
- Analysis/Exploitation — Execute the technique, analyze results, document findings
- Reporting — Document IOCs, write findings, provide remediation recommendations
Verification
- All steps executed successfully against a test environment before production use
- Output documented with screenshots or logs demonstrating expected behavior
- Captures verified as complete with no dropped packets
- Detection rules tested against known-benign traffic for false positive rate
- Alert thresholds validated and tuned to reduce noise
Anti-Rationalization Table
| Rationalization |
Reality |
| "We are too small to be targeted" |
Automated attacks target everyone. Size does not matter. |
| "Security slows us down" |
A breach slows you down 100x more. Build security in from the start. |
| "We will fix it after launch" |
Vulnerabilities in production are exploited within hours. Fix before deploy. |
1---2name: detecting-exfiltration-over-dns-with-zeek3description: Use when detect DNS-based data exfiltration by analyzing Zeek dns.log for high-entropy subdomains and anomalous query patterns. Use when detecting dns-based data exfiltration by analyzing zeek dns.log for high-entropy.4license: Apache-2.05---6789# Detecting Exfiltration over DNS with Zeek1011## Overview1213DNS tunneling and exfiltration is a technique used by attackers to bypass firewalls and DLP controls by encoding stolen data into DNS query subdomains. Legitimate DNS queries have predictable entropy and length patterns, while exfiltration queries contain encoded data with high Shannon entropy, unusually long subdomain labels, and high volumes of unique subdomains per parent domain.1415This skill analyzes Zeek dns.log files (TSV format) to detect exfiltration indicators. The agent computes Shannon entropy for each subdomain component, identifies queries exceeding the 63-character DNS label limit, counts unique subdomains per parent domain, and flags domains that exceed configurable thresholds. These techniques detect tools like dnscat2, iodine, dns2tcp, and custom DNS tunneling implementations.161718## When to Use19**Trigger phrases:**20- "detecting exfiltration over dns with zeek"21- "Detect DNS-based data exfiltration by analyzing Zeek dns"222324- When investigating security incidents that require detecting exfiltration over dns with zeek25- When building detection rules or threat hunting queries for this domain26- When SOC analysts need structured procedures for this analysis type27- When validating security monitoring coverage for related attack techniques282930## When NOT to Use3132- When you lack proper authorization for testing33- For production systems without change management34- When the task requires legal or compliance expertise beyond technical scope353637## Prerequisites3839- Python 3.9 or later with math and collections modules (stdlib)40- Zeek dns.log files in TSV format with standard field headers41- Network capture data processed by Zeek 5.0+ or later42- Understanding of DNS protocol structure and query types4344## Steps45461. **Parse Zeek dns.log headers**: Read the TSV file, extract the `#fields` header line to identify column positions for `ts`, `id.orig_h`, `query`, `qtype_name`, `rcode_name`, and `answers`.47482. **Extract and decompose queries**: For each DNS query, split the FQDN into subdomain labels and parent domain. Skip queries to known safe domains and internal zones.49503. **Compute Shannon entropy**: Calculate the information entropy of each subdomain label. Legitimate subdomains typically have entropy below 3.5, while encoded/encrypted data produces entropy above 4.0.51524. **Detect long labels**: Flag DNS labels exceeding 52 characters (approaching the 63-character maximum). Long labels are a strong indicator of data tunneling.53545. **Count unique subdomains per domain**: Track how many distinct subdomains each parent domain receives. Domains with more than 50 unique subdomains within the log window are suspicious.55566. **Identify query volume anomalies**: Calculate queries-per-minute per source IP per domain. Exfiltration tools generate sustained high-volume query streams that differ from normal browsing.57587. **Score and rank domains**: Combine entropy, label length, uniqueness count, and query volume into a composite risk score. Rank domains by score and output the top suspicious domains.59608. **Generate detection report**: Produce a JSON report with flagged domains, their evidence indicators, originating source IPs, and recommended response actions.6162## Expected Output6364```json65{66 "analysis_summary": {67 "total_queries_analyzed": 145832,68 "unique_domains": 3421,69 "flagged_domains": 3,70 "entropy_threshold": 3.571 },72 "flagged_domains": [73 {74 "domain": "data.evil-c2.com",75 "unique_subdomains": 892,76 "avg_entropy": 4.72,77 "max_label_length": 61,78 "source_ips": ["10.0.1.45"],79 "risk_score": 9.4,80 "indicators": ["high_entropy", "long_labels", "high_subdomain_count"]81 }82 ]83}84```85## Red Flags8687- Performing actions without explicit written authorization from the asset owner88- Testing against production systems without a defined scope and rules of engagement89- Capturing traffic on networks without authorization or privacy considerations90- Leaving packet captures containing sensitive data unencrypted on disk91- Deploying inline blocking rules without testing for false positives first9293## Process94951. **Reconnaissance** — Gather target information, identify attack surface, enumerate services961. **Analysis/Exploitation** — Execute the technique, analyze results, document findings971. **Reporting** — Document IOCs, write findings, provide remediation recommendations9899## Verification100101- All steps executed successfully against a test environment before production use102- Output documented with screenshots or logs demonstrating expected behavior103- Captures verified as complete with no dropped packets104- Detection rules tested against known-benign traffic for false positive rate105- Alert thresholds validated and tuned to reduce noise106107## Anti-Rationalization Table108109| Rationalization | Reality |110|---|---|111| "We are too small to be targeted" | Automated attacks target everyone. Size does not matter. |112| "Security slows us down" | A breach slows you down 100x more. Build security in from the start. |113| "We will fix it after launch" | Vulnerabilities in production are exploited within hours. Fix before deploy. |