Protocol Analysis

DNS deep dive

DNS is in almost every capture you will ever look at. Understanding how it works and what to look for is one of the most practical packet analysis skills you can build.

3 min readLesson 1

Captures used in this lesson

DNS (Domain Name System) translates human-readable domain names into IP addresses. Before almost any connection happens on the internet, a DNS query happens first. This makes DNS incredibly useful for packet analysis because it tells you what the machine was trying to reach, even if the actual connection is encrypted.

What a DNS query looks like

A typical DNS exchange is two packets:

  1. Query (client to DNS server): "What is the IP address of example.com?"
  2. Response (DNS server to client): "example.com is at 93.184.216.34"

Both packets are usually UDP on port 53. The query and response are matched by a Transaction ID in the header.

DNS (Layer 7) / Port 53 (UDP)

Resolves domain names to IP addresses. Almost all internet traffic starts with a DNS lookup.

  • Transport: Usually UDP, sometimes TCP (for large responses or zone transfers)
    • Query types: A (IPv4), AAAA (IPv6), MX (mail), CNAME (alias), TXT (text records), NS (nameserver)
    • Response codes: NOERROR (success), NXDOMAIN (domain does not exist), SERVFAIL (server error)

Why DNS is so useful for analysis

Even when all other traffic is encrypted with TLS, DNS queries are often sent in plain text. This means you can see exactly which domains a machine was contacting, which gives you a roadmap for the rest of the capture.

Look at the DNS queries in a capture and you immediately know:

  • What websites were visited
  • What services were contacted (update servers, API endpoints, CDNs)
  • What potentially suspicious domains were resolved

What to look for

Unusual query types

Most legitimate traffic uses A (IPv4 address) and AAAA (IPv6 address) records. If you see a lot of TXT queries or unusually long domain names, that might indicate DNS tunneling, which is a technique for hiding data inside DNS queries.

NXDOMAIN responses

A high number of NXDOMAIN (Non-Existent Domain) responses can indicate:

  • A misconfigured application trying to reach domains that do not exist
  • Malware trying to contact command-and-control domains that have been taken down
  • Domain generation algorithms (DGAs) used by malware to find active C2 servers

Uncommon DNS servers

Most machines should be querying a known DNS resolver (your organisation's DNS server, or a public resolver like 8.8.8.8 or 1.1.1.1). If you see queries going to an unusual IP address on port 53, that is worth investigating.

Use the filter dns to see all DNS traffic in a capture. Add dns.flags.response == 0 for queries only, or dns.flags.response == 1 for responses only.

DNS over HTTPS and DNS over TLS

Modern DNS privacy protocols like DoH (DNS over HTTPS, port 443) and DoT (DNS over TLS, port 853) encrypt DNS queries. If a machine is using these, you will not see the query content in the PCAP. You will only see encrypted TLS traffic to a known DoH/DoT provider.

This is good for privacy but makes network analysis harder. If you are troubleshooting or doing security analysis on your own network, consider whether your DNS infrastructure uses encrypted DNS.

You see a large number of DNS TXT queries with long, random-looking subdomain names. What might this indicate?

Practical exercise

Next time you open a capture, start with the DNS queries. Filter to dns and scan through the domain names. You will often find that the DNS traffic alone gives you a complete picture of what the machine was doing.