Threat Detection

Spotting suspicious DNS queries

DNS is the first place to look when hunting for malicious activity in a capture. Malware needs to phone home, and DNS is almost always part of that process.

4 min readLesson 1

Captures used in this lesson

When malware lands on a machine, one of the first things it does is try to contact its command-and-control (C2) server. Before it can make that connection, it usually needs to resolve a domain name. That DNS query is your first opportunity to detect it.

Why attackers use DNS

Attackers use DNS because it almost always works. Most networks allow outbound DNS traffic. Firewalls and proxies are configured to let it through. It is the one protocol that is rarely blocked entirely, which makes it the most reliable way for malware to reach the outside world.

This is also why DNS is one of the most valuable protocols for defenders to monitor.

Red flags in DNS traffic

1. Algorithmically generated domains

Domain Generation Algorithms (DGAs) create domains that look like random strings:

xjk39fal2.com
a8dj2ksl0p.net
m3ndf9xk2w.com

Legitimate domains are usually readable words or brand names. A cluster of queries for domains that look like someone mashed the keyboard is a strong indicator of DGA-based malware.

Filter for NXDOMAIN responses: dns.flags.rcode == 3. A large number of NXDOMAINs often indicates DGA activity, since the malware is cycling through generated domains hoping to find one that is currently active.

Give it a try on this capture:

trypcaphub/learn-domain-generation-algorithm-dga-detection

Opens alongside this page, keeping your place.

2. Unusually long subdomain names

Normal subdomains are short: www, api, mail, cdn. If you see queries for domains like:

aGVsbG8gdGhpcyBpcyBlbmNvZGVkIGRhdGE.exfil.example.com

That long subdomain is likely encoded data. This is DNS tunneling, where the attacker hides data exfiltration inside DNS queries. The subdomain is actually a base64-encoded payload.

3. High volume of TXT queries

TXT records can carry arbitrary text data. Legitimate uses include SPF records, DKIM keys, and domain verification. But attackers use TXT records for C2 communication because they can carry more data than A records.

If you see a machine making hundreds of TXT queries to the same domain, that is very suspicious.

4. Queries to non-standard DNS servers

Most machines should query your internal DNS server or a known public resolver (8.8.8.8, 1.1.1.1, 9.9.9.9). If a machine is sending DNS queries to an unknown IP address, the malware may be using its own DNS infrastructure to avoid your monitoring.

Filter: dns && !(ip.dst == 8.8.8.8) && !(ip.dst == 1.1.1.1) (adjust for your environment's DNS servers)

5. DNS queries at unusual times

Legitimate DNS traffic follows human patterns. If you see a burst of DNS queries at 3 AM from a workstation that should be idle, something might be running that should not be.

Putting it together

Here is a practical workflow for DNS threat hunting in a capture:

  1. Filter to dns and scan the queried domain names
  2. Look for patterns: random strings, very long names, repeated queries to the same unusual domain
  3. Check response codes: a cluster of NXDOMAINs is suspicious
  4. Note the DNS servers being queried: anything unexpected?
  5. Look at query types: excessive TXT or NULL queries are unusual
  6. Cross-reference suspicious domains with threat intelligence (VirusTotal, URLhaus)

Challenge: Find the odd one out

In a capture with normal web browsing traffic, look for DNS queries that do not match the pattern. Which domains look legitimate, and which look algorithmically generated? What query types are being used?

Filter hint: dns.qry.type == 16

The filter above shows TXT queries. In normal browsing, you should see very few of these. A high count might indicate DNS tunneling.

You see 200 DNS queries in 5 minutes, all to different subdomains of the same domain, and all returning NXDOMAIN. What is the most likely explanation?

Key takeaway

DNS monitoring is one of the easiest and most effective ways to detect malicious activity. You do not need deep expertise to spot the red flags: random-looking domains, long subdomain strings, high NXDOMAIN rates, and unusual query types. Start every threat hunt with DNS.