Every DNS query expects an answer. When a domain does not exist, the resolver returns NXDOMAIN, response code 3. Most analysts scroll past these responses, treating them as noise. That is a mistake. NXDOMAIN responses are one of the most reliable signals in threat hunting, and learning to read them turns routine DNS captures into detection goldmines.
trypcaphub/learn-dns-threat-hunting-challenge-find-the-malicious-queries
View this capture on PcapHub
What NXDOMAIN actually means
When a DNS resolver receives a query for a domain that does not exist in any authoritative zone, it returns a response with rcode 3 (NXDOMAIN). This is the DNS equivalent of "there is nothing here." In Wireshark or any packet viewer, you will see it in the DNS flags field: Reply code: No such name (3).
A handful of NXDOMAINs in any capture is normal. Users mistype URLs. Applications probe for service discovery records that may not exist. CDNs check alternate hostnames. The signal is not in a single NXDOMAIN. It is in the pattern.
The five NXDOMAIN patterns that matter
1. DGA beaconing: high entropy, multiple TLDs
Domain generation algorithms produce domains that look like someone fell asleep on a keyboard. When malware needs to find its command-and-control server, it generates hundreds or thousands of candidate domains, queries each one, and waits for one to resolve. The rest come back NXDOMAIN.
In a capture, this looks like a single internal host making sequential queries for domains like aji0y6dpb.net, sahxthv3a3z.org, f8mdd4v30t9n.biz, spread across multiple TLDs (.com, .net, .org, .biz, .info). The queries come at regular intervals, not in bursts. Most return NXDOMAIN. One or two might resolve to the active C2 server, and those are the ones the attacker registered this week.
The detection signal: a single source generating DNS queries with high character entropy, spread across uncommon TLDs, where 80%+ of responses are NXDOMAIN. Legitimate software does not query randomly generated domain names across five different TLDs.
To calculate domain entropy quickly, look at the ratio of unique characters to domain length. DGA domains typically have near-uniform character distribution. Human-chosen domains cluster around dictionary words and common patterns.
2. NXDOMAIN floods: volume as a weapon
An NXDOMAIN flood targets the resolver itself. The attacker sends thousands of queries for non-existent subdomains under a target domain, forcing the resolver to perform full recursive lookups for each one. Because the subdomains do not exist, responses cannot be cached, and each query consumes resolver resources.
In a capture, this is unmistakable: dozens or hundreds of queries arriving within milliseconds, all targeting variations like random-nonexistent-domain-1-75d67fd25d778964.pcaplab.local, random-nonexistent-domain-2-6aa5576dc6c25b82.pcaplab.local. The hex suffixes ensure no two queries are identical, defeating cache-based mitigation.
The detection signal: query volume. Fifty NXDOMAIN responses in 150 milliseconds from a single host to a single resolver is not normal DNS behaviour. Set your threshold based on your environment, but anything above 10 NXDOMAIN responses per second from one source warrants investigation.
3. Data exfiltration: the payload is in the query
This is the pattern most analysts miss. DNS exfiltration encodes stolen data directly in the subdomain label of the query itself. The attacker does not need the response to contain anything useful, so NXDOMAIN is fine. The data has already left the network by the time the resolver processes the query.
In the wild, these queries look like c3RvbGVuOnBhc3N3b3JkMTIz.t.example.com or ZXhmaWw6Y3JlZGl0X2NhcmQ.t.example.com. If you base64-decode those subdomain labels, they read stolen:password123 and exfil:credit_card. The .t. subdomain is a channel marker. The authoritative nameserver for example.com (controlled by the attacker) logs every query it receives, reassembles the data from the subdomain labels, and the actual DNS response is irrelevant.
The detection signal: long subdomain labels (often 20+ characters), base64-like character sets (alphanumeric with occasional padding characters), and queries landing under a single parent domain that itself may or may not resolve. The NXDOMAIN response is the giveaway that the parent zone is not configured to answer, only to collect.
DNS exfiltration works even in networks with strict outbound firewall rules. As long as DNS queries can reach a resolver (and they almost always can), data can be exfiltrated. This is why monitoring NXDOMAIN responses is a critical layer of defence even in well-segmented environments.
4. Subdomain enumeration: mapping infrastructure
Attackers and penetration testers use DNS to map internal infrastructure by querying sequential hostnames and watching which ones resolve versus which return NXDOMAIN. A burst of queries for site1.internal.local through site40.internal.local is automated subdomain brute-forcing.
In a capture, the pattern is obvious: ordered queries with predictable naming, rapid timing (60 queries in under 600 milliseconds), and a mix of resolved and NXDOMAIN responses. The resolved names are the targets the attacker found. The NXDOMAINs are the misses.
The detection signal: sequential or dictionary-based subdomain patterns from a single source, especially against internal zones. Legitimate applications do not query site1 through site40 in half a second.
5. C2 beaconing via structured subdomains
Some C2 frameworks use DNS queries with numeric or structured subdomain prefixes as a command channel. The queries look superficially like CDN or analytics hostnames: 7715.api-analytics-cdn.example.local, 2580.api-analytics-cdn.example.local. The numeric prefix is the beacon data (a session ID, a command response, or a status code). The parent domain is crafted to look like legitimate infrastructure.
The detection signal: repeating parent domain with variable numeric or hex prefixes, sent at regular intervals from one host. If the parent domain returns NXDOMAIN, it was never real infrastructure. Legitimate CDN and analytics hostnames resolve.
How to hunt NXDOMAINs in a capture
Step 1: Filter for NXDOMAIN responses
In Wireshark, the display filter is:
dns.flags.rcode == 3
This shows only DNS responses with rcode NXDOMAIN. In PcapHub's viewer, look for packets where the Info column shows "No such name" or the response flags indicate rcode 3.
Step 2: Group by queried domain
Once you have the NXDOMAIN responses filtered, look at what was being queried. Sort or group by the query name field. You are looking for:
- One parent domain, many subdomains: exfiltration or C2
- Many unrelated domains, multiple TLDs: DGA
- Sequential or patterned subdomains: enumeration
- One domain, massive volume: NXDOMAIN flood
Step 3: Check the source
Identify which internal host is generating the queries. A single workstation producing 50 NXDOMAIN-triggering queries in a minute is suspicious. Multiple workstations querying the same non-existent domain might indicate a misconfiguration propagating through the network, or a worm spreading laterally.
Step 4: Measure timing
The interval between queries tells you what you are dealing with:
| Pattern | Typical timing |
|---|---|
| NXDOMAIN flood | Sub-millisecond to low milliseconds between queries |
| DGA beaconing | Seconds between queries, regular intervals |
| Data exfiltration | Variable, often mimics normal browsing patterns |
| Subdomain enumeration | Milliseconds, rapid sequential bursts |
| C2 structured beaconing | Regular intervals (30s, 60s, 5min) |
Step 5: Decode suspicious labels
For any subdomain label that looks like encoded data, try base64 decoding it. Many exfiltration tools use base64 or hex encoding. A label like c3RvbGVuOnBhc3N3b3JkMTIz decoding to stolen:password123 confirms exfiltration. Even partial decodes (readable fragments mixed with binary) indicate data in transit.
Why NXDOMAIN is the defender's friend
Most network security monitoring focuses on connections that succeed. Firewalls log allowed and denied connections. IDS rules trigger on known-bad signatures in traffic payloads. But NXDOMAIN responses represent failed connections, and in threat hunting, failures are often more interesting than successes.
An attacker using DGA will generate hundreds of failed lookups for every successful C2 connection. An exfiltration channel using DNS produces NXDOMAIN responses for every data chunk sent. A subdomain brute-force creates a trail of NXDOMAIN responses that maps exactly what the attacker was looking for.
These failures are the breadcrumbs. They are harder to suppress than successful connections (the attacker cannot control what the resolver returns for domains they have not registered), and they create a pattern that is visible at the DNS layer even when the actual malicious traffic is encrypted or tunnelled through other protocols.
The next time you open a DNS capture, filter for rcode 3 first. The domains that do not exist might be the most important ones in the capture.