CS0-003Chapter 46 of 100Objective 1.3

DNS Analysis and Anomaly Detection

This chapter covers DNS analysis and anomaly detection, a critical skill for the CS0-003 exam's Security Operations domain (Objective 1.3). DNS is a foundational protocol, but its ubiquity makes it a prime vector for attacks like data exfiltration, command-and-control (C2) communication, and phishing. Approximately 10-15% of exam questions will involve interpreting DNS logs, identifying anomalies, or selecting the appropriate detection/response technique. Mastering this topic requires understanding normal DNS behavior, common attack patterns, and the tools used to analyze DNS traffic.

25 min read
Intermediate
Updated May 31, 2026

DNS as a Phone Switchboard with Logs

Imagine a large company with one main phone number and hundreds of employees. When an employee wants to call an external client, they dial the client's name into an operator (the DNS resolver). The operator looks up the name in a company directory (the DNS cache) to find the client's phone number. If the number is not in the directory, the operator calls the central switchboard (the authoritative DNS server) to get the number. The operator then connects the call and logs the employee's extension, the client's name, and the duration of the call. This log is the DNS query log. Now, an anomaly detection system monitors these logs. If an employee suddenly calls hundreds of different clients in a minute (a DNS flood), or if an employee calls a known scam number (a malicious domain), or if an employee calls a number that is actually a disguised internal line (a DNS tunneling attempt), the system alerts. The operator can also be tricked into using a fake directory (DNS cache poisoning) if the switchboard is compromised. By analyzing the patterns in the call logs, the system can detect these anomalies. For instance, a steady stream of calls to a single number every 60 seconds might be a beaconing call (C2 communication). The system can block the employee's extension (block the IP) or quarantine the call (sinkhole the domain).

How It Actually Works

What is DNS and Why Analyze It?

DNS (Domain Name System) translates human-readable domain names (e.g., www.example.com) into IP addresses (e.g., 192.0.2.1). It is a hierarchical, distributed database. Every time a user visits a website, sends an email, or connects to a service, a DNS query is typically made. This makes DNS traffic ubiquitous and often poorly monitored, creating a blind spot that attackers exploit.

From a security perspective, DNS analysis involves examining DNS query and response logs to detect malicious activity. Common threats include: - DNS Tunneling: Encapsulating non-DNS data (e.g., exfiltrated files, C2 commands) within DNS queries and responses. Because DNS is often allowed through firewalls, attackers can use it as a covert channel. - DNS Hijacking/Poisoning: Corrupting DNS caches to redirect users to malicious sites. - Fast-Flux DNS: Rapidly changing IP addresses associated with a domain to evade blocklists. - Domain Generation Algorithms (DGAs): Malware that generates many random domain names to find its C2 server; only a few are registered, making it hard to block. - DNS Amplification Attacks: Using open DNS resolvers to flood a target with large DNS responses. - Data Exfiltration: Encoding stolen data in DNS queries (e.g., subdomain labels).

How DNS Works Internally

A standard DNS query follows these steps: 1. User Request: A client application (e.g., web browser) needs the IP address for www.example.com. It sends a query to the configured recursive resolver (often provided by the ISP or a public resolver like 8.8.8.8). 2. Recursive Resolver Check: The resolver checks its cache. If found, it returns the cached answer. If not, it begins recursion. 3. Root Server Query: The resolver queries a root server (e.g., a.root-servers.net) to find the TLD (top-level domain) name server for .com. 4. TLD Server Query: The resolver queries the .com TLD server (e.g., a.gtld-servers.net) to get the authoritative name server for example.com. 5. Authoritative Server Query: The resolver queries the authoritative name server (e.g., ns1.example.com) for the IP address of www.example.com. 6. Response: The authoritative server returns the IP address. The resolver caches the result and sends it back to the client.

All these queries and responses are logged by the resolver, the authoritative server, and any monitoring devices along the path.

Key Components and Defaults

- DNS Record Types: - A: Maps hostname to IPv4 address. - AAAA: Maps hostname to IPv6 address. - CNAME: Canonical name (alias). - MX: Mail exchange. - NS: Name server. - TXT: Arbitrary text (often used for SPF, DKIM, DMARC). - SOA: Start of authority (contains zone serial number, refresh, retry, expire, and minimum TTL). - Default Ports: UDP 53 (queries), TCP 53 (zone transfers, large responses). - TTL (Time to Live): Specified in seconds, default common values: 300 (5 minutes), 3600 (1 hour), 86400 (1 day). Short TTLs (e.g., 60 seconds) are used for fast-flux or load balancing. - Recursive vs. Iterative: Recursive resolver does the full lookup; iterative resolver returns referrals. - EDNS0 (Extension Mechanisms for DNS): Allows larger UDP packets (up to 4096 bytes) and supports DNSSEC.

Anomaly Detection Techniques

Detection relies on baselining normal DNS behavior and identifying deviations. Key indicators: - Volume Anomalies:

Unusually high number of queries from a single IP (possible DDoS or scanning).

Unusually high number of NXDOMAIN responses (non-existent domain) – often a sign of DGA malware trying many domains.

Rarity: Queries to domains never seen before, or domains with high entropy (random-looking) in subdomain labels. Entropy calculation: For a string of length L with character set size C, entropy = L * log2(C). High entropy (e.g., >4 bits per character) suggests DGA or tunneling.

Protocol Anomalies:

DNS queries over TCP when UDP is expected (possible tunneling).

DNS responses larger than queries (amplification).

Queries for unusual record types (e.g., TXT, NULL, ANY) – often used for tunneling.

Timing Anomalies:

Regular, periodic queries (beaconing) – e.g., every 60 seconds exactly.

Queries at unusual hours (e.g., 3 AM).

Geolocation Anomalies: Queries to domains hosted in countries where the organization has no business.

Domain Reputation: Checking against threat intelligence feeds (e.g., known malicious domains, newly registered domains).

Tools and Commands

- tcpdump: Capture DNS traffic.

tcpdump -i eth0 -n port 53

- tshark: Analyze DNS packets.

tshark -r dns.pcap -Y "dns" -T fields -e dns.qry.name -e dns.flags.response

- dnstop: Real-time DNS statistics.

dnstop -s eth0

dnscap: Capture and analyze DNS traffic.

Bro/Zeek: DNS log generation.

SIEM: Correlate DNS logs with other event logs.

Passive DNS: Collect DNS responses from multiple resolvers to build historical record.

Interaction with Related Technologies

DNSSEC: Validates DNS responses to prevent spoofing. Anomaly detection must account for DNSSEC signatures (RRSIG, DNSKEY records).

DNS over HTTPS (DoH) / DNS over TLS (DoT): Encrypts DNS queries, hiding them from traditional monitoring. Anomaly detection must be performed at the endpoint or via analysis of encrypted traffic metadata.

CDNs (Content Delivery Networks): Use short TTLs and multiple IPs – can appear as fast-flux but are legitimate. Whitelisting known CDN ranges helps reduce false positives.

Load Balancers / Anycast: Multiple IPs for one domain – normal.

Common Attack Patterns in Detail

DNS Tunneling:

Attacker sets up a malicious authoritative server for e.g., tunnel.example.com.

Infected client sends queries with encoded data in subdomains: e.g., base64encodeddata.tunnel.example.com.

The authoritative server logs the query and sends a response (also possibly encoded).

Detection: High volume of TXT queries, long subdomain names ( > 52 characters ), high entropy, low TTL, and queries to a single domain from many internal IPs.

Fast-Flux DNS:

A single domain resolves to many IPs (often compromised machines) that change rapidly.

Detection: Short TTL (e.g., 60 seconds), multiple A records for the same domain, and IP addresses from diverse ASNs.

DGA:

Malware generates random domains (e.g., wxyz1234.com, abcd5678.net) until one resolves to a C2 server.

Detection: High rate of NXDOMAIN responses, high entropy in domain names, and queries to domains not seen before.

DNS Cache Poisoning:

Attacker sends forged DNS responses to a resolver, causing it to cache incorrect IPs.

Detection: Unexpected IP addresses for known domains, or multiple different IPs for the same domain from the same resolver.

DNS Amplification:

Attacker spoofs source IP of victim and sends small queries to open resolvers, which send large responses to the victim.

Detection: Large response-to-query size ratio (> 10:1), and many responses to a single IP from multiple resolvers.

Configuration and Verification

- BIND:

options {
      recursion no;  // disable recursion to prevent amplification
      allow-query { trusted; };
  };

- Windows DNS: Disable recursion on external-facing servers. - Verification: Use dig or nslookup to test:

dig @8.8.8.8 www.example.com

Check for open recursion with:

dig @your-server-ip www.example.com

If it returns a response, recursion is open.

Log Analysis Example

Consider a Zeek DNS log entry:

#fields ts      uid     id.orig_h       id.orig_p       id.resp_h       id.resp_p       proto   trans_id        query   qclass  qclass_name     qtype   qtype_name      rcode   rcode_name      AA      TC      RD      RA      Z       answers TTLs   rejected
1337084967.123456       ABC123  10.0.0.5        12345   8.8.8.8 53      udp     54321   www.example.com 1       C_INTERNET      1       A       0       NOERROR 0       0       1       1       0       192.0.2.1       3600    F

ts: timestamp

id.orig_h: source IP (10.0.0.5)

query: domain queried

rcode: 0 = NOERROR, 3 = NXDOMAIN

AA: Authoritative Answer flag

answers: IP returned

TTLs: TTL in seconds

Anomaly: If you see many queries from 10.0.0.5 to random-looking domains with rcode=3 (NXDOMAIN), that is suspicious for DGA.

Summary of Detection Rules

Threshold-based: e.g., > 100 queries per minute to NXDOMAIN domains from a single IP.

Entropy-based: e.g., domain name entropy > 4.5 bits per character.

Whitelist-based: e.g., domains not in top 1 million Alexa list.

Machine learning: Models trained on normal DNS behavior.

Walk-Through

1

Collect DNS Logs

The first step is to gather DNS query and response logs from all relevant sources: recursive resolvers (e.g., internal DNS servers), authoritative servers, and network taps. Use tools like Zeek, tcpdump, or dnscap to capture traffic on port 53 (UDP and TCP). Ensure logs include timestamp, source IP, query domain, query type, response code, answer IPs, TTLs, and response size. For encrypted DNS (DoH/DoT), logs must come from endpoints or from decrypting proxies. Centralize logs in a SIEM or data lake for analysis. Set retention policies appropriate for forensic needs (e.g., 90 days).

2

Baseline Normal Behavior

Establish a baseline of typical DNS traffic for your environment. Analyze historical logs to determine average query volume per hour, common domains visited, typical query types (mostly A/AAAA), and normal TTL ranges. Identify legitimate CDN domains and whitelist them to reduce false positives. Note patterns like user work hours vs. off-hours. Baselines should be updated periodically (e.g., weekly) to reflect changes. Tools like Elasticsearch with aggregations can compute percentiles and standard deviations. For example, a baseline might show that 95% of internal IPs make fewer than 10 queries per minute.

3

Detect Volume Anomalies

Monitor for deviations from the baseline in query volume. Set thresholds: for instance, alert if a single internal IP makes more than 100 queries per minute (possible scanning or DDoS), or if NXDOMAIN responses exceed 20% of total queries from a single source (possible DGA). Also monitor for high response-to-query size ratio (> 10:1) indicating amplification. Use rolling windows (e.g., 5-minute sliding window) to detect gradual increases. Correlate with other data: a spike in DNS queries coinciding with a new malware infection indicator.

4

Analyze Domain and Subdomain Characteristics

Examine the domains and subdomains being queried. Compute entropy of domain names (excluding TLD) – high entropy suggests DGA or tunneling. Flag domains with many subdomains (e.g., > 10 unique subdomains from a single IP). Check for long subdomain labels (> 52 characters) typical of tunneling. Use threat intelligence feeds to compare domains against known malicious lists. Look for domains registered recently (within 30 days) or with suspicious registrant info. Also flag queries to domains that resolve to IPs in high-risk countries.

5

Investigate Timing and Beaconing Patterns

Analyze the timing of queries for regularity. Use statistical tests to detect periodic behavior: for example, queries that occur every 60 seconds with less than 5% jitter are likely beaconing. Check for queries at unusual times (e.g., 3 AM) from a workstation that is normally idle. Correlate with user login/logout times. Beaconing intervals can range from seconds to hours; common C2 intervals are 60, 300, or 3600 seconds. Visualize with time-series graphs to spot patterns.

6

Respond and Mitigate

Once an anomaly is confirmed, take action. For a compromised host, block its IP at the firewall, quarantine the host, and force a scan. For malicious domains, add them to a DNS sinkhole (e.g., using a local resolver to return 127.0.0.1 or a benign IP) or block at the proxy. For DNS tunneling, block the authoritative server IP or domain. For amplification attacks, ensure your DNS servers are not open resolvers (disable recursion on external-facing servers). Document the incident and update detection rules. Use automated playbooks in SOAR for common scenarios.

What This Looks Like on the Job

Enterprise Scenario 1: Detecting DGA Malware in a Corporate Network

A large financial institution deployed Zeek on their network to monitor DNS traffic. One day, the security team noticed a workstation (10.10.50.25) generating an unusually high number of NXDOMAIN responses – about 200 per minute. The domains looked like random strings (e.g., a3f8k2d9.com, x7m4n1p0.net). The team had set a baseline of < 5 NXDOMAIN per minute per host. The SIEM alerted. Investigation revealed the workstation had been infected with a DGA-based malware trying to reach its C2 server. The team used a threat intelligence feed that identified the DGA algorithm. They blocked all domains matching the pattern at the firewall. The host was isolated and reimaged. The detection rule was updated to alert on > 50 NXDOMAIN per minute from a single IP. This scenario highlights the importance of baselining and threshold tuning. In a large network, false positives can occur from misconfigured devices (e.g., a server trying to resolve an internal hostname externally). Whitelisting internal domains reduces noise.

Enterprise Scenario 2: DNS Tunneling for Data Exfiltration

A tech company with strict outbound firewall rules (only DNS and HTTP allowed) experienced a data breach. The attacker used DNS tunneling to exfiltrate credit card numbers. The attacker registered a domain (exfil.example.com) and set up an authoritative server. The malware on the internal server encoded stolen data as subdomains: e.g., 1234567890123456.exfil.example.com. The DNS resolver queried the authoritative server, which logged the subdomain. The attacker collected the data from logs. Detection came from a security analyst who noticed a server (10.10.1.100) making thousands of TXT queries to a single domain (exfil.example.com) with long subdomains (average 60 characters). The entropy of the subdomains was high (5.2 bits/char). The company had no baseline for TXT queries – they were rare. The analyst blocked the domain and investigated the server. Remediation included implementing a DNS sinkhole for unknown domains and monitoring for TXT query volume. This case underscores the need to monitor for rare query types and long subdomain lengths.

Scenario 3: DNS Amplification Attack on a Service Provider

A managed DNS provider had an open resolver that was inadvertently configured to allow recursion from any source. Attackers used this to amplify a DDoS attack against a gaming company. The provider saw a sudden spike in outbound DNS responses (up to 10 Gbps) from their resolver to a single IP (the victim). The response-to-query size ratio was 50:1. The provider quickly disabled recursion on the public-facing interface and restricted it to internal IPs only. They also implemented rate limiting per source IP. Post-incident, they configured ACLs to allow recursion only from authorized clients. This scenario demonstrates the importance of secure DNS configuration: never allow open recursion on public servers. The exam may ask about mitigation steps: disable recursion, use response rate limiting (RRL), or deploy anycast to absorb attacks.

How CS0-003 Actually Tests This

What CS0-003 Tests on DNS Analysis and Anomaly Detection

This topic falls under Objective 1.3: Given a scenario, analyze potential indicators associated with network attacks. The exam expects you to interpret DNS logs, identify anomalies, and select appropriate detection/response actions. Specific sub-objectives include: - 1.3.1: Analyze DNS logs for signs of tunneling, DGA, fast-flux, and cache poisoning. - 1.3.2: Given a DNS log, identify the attack type (e.g., NXDOMAIN flood indicates DGA). - 1.3.3: Determine the appropriate response (e.g., sinkhole, block IP, disable recursion).

Common Wrong Answers and Why Candidates Choose Them

1.

Choosing 'DNSSEC' as a solution to DNS tunneling: DNSSEC validates authenticity but does not prevent tunneling. Candidates confuse integrity with covert channel prevention.

2.

Selecting 'Block all DNS queries' as a response: This would break internet access. The correct response is to block only malicious domains or the specific resolver.

3.

Identifying a high TTL as suspicious: High TTL (e.g., 86400) is normal for stable domains. Fast-flux uses low TTL. Candidates often think high TTL is bad because it means longer cache persistence, but that's not an anomaly indicator.

4.

Confusing NXDOMAIN with NOERROR: NXDOMAIN means domain does not exist; NOERROR means successful resolution. DGA causes many NXDOMAINs, while successful C2 queries return NOERROR.

Specific Numbers and Values That Appear on the Exam

Default DNS ports: UDP 53, TCP 53.

TTL values: 60 seconds (fast-flux), 300 seconds (common), 86400 seconds (typical).

Response-to-query size ratio: > 10:1 indicates amplification.

Entropy threshold: > 4.5 bits per character for domain names is suspicious.

Subdomain length: > 52 characters is typical for tunneling.

NXDOMAIN rate: > 20% of total queries from a single source is anomalous.

Edge Cases and Exceptions

Legitimate high entropy domains: CDNs sometimes use random-looking hostnames (e.g., a12345.cloudfront.net). Whitelist known CDN ASNs.

Legitimate TXT queries: Used for SPF/DKIM verification. Baseline normal TXT query volume.

Multiple A records: Load balancing or CDN – not necessarily fast-flux. Check TTL and IP diversity.

DNSSEC responses: Include RRSIG records – do not flag as large responses.

How to Eliminate Wrong Answers

Read the log carefully: Look at response code, query type, TTL, and frequency.

Match the pattern: If you see many NXDOMAINs, think DGA. If you see long subdomains with high entropy, think tunneling. If you see low TTL and many IPs, think fast-flux.

Use elimination: If an answer says 'disable DNS recursion on internal servers' – that is wrong because internal servers need recursion. Disable recursion on external-facing servers.

Think about the goal: The attacker's goal determines the technique. Exfiltration? Tunneling. Evasion? Fast-flux. Persistence? DGA.

Exam Tips

Memorize the default ports and common TTLs.

Practice reading Zeek DNS logs.

Know the difference between recursive and authoritative servers.

Understand that DNS can be used for both C2 and data exfiltration.

Be able to recommend sinkholing as a response to malicious domains.

Key Takeaways

DNS uses UDP port 53 for queries and TCP port 53 for zone transfers and large responses.

A TTL of 60 seconds or less is a red flag for fast-flux DNS.

High NXDOMAIN rates (>20% of total queries from a source) indicate possible DGA activity.

Subdomain entropy >4.5 bits per character suggests DNS tunneling or DGA.

Response-to-query size ratio >10:1 indicates DNS amplification attack.

Disable recursion on external-facing DNS servers to prevent amplification attacks.

Sinkholing is an effective response to redirect malicious domain queries to a benign IP.

Easy to Mix Up

These come up on the exam all the time. Here's how to tell them apart.

DNS Tunneling

Used for data exfiltration or command/control.

High entropy in subdomain labels (e.g., base64 encoded).

Often uses TXT or NULL record types.

Long subdomain names (> 52 characters).

Queries to a single domain from many internal IPs.

DNS Beaconing (C2)

Used for periodic check-ins with C2 server.

Low entropy, often uses normal-looking domains (e.g., microsoft-update.com).

Typically uses A or AAAA records.

Short subdomain or no subdomain.

Regular timing (e.g., every 60 seconds) from a single IP.

Watch Out for These

Mistake

DNS only uses UDP port 53.

Correct

DNS uses UDP port 53 for most queries, but TCP port 53 is used for zone transfers and for responses larger than 512 bytes (or 4096 with EDNS0). The exam may test that large responses or zone transfers require TCP.

Mistake

A high TTL always indicates a legitimate domain.

Correct

While high TTL is common for legitimate domains, some malicious domains also use high TTL to stay cached longer after being reported. The anomaly is low TTL (e.g., 60 seconds) used by fast-flux networks.

Mistake

DNS tunneling always uses TXT records.

Correct

DNS tunneling can use any record type, including A, AAAA, CNAME, or NULL. TXT is common because it allows arbitrary text, but attackers may use other types to evade detection. Detection should focus on entropy and volume, not just record type.

Mistake

NXDOMAIN responses always indicate a DGA.

Correct

NXDOMAIN can also result from user typos, misconfigured applications, or broken links. However, a high rate of NXDOMAIN from a single source is suspicious. Baseline normal NXDOMAIN rates to avoid false positives.

Mistake

Enabling DNSSEC prevents DNS tunneling.

Correct

DNSSEC only provides data integrity and origin authentication; it does not inspect the content of DNS records. Tunneling can still occur using signed zones. DNSSEC does not prevent covert channels.

Do You Actually Know This?

Reveal each answer, then mark whether you got it right. Score 60%+ to unlock the next chapter.

Frequently Asked Questions

What is the difference between DNS tunneling and DNS beaconing?

DNS tunneling is a technique where attackers encapsulate data (e.g., exfiltrated files or C2 commands) within DNS queries and responses, often using long, high-entropy subdomains and TXT records. DNS beaconing (C2) is a periodic check-in where malware sends regular DNS queries to a domain to receive commands, typically with short, low-entropy names and standard record types like A. The key difference is the purpose: tunneling for data transfer, beaconing for command/control. Detection focuses on entropy, subdomain length, and query regularity.

How can I detect DNS amplification attacks in my logs?

Look for DNS responses that are significantly larger than the corresponding queries. A normal query is about 40-60 bytes, while a response can be up to 4096 bytes with EDNS0. If the response-to-query size ratio exceeds 10:1, it may be an amplification attack. Additionally, you may see many responses to a single victim IP from multiple open resolvers. To mitigate, ensure your DNS servers are not open resolvers (disable recursion on external interfaces) and implement response rate limiting (RRL).

What is a DNS sinkhole and how does it work?

A DNS sinkhole is a DNS server that returns a false IP address (often 127.0.0.1 or a benign IP) for malicious domains, preventing clients from reaching the actual malicious server. It works by configuring the resolver to redirect queries to known malicious domains to a sinkhole server. For example, you can add entries to a local zone file: 'malware.com A 127.0.0.1'. This is effective for blocking C2 traffic and malware downloads. On the CS0-003 exam, sinkholing is a recommended response for malicious domains.

Why is it important to monitor NXDOMAIN responses?

NXDOMAIN responses indicate that a queried domain does not exist. A sudden increase in NXDOMAINs from a single host often indicates Domain Generation Algorithm (DGA) malware, which generates many random domain names hoping to find its C2 server. Monitoring NXDOMAIN rates helps detect infections early. However, you must baseline normal NXDOMAIN rates (e.g., due to user typos) to avoid false positives. A threshold of >20% NXDOMAIN of total queries from a source is commonly used.

What are the signs of DNS cache poisoning?

DNS cache poisoning occurs when a resolver caches a forged DNS response. Signs include: multiple different IP addresses for the same domain from the same resolver, unexpected IPs for known domains, or users being redirected to malicious sites. Detection involves comparing resolved IPs against known good values (e.g., from a trusted resolver). Prevention includes using DNSSEC and ensuring resolvers use random source ports and transaction IDs.

How does DNSSEC help with DNS security?

DNSSEC adds digital signatures to DNS records, allowing resolvers to verify that responses are authentic and have not been modified in transit. It prevents cache poisoning and man-in-the-middle attacks. However, DNSSEC does not encrypt queries, so it does not prevent eavesdropping or DNS tunneling. For privacy, use DNS over TLS (DoT) or DNS over HTTPS (DoH). On the exam, know that DNSSEC provides integrity and authentication, not confidentiality.

What tools can I use to analyze DNS traffic?

Common tools include: tcpdump and Wireshark for packet capture; tshark for command-line analysis; dnstop for real-time statistics; dnscap for full packet capture; Zeek (Bro) for log generation; and SIEM platforms (e.g., Splunk, ELK) for correlation. For passive DNS, tools like PassiveDNS or DNSDB can help. The exam expects you to know how to use tcpdump and tshark to filter DNS traffic (e.g., 'tcpdump port 53').

Terms Worth Knowing

Ready to put this to the test?

You've just covered DNS Analysis and Anomaly Detection — now see how well it sticks with free CS0-003 practice questions. Full explanations included, no account needed.

Done with this chapter?