CTF Arsenal
DFIR/Network Forensics

DNS Analysis & Exfiltration Detection

Concept

DNS queries are rarely blocked by firewalls, making DNS a common covert channel for data exfiltration or C2 (encoding data into subdomain labels). Unusual query patterns — long/random subdomains, high query volume to one domain, or rare record types — are the main indicators.

When to Use

  • pcap or log contains significant DNS traffic.
  • Challenge hints at 'exfiltration' or 'covert channel'.

Workflow

  1. 1
    List all queried domains

    Look for one domain dominating the query count.

  2. 2
    Inspect subdomain labels for encoded data

    Unusually long/base32/hex-looking labels.

  3. 3
    Reassemble the encoded payload across queries

    Concatenate and decode.

  4. 4
    Confirm the destination domain's role

    Attacker-controlled vs legitimate.

Commands

tshark -r FILE_PATH -Y 'dns.flags.response==0' -T fields -e dns.qry.name
tshark -r capture.pcapng -Y 'dns.flags.response==0' -T fields -e dns.qry.name | sort | uniq -c | sort -rn

Lists every DNS query name made, counted and sorted — quickly surfaces a dominant or suspicious domain.

  • dns.flags.response==0 — Only queries (not responses).

When to use: First DNS-specific command on a pcap.

Expected output:

482 aGVsbG93b3JsZA.data.evil-tunnel.com
  2 google.com

Look for: One domain with an abnormally high query count, or subdomains that look like encoded data rather than real hostnames.

Next step: Extract and concatenate the subdomain labels in capture order for that domain.

tshark -r FILE_PATH -Y 'dns.qry.name contains "DOMAIN"' -T fields -e dns.qry.name
tshark -r capture.pcapng -Y 'dns.qry.name contains "evil-tunnel.com"' -T fields -e dns.qry.name

Extracts every query to a specific suspicious domain in order, to reconstruct an exfiltrated payload from the subdomain labels.

When to use: Once a suspicious domain is identified from the frequency count above.

Expected output:

aGVsbG8.data.evil-tunnel.com
d29ybGQ.data.evil-tunnel.com

Look for: Base32/base64/hex-looking subdomain segments.

Next step: Strip the domain suffix, concatenate the remaining labels in order, and decode (base64 -d / base32 -d).

Tools

Tshark / Wireshark

Primary tools for extracting and filtering DNS query data from a capture.

When to use: Any DNS-based investigation.

tshark -r FILE_PATH -Y 'dns'

Example workflow: Frequency count -> isolate suspicious domain -> extract labels in order -> decode.

Findings & Interpretation

Interesting

  • Subdomain labels decoding to readable text/flag content
  • A single domain responsible for the overwhelming majority of DNS queries in the capture

False Positives

  • CDNs and some legitimate services do generate many subdomains naturally (e.g. cache-busting) — check the decoded content's plausibility, not just volume alone

How to Validate

  • Successful decode into coherent text/data is the real confirmation, not query volume alone

Next Step

  • Decoded payload may itself be another encoded/compressed blob — repeat decoding as needed.

Troubleshooting

Decoding the concatenated labels produces garbage.

Likely cause: Wrong packet order (DNS over UDP can arrive out of send-order relative to capture), or wrong encoding assumed (base64 vs base32 vs hex).

Verify: Check the frame/packet timestamp ordering, not just the display order; try each likely encoding.

Fix: Sort by frame.time_relative before concatenating; try base32 if base64 fails (DNS labels are case-insensitive, which suits base32 better).

Recovery: Re-extract with explicit time-based sorting via tshark -E or by exporting to CSV and sorting in a script.

Avoid repeating: Don't assume capture/display order equals transmission order without checking timestamps.