DNS Tunneling: Recognizing Data Smuggled in Queries
Your firewall is strict. Web traffic goes through a proxy, unknown ports are closed, and outbound connections from servers are locked down to a short list. And yet there is one protocol that almost every organization lets out unconditionally, because without it nothing works: DNS. A name lookup is such an ordinary, harmless-looking thing that most networks never inspect it at all. That is precisely why people who want to move data quietly in or out of a network have long used DNS as the delivery van.
This guide is written entirely from the defender's chair. It will not explain how a tunnel is built. It will explain what one looks like in your query log, so you can recognize it. You will learn the six patterns that give tunneling away, and how to turn each into a simple detection rule against your log. You will learn which perfectly innocent services trigger those rules (there are several). And you will learn what to do in the first twenty minutes after a rule fires. It assumes you already have a query log flowing to a collector. If not, start with turning your resolver into a sensor and come back.
In this guide
- Why DNS is the smuggler's favorite door
- What the defender observes: six patterns
- Turning patterns into detection rules
- The false positives you will meet on day one
- Triage: the first twenty minutes after a rule fires
- The pattern reference table
- Keeping the rules alive
- Where to go next
Why DNS is the smuggler's favorite door
Think of your resolver as a mail room. Any machine in the building can hand it an envelope addressed to any name in the world. The mail room will faithfully forward it up the chain until it reaches the servers responsible for that name, then bring the reply back. The mail room never opens the envelope. It only reads the address. Now notice something: the address line itself can be quite long, and whoever runs the destination gets to read every character of it. If you can write on the envelope, you can send a message without ever putting anything inside.
That is the whole idea of DNS tunneling, described at the level a defender needs. Information is carried in the names being asked about (the outbound direction) and in the answers coming back (the inbound direction). It is carried there rather than in a normal connection your firewall would inspect. Your resolver forwards any question about any domain, and the owner of a domain controls what its name servers reply. Because of that, a domain set up for this purpose becomes a two-way channel that rides entirely on lookups your network already permits.
Two consequences matter for you. First, a tunnel never has to talk to its destination directly. Your own resolver carries the traffic on its behalf. That is why firewall rules that block the client from reaching the outside world do not stop it. Second, everything about it is visible in the query log, because every message passes through the mail room. You cannot read the message, but you can see that a client is mailing a suspicious number of very long, very strange envelopes to the same address. That is what you hunt for.
What the defender observes: six patterns
Tunneled data has to fit inside the shape of a DNS question and answer, and that shape leaves fingerprints. None of these six is proof on its own; two or three together from the same client are worth dropping what you are doing.
1. Unusually long query names
Ordinary names are short because humans type them. A name has hard limits (each dot-separated label is at most 63 characters, the whole name at most 253). Something that wants to move data will push toward those limits to carry more per query. Names that run to a hundred characters or more are the first thing that stands out in a sorted list. That is especially true with several long labels stacked in front of a short domain.
2. High-entropy, random-looking subdomains
Entropy is a measure of how unpredictable a string is. mail has low entropy; x7q2mv9pk0zt4bh1 has high entropy. Encoded data looks like the second one because it has to: it is a payload rendered into characters DNS allows. A domain whose subdomains look like nothing a human would name, and are different on every query, is showing you encoded content.
3. A very high query rate to one domain from one client
Each query carries only a small amount of data, so moving anything meaningful needs a lot of queries. A workstation that resolves thousands of distinct names under one domain in an hour is doing something no browser does. Compare it with the same client's rate to any other domain and with other clients' rate to the same domain. A tunnel is an outlier on both axes.
4. Unusual record types in bulk
Clients overwhelmingly ask for addresses: A and AAAA records. Other types exist for other jobs: TXT holds free text, MX names mail servers, NULL and CNAME have their own roles. Because TXT and similar types can carry more arbitrary data in the answer, a tunnel's inbound direction often prefers them. A single workstation making a steady stream of TXT queries is odd. Your mail server doing it is not (more on that below).
5. Large responses
Most DNS answers are tiny. A steady flow of answers near the size limits, to the same client from the same domain, suggests data is riding in the response. If your log records response size, sort by it; if it does not, response size is worth adding.
6. Steady query volume with no matching connection
Normally a lookup is followed by a connection to the address returned. A client that resolves a domain heavily but never connects to anything it was told about, day after day, is using the lookups themselves as the channel. This one needs a second data source (firewall or flow logs). And the guide on egress monitoring on a budget covers getting that view cheaply.
What several patterns together look like
Here is an illustrative excerpt, in a generic log layout, of the kind of run that combines patterns 1, 2, 3, and 4 from a single client:
14:02:11.203 client=10.20.9.203 qtype=TXT qname=0a9f3c1e7b2d4a6c8e0f1a3b5c7d9e1f2a4b6c8d.t.updates-cdn.example rcode=NOERROR size=412 14:02:11.417 client=10.20.9.203 qtype=TXT qname=1b8e2d0f6a3c5b7d9f1e2a4c6b8d0e2f3a5c7d9e.t.updates-cdn.example rcode=NOERROR size=409 14:02:11.622 client=10.20.9.203 qtype=TXT qname=2c7d1e9f5b4a6c8e0d2f3b5a7c9e1d3f4b6a8c0d.t.updates-cdn.example rcode=NOERROR size=415 14:02:11.830 client=10.20.9.203 qtype=TXT qname=3d6c0f8e4a5b7d9f1c3e4a6b8d0f2e4a5c7b9d1e.t.updates-cdn.example rcode=NOERROR size=411 14:02:12.041 client=10.20.9.203 qtype=TXT qname=4e5b9e7d3f6a8c0e2b4d5f7a9c1e3d5b6a8c0e2f.t.updates-cdn.example rcode=NOERROR size=406
Read it the way the rules will. One client. One registered domain, with a plausible-sounding name chosen to look like an update service. A new forty-character label on every line, every fifth of a second, none of them repeating, so nothing is served from cache. All TXT, all answered, all with responses far larger than an address would need. No single line is alarming; the run is. When you check, nobody else on the network has ever resolved that domain. The firewall shows no connection from the client to anything the answers contained. That combination is what the rest of this guide teaches you to find on purpose rather than by luck.
Turning patterns into detection rules
Every pattern above becomes a question you can ask a parsed query log. The exact syntax depends on your collector, so the sketches here are generic pseudo-queries; translate them into whatever your search tool speaks. Each one groups by client and by the registered domain. That is the part of the name someone actually owns, such as example.com in a.b.c.example.com. The reason is that tunnels vary the subdomain constantly while the owned domain stays fixed.
Length threshold
FROM dns_log WHERE window = last 24h SELECT client, qname, LENGTH(qname) AS len WHERE len > 80 ORDER BY len DESC
Start with a generous threshold and look at what comes back. You will immediately discover which legitimate services use long names on your network. Add them to an allowlist and lower the threshold until the list is short enough to read weekly.
Per-client, per-domain query counts over a window
FROM dns_log WHERE window = last 1h SELECT client, registered_domain(qname) AS domain, COUNT(*) AS queries GROUP BY client, domain HAVING queries > 500 ORDER BY queries DESC
The interesting number is not the raw count but how far it sits above that client's usual behavior and above other clients' interest in the same domain. A domain that one client hits five hundred times an hour while nobody else touches it is the shape you are after.
Unique-subdomain counts per domain
FROM dns_log WHERE window = last 24h
SELECT client, registered_domain(qname) AS domain,
COUNT(DISTINCT qname) AS unique_names
GROUP BY client, domain
HAVING unique_names > 200
This is the single most useful tunneling query. A browser visiting a big site might resolve a few dozen names under it. Hundreds or thousands of distinct names under one domain, from one client, in a day, is a payload being sent piece by piece. Each piece needs a new name so the resolver's cache does not swallow it.
Record-type ratios
FROM dns_log WHERE window = last 24h SELECT client, qtype, COUNT(*) AS n GROUP BY client, qtype -- then compare each client's TXT / NULL / CNAME share with the network average
Compute what share of each client's queries are for types other than A and AAAA, and flag clients well above the network norm. Expect mail servers and a few security agents to top the list legitimately; the rule is for the workstation that suddenly joins them.
A random-looking label heuristic
You do not need a perfect entropy calculation. Simple signals work. These include the ratio of digits to letters in a label, the longest run of consonants, whether the label contains any dictionary word, or the count of distinct characters. Score labels, average per domain, and sort. Names that humans chose cluster at the bottom; encoded payloads and machine-generated content-delivery names cluster at the top. The next section explains how to tell those two apart.
Tip: run every rule as a report before you run it as an alert. A week of daily reports teaches you what your network normally looks like and builds your allowlist. Only when a rule produces a short, readable list most days is it ready to page anyone.
The false positives you will meet on day one
Your first length report will be full of long, random-looking names, and nearly all of them will be legitimate. This is not a failure of the rule; it is the rule teaching you about your network. The usual suspects:
- Content delivery networks. Large sites serve files from names that encode cache keys, regions, and version hashes. Long, high-entropy, and entirely normal. The giveaway is breadth: many clients resolve them, and the lookups are followed by ordinary web connections.
- Security products. Endpoint protection and filtering agents commonly check reputation by encoding a file hash or a URL fragment into a query name under the vendor's domain. That is, technically, data in a query name, on purpose. Every managed endpoint does it, which is how you recognize it.
- Mail-authentication lookups. Your mail server verifies incoming mail by fetching
TXTrecords for sender domains, and it does so constantly. It will always top the record-type ratio report. Allowlist the mail server for that rule, not for the others. - Cloud and collaboration services. Service discovery, per-tenant hostnames, and health probes generate long, structured, sometimes ugly names at high rates. They are shared by many clients and resolve to the provider's ranges.
- Reverse lookups and device discovery. Logging tools that turn addresses back into names, and devices announcing themselves, produce bursts of odd-looking queries that are entirely local in origin.
Two principles keep allowlisting from becoming a hole. Allowlist by domain, not by client, so an allowlisted workstation cannot later tunnel through any domain it likes. And allowlist per rule: the mail server is excused from the record-type check, not from the unique-subdomain check. Review the list every few months; services get retired, and a domain you excused last year may be one you would rather watch now.
Triage: the first twenty minutes after a rule fires
A rule has fired. Before you touch anything, answer four questions in order; each narrows the next.
- Which client, and what is it? Turn the address into a hostname and a person or a role using DHCP leases, your inventory, or the directory. A mail server behaving like a mail server ends the investigation. A receptionist's PC making thousands of
TXTqueries does not. - Since when? Search the log for the client-and-domain pair going back as far as your retention allows. Something that started at a precise moment last Tuesday is different from something that has always been there. The start time also tells you which other logs to open.
- Who else resolves this domain? If it is half the company, it is almost certainly a service. If it is one machine, or a handful that share nothing in common except this domain, keep going.
- What else does the client do? Open the firewall and proxy logs around the start time. Are there matching connections to the answered addresses, or none at all? Any other new destinations? Any new process on the endpoint, if you have endpoint logging? The DNS log raised the question; the other logs answer it.
Then decide. If the domain is a recognizable service and the pattern is shared across the network, allowlist it and move on. If it is unknown, one client, and started recently, treat it as a live incident. In that case, isolate the client from the network rather than just blocking the domain. Blocking alone tells whoever is on the other end that you noticed. Preserve the endpoint, and hand it to your incident process. If it is somewhere in between, block the domain at the resolver, keep watching the client, and write down what you found. The sinkholes and blocklists guide covers making that block also tell you who else tries to reach the name.
The pattern reference table
Pin this next to your desk. It condenses everything above into what you see, what usually explains it, what should worry you, and the first thing to check.
| Pattern | Likely benign | Likely worrying | First check |
|---|---|---|---|
| Very long query names | Content delivery, cloud service discovery, security agents; seen from many clients | One client, one unknown domain, labels near the length limit, different every time | How many clients resolve this domain? |
| Random-looking subdomains | Cache keys and hashes under well-known domains that also get normal web connections | Unknown domain, no web connections follow, high query rate | Do connections to the answered addresses appear in firewall logs? |
| High query rate, one client, one domain | Chatty application, monitoring poller, misconfigured retry loop (usually with failures) | Thousands of successful queries for distinct names, steady all day and all night | Distinct names or the same name repeated? Since when? |
| Bulk TXT or other unusual types | Mail server verifying senders; a few security agents | A workstation or an unexpected server doing it | Is this client supposed to send or verify mail? |
| Large responses | Long TXT policy records, big address sets for large services | Consistently near the size limit, one client, one domain | What does the answer contain, and who else receives it? |
| Lookups with no matching connection | Prefetching, reputation checks, a service that is down | Sustained for days, one domain, one client, high rate | Correlate with flow or firewall logs over a full day |
Keeping the rules alive
Detection rules decay. Thresholds that were quiet in spring get noisy after a new application rolls out; an allowlist that was tidy grows until it excuses everything. A few habits keep the sensor honest:
- Review the reports weekly, even when nothing fires, so you know what normal looks like. The weekly hunting workflow makes this a fixed thirty-minute routine.
- Record every allowlist entry with a reason and a date. "Excused because it is our mail server" ages better than an unexplained domain in a text file.
- Re-baseline after big changes. A new endpoint agent, a migration to a new cloud suite, or a new branch office all shift what normal looks like. Expect a noisy week and tune deliberately rather than muting the rule.
- Test the rule occasionally. From a lab machine, resolve a few hundred distinct made-up names under a domain you control and confirm the unique-subdomain report lights up. A rule you have never seen fire is a rule you cannot trust.
Remember, too, what the rules are not. They will not catch a tunnel that runs slowly enough to hide under your thresholds. And they cannot see clients that bypass your resolver entirely, which is why closing that bypass matters so much. Nothing here replaces endpoint protection or egress control; the DNS view is one sensor among several. Its strength is cost and coverage: it watches every client, all the time, for the price of a log line.
Where to go next
You can now look at a query log and recognize the shape of data being smuggled through it: long, random, high-rate, odd-typed, and unmatched by real connections. You can turn each of those shapes into a simple report. You know which legitimate services will show up first and how to excuse them safely. And you have a twenty-minute triage sequence for the day a rule finally fires for real. Tunneling is one of two behavior families the query log reveals. The other, periodic check-ins and storms of generated names, is covered in beaconing and domain-generation patterns. The full set of guides is collected at DNS as a Threat Sensor.
Put this into practice with SysPeep Monitor
Spotting a tunnel in the log is detective work, but the sensor behind it needs plain old monitoring. It needs resolvers that stay up, a collector that keeps ingesting, and disks that do not fill up mid-incident. SysPeep Monitor keeps an eye on those servers and their resources from one console and alerts you when one goes quiet. The free trial runs on any Windows machine.
Download Free TrialLearn About SysPeep