TExcelTAD

DNS Resolution and Record Types

Almost every connection starts with a DNS lookup, which makes DNS two things at once for security. It is an attack surface: if an attacker controls the answer, they control where the victim connects. And it is one of the best sources of evidence a defender has: malware has to look up its servers, data smuggled out in DNS queries leaves traces, and a phishing domain is visible in the resolver log before anyone clicks a link. This lesson queries a lab DNS server with dig, reads every part of the answer, and shows what DNS logs reveal. Resolution and the message format are explained in DNS and DNS Messages.

Resolution in one paragraph

A client asks its recursive resolver ("what is the A record of www.lab.test?"). The resolver, if it has no cached answer, asks a root server, which refers it to the .test servers, which refer it to the authoritative servers of lab.test, which answer. The resolver caches the answer for its TTL and returns it. The client trusts whatever the resolver says, and the resolver trusts whatever comes back on the right port with the right ID, unless DNSSEC is used (see DNS Spoofing and DNSSEC).

Record types an analyst meets

Type Holds Security use
A / AAAA IPv4 / IPv6 address where a name points; IOC lookups
CNAME alias to another name dangling CNAMEs to deleted cloud resources enable subdomain takeover
MX mail servers, with preference where mail for a domain goes
TXT free text SPF, DKIM keys, DMARC policy, domain-verification tokens; also abused for tunnelling
NS / SOA delegation, zone authority who controls a zone
PTR reverse lookup (address → name) naming hosts in logs
CAA which CAs may issue certificates limits mis-issuance
SRV service location (_ldap._tcp…) Active Directory discovery

Querying the lab zone

The session starts dnsmasq, a small DNS server, on 127.0.0.1:5353 with the sample zone lab.test, queries it with dig, and stops it. The sandbox has no network, so only this lab server can answer.

bash · try it yourself
dnsmasq --conf-file=$SAMPLES/dns/lab.test.conf --pid-file="$PWD/dns.pid"
for i in $(seq 50); do dig @127.0.0.1 -p 5353 +short lab.test >/dev/null 2>&1 && break; sleep 0.1; done
dig @127.0.0.1 -p 5353 www.lab.test
kill "$(cat dns.pid)"

; <<>> DiG 9.18.39-0ubuntu0.24.04.8-Ubuntu <<>> @127.0.0.1 -p 5353 www.lab.test
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 44606
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
;; QUESTION SECTION:
;www.lab.test.			IN	A

;; ANSWER SECTION:
www.lab.test.		0	IN	A	10.10.0.10

;; Query time: 0 msec
;; SERVER: 127.0.0.1#5353(127.0.0.1) (UDP)
;; WHEN: Sun Nov 22 10:04:55 UTC 2026
;; MSG SIZE  rcvd: 57

How to read it:

  • status: NOERROR and ANSWER: 1: the name exists and has one A record. NXDOMAIN would mean the name doesn't exist; SERVFAIL, the server couldn't answer; REFUSED, it won't answer you.
  • flags: qr (a response), aa (authoritative answer, from the zone's own server), rd (recursion desired, set by dig), ra (recursion available).
  • ANSWER SECTION: name, TTL (here 0: dnsmasq serves local records uncached), class IN, type, value.
  • OPT PSEUDOSECTION: EDNS0, here allowing UDP answers up to 1232 bytes (the size recommended since DNS Flag Day 2020 to avoid fragmentation).

Now the other record types, with +short for just the values:

bash · try it yourself
dnsmasq --conf-file=$SAMPLES/dns/lab.test.conf --pid-file="$PWD/dns.pid"
for i in $(seq 50); do dig @127.0.0.1 -p 5353 +short lab.test >/dev/null 2>&1 && break; sleep 0.1; done
for q in "lab.test MX" "lab.test TXT" "intranet.lab.test A"; do
    echo "== $q"; dig @127.0.0.1 -p 5353 +short $q
done
echo "== PTR for 10.10.0.53"; dig @127.0.0.1 -p 5353 +short -x 10.10.0.53
echo "== a name that doesn't exist, and a public name:"
dig @127.0.0.1 -p 5353 nope.lab.test | grep -o 'status: [A-Z]*'
dig @127.0.0.1 -p 5353 example.com | grep -o 'status: [A-Z]*'
echo "== the same query over TCP:"; dig @127.0.0.1 -p 5353 +tcp +short www.lab.test
kill "$(cat dns.pid)"
== lab.test MX
10 mail.lab.test.
== lab.test TXT
"v=spf1 ip4:10.10.0.25 -all"
== intranet.lab.test A
www.lab.test.
10.10.0.10
== PTR for 10.10.0.53
ns.lab.test.
== a name that doesn't exist, and a public name:
status: NXDOMAIN
status: REFUSED
== the same query over TCP:
10.10.0.10
  • The MX record says mail for lab.test goes to mail.lab.test (preference 10, lower wins).
  • The TXT record is an SPF policy: only 10.10.0.25 may send mail for the domain, everything else fails (-all).
  • intranet.lab.test is a CNAME: dig follows the alias and prints both steps.
  • The PTR maps 10.10.0.53 back to ns.lab.test. Reverse records are set by whoever controls the address block, so they are hints, not proof.
  • example.com is REFUSED: this server is authoritative for lab.test only and does no recursion, which is the correct configuration for an authoritative server (an open resolver would be an amplifier, see UDP and Amplification).
  • DNS also runs over TCP port 53, for large answers, zone transfers, and when a server truncates a UDP answer (TC flag).

DNS as evidence

Resolver logs (or DNS captured at the edge) answer many security questions. The program classifies a synthetic resolver log the way a hunt would: long, random-looking labels can be tunnelling (data encoded in query names), many NXDOMAIN answers from one host can be domain-generation-algorithm (DGA) malware trying candidates, and young look-alike domains can be phishing.

python · try it yourself
import math
from collections import Counter

log = [  # (client, query, rcode): synthetic lab resolver log
    ("10.10.0.5", "www.lab.test", "NOERROR"), ("10.10.0.5", "mail.lab.test", "NOERROR"),
    ("10.10.0.7", "a1b2c3d4e5f60718293a4b5c6d7e8f90a1b2c3d4.t.tunnel.example", "NOERROR"),
    ("10.10.0.7", "9f8e7d6c5b4a39281706f5e4d3c2b1a0f9e8d7c6.t.tunnel.example", "NOERROR"),
    ("10.10.0.9", "qzkxjvwtrp.example", "NXDOMAIN"), ("10.10.0.9", "mbvlqhzxtw.example", "NXDOMAIN"),
    ("10.10.0.9", "kwpzrxqjvd.example", "NXDOMAIN"), ("10.10.0.9", "hxlqzvmwpk.example", "NXDOMAIN"),
    ("10.10.0.5", "1ab-test.example", "NOERROR"),
]

def entropy(s):
    c = Counter(s)
    return -sum(n / len(s) * math.log2(n / len(s)) for n in c.values())

nx = Counter(cli for cli, _, rc in log if rc == "NXDOMAIN")
for cli, q, rc in log:
    first = q.split(".")[0]
    flags = []
    if len(first) > 30 and entropy(first) > 3.5:
        flags.append(f"long high-entropy label ({len(first)} chars, entropy {entropy(first):.2f}): possible tunnelling")
    if rc == "NXDOMAIN" and nx[cli] >= 3:
        flags.append(f"one of {nx[cli]} NXDOMAINs from {cli}: possible DGA")
    looks = q.translate(str.maketrans("10", "lo"))      # 1 -> l, 0 -> o, the usual swaps
    if "lab" in looks and "lab" not in q:
        flags.append("look-alike of lab.test (digit for letter)")
    print(f"{cli:<10} {q[:42]:<43} {rc:<9} {'; '.join(flags) or 'ok'}")
10.10.0.5  www.lab.test                                NOERROR   ok
10.10.0.5  mail.lab.test                               NOERROR   ok
10.10.0.7  a1b2c3d4e5f60718293a4b5c6d7e8f90a1b2c3d4.t  NOERROR   long high-entropy label (40 chars, entropy 3.97): possible tunnelling
10.10.0.7  9f8e7d6c5b4a39281706f5e4d3c2b1a0f9e8d7c6.t  NOERROR   long high-entropy label (40 chars, entropy 3.97): possible tunnelling
10.10.0.9  qzkxjvwtrp.example                          NXDOMAIN  one of 4 NXDOMAINs from 10.10.0.9: possible DGA
10.10.0.9  mbvlqhzxtw.example                          NXDOMAIN  one of 4 NXDOMAINs from 10.10.0.9: possible DGA
10.10.0.9  kwpzrxqjvd.example                          NXDOMAIN  one of 4 NXDOMAINs from 10.10.0.9: possible DGA
10.10.0.9  hxlqzvmwpk.example                          NXDOMAIN  one of 4 NXDOMAINs from 10.10.0.9: possible DGA
10.10.0.5  1ab-test.example                            NOERROR   look-alike of lab.test (digit for letter)

How DNS abuse is detected

  • Query logging on resolvers (or passive DNS from the network), kept long enough to look back during incidents.
  • Unusual names: long labels, high entropy, many unique subdomains under one domain (tunnelling); bursts of NXDOMAIN (DGA, misconfiguration); newly registered or look-alike domains.
  • Unusual resolvers: hosts querying external resolvers directly, or DNS-over-HTTPS to unapproved providers, which bypasses your logging and filtering.
  • Changes in your own zones: new records, changed NS or MX, CNAMEs pointing to resources that no longer exist.

How it is protected

  • Authoritative servers: no recursion, zone transfers (AXFR) only to secondary servers, DNSSEC signing, registrar lock on the domain.
  • Resolvers: recursion only for your clients, DNSSEC validation, response rate limiting, logging; force clients to use them (block outbound 53 and known DoH endpoints elsewhere).
  • Records: CAA to restrict certificate issuance, SPF/DKIM/DMARC for mail, regular review for dangling CNAMEs.

Pitfalls

  • Trusting PTR records as identity. Anyone who controls an address block can make its reverse name say anything.
  • Logging only the queries that succeed. NXDOMAINs are often the most interesting part.
  • Testing with dig against your laptop's resolver and forgetting caching: the answer may be minutes old. Query the authoritative server (@server) to see the current state.

Practice

1. What does the flag aa mean, and would you see it from a recursive resolver?

Authoritative answer: the response comes from a server that hosts the zone. A recursive resolver answering from its cache doesn't set it.

2. A host makes 4,000 queries an hour to unique subdomains of one domain, each with a 50-character random label. What do you suspect and what do you check next?

DNS tunnelling or exfiltration. Check the record types (TXT and NULL are common), the answer sizes, the domain's age and owner, and the process on the host that made the queries.

3. Why is an authoritative server that also answers recursive queries for anyone a problem?

It is an open resolver: it can be used for reflection and amplification attacks, and it can be targeted with cache-poisoning attempts because anyone can make it query arbitrary names.

Test yourself

What does status REFUSED from the lab server for example.com mean?

  1. example.com doesn't exist
  2. The server won't answer that query (it is authoritative for lab.test only and does no recursion)
  3. The network is down
  4. The answer was truncated

Which record type holds an SPF policy?

  1. MX
  2. TXT
  3. PTR
  4. CAA

Many NXDOMAIN answers for random-looking names from one host suggest what?

  1. DNS tunnelling
  2. Malware using a domain-generation algorithm
  3. A zone transfer
  4. An open resolver

Why is a dangling CNAME a risk?

  1. It slows down resolution
  2. If it points to a deleted cloud resource, someone else can claim that resource and serve content under your name
  3. It disables DNSSEC
  4. It leaks the zone file