Home › Topics › DNS as a Threat Sensor › DNS Beaconing and DGA

Beaconing and Domain-Generation Patterns in DNS


Most of what a compromised machine does is boring. It sits there. Every so often it checks in with whoever controls it, asks whether there is anything to do, and goes back to sitting. Sometimes it cannot even find its controller, and it spends its time guessing names in the hope that one of them answers. Neither behavior moves much data or trips a bandwidth alarm. Both are nearly invisible in a firewall log full of ordinary web traffic. Both, however, leave a distinctive rhythm in your DNS query log, because every check-in and every guess begins with a lookup.


This guide teaches you to hear that rhythm. It covers the two behavior families: beaconing (regular repeated lookups of the same name) and domain generation (storms of lookups for random-looking names that mostly fail). It also covers two signals that support both. One is the rare domain that only one client on your network has ever asked for. The other is the brand-new domain that did not exist until recently. For each you will get the detection logic in plain language, the innocent things that look identical, and a triage sequence. Everything here is written from the defender's side, using only what the query log shows you. It assumes you have one. If you do not, turning your resolver into a sensor is the place to begin.


In this guide

  • Beaconing as seen in DNS
  • Domain generation as seen by the defender
  • The two rhythms, side by side in a log
  • Two supporting signals: rare and brand-new domains
  • Detection logic, signal by signal
  • The legitimate causes that look exactly the same
  • Triage: from a hit to a decision
  • The signal table
  • Where to go next

Beaconing as seen in DNS


A beacon is a periodic check-in: software on a client contacts a controlling server at a fixed interval to ask for instructions. Picture an employee who, every fifteen minutes, all day and all night, phones the same number, says "anything for me?", and hangs up. Individually each call is trivial. The pattern is what gives it away, and the pattern begins in DNS, because before each call the client asks your resolver where the name lives.


In the query log a beacon looks like this: the same client, the same name, over and over, with lookups spaced at a suspiciously regular interval. Sometimes the interval is exact; sometimes a small random delay is added to blur it, but the average still holds over a day. There is a technical reason the lookups repeat at all. Every DNS answer carries a TTL (time to live), the number of seconds a client is allowed to keep using the answer before asking again. A short TTL, such as one minute, forces the client to look the name up afresh almost every time it checks in. That is exactly why a beacon's rhythm shows up so clearly at the resolver. A long TTL would hide most of the repeats inside the client's cache; a short one hands the defender a metronome.


Beaconing is visible in more than one place, and it is worth being clear about what each view adds. The guide on beaconing patterns in flow data covers the same behavior seen as connections: regular, small, same-sized sessions to one address. The DNS view differs in three useful ways. It shows you a name rather than an address, which is far more meaningful when the address belongs to a cloud provider. It catches beacons even when the connection never happens, because a client whose controller is offline still asks DNS on schedule. And it is cheaper: you already have the log. Use both when you can; when you can only afford one, the query log is the better first sensor.


Domain generation as seen by the defender


Some malicious software does not carry a fixed controller name, because a fixed name is easy to block. Instead it computes a list of candidate names and tries them one after another until one answers. From your chair, you do not need to know how the list is made. What you need to recognize is what it produces in your log. A single client issues a burst of lookups for names that look like nobody chose them. Nearly all fail with NXDOMAIN, the response code meaning "no such name," until, sometimes, one of them succeeds.


Three features make this storm distinctive. The names are random-looking and often share a structure (similar lengths, the same top-level domain, the same character mix). The failure rate is extreme; ordinary clients get a small trickle of NXDOMAIN from typos and stale settings, not hundreds in a row. And the burst has a beginning and an end, then repeats on a schedule, because the software tries its list, gives up, and tries again later. The most important line in the storm is the one that does not fail. A successful answer amid a sea of NXDOMAIN is the moment the client found its controller. And that name and address are what you pull out for blocking and for searching across every other client.


The two rhythms, side by side in a log


Here is an illustrative excerpt in a generic log layout. The first block is a beacon; the second is a generation storm. Both are from the same workstation, which is not unusual, because software that beacons often falls back to guessing when its usual name stops answering.


02:00:03 client=10.20.9.203 qname=sync.status-relay.example qtype=A rcode=NOERROR answer=198.51.100.23 ttl=60
02:15:03 client=10.20.9.203 qname=sync.status-relay.example qtype=A rcode=NOERROR answer=198.51.100.23 ttl=60
02:30:04 client=10.20.9.203 qname=sync.status-relay.example qtype=A rcode=NOERROR answer=198.51.100.23 ttl=60
02:45:03 client=10.20.9.203 qname=sync.status-relay.example qtype=A rcode=NOERROR answer=198.51.100.23 ttl=60

03:00:03 client=10.20.9.203 qname=sync.status-relay.example qtype=A rcode=SERVFAIL answer=-
03:00:04 client=10.20.9.203 qname=qzvkmtplwrhb.example qtype=A rcode=NXDOMAIN answer=-
03:00:04 client=10.20.9.203 qname=fjdnexuwaosc.example qtype=A rcode=NXDOMAIN answer=-
03:00:05 client=10.20.9.203 qname=lrpykvhgtbmq.example qtype=A rcode=NXDOMAIN answer=-
03:00:05 client=10.20.9.203 qname=wbcsdnaortie.example qtype=A rcode=NXDOMAIN answer=-
03:00:06 client=10.20.9.203 qname=hxmqtlzpvcek.example qtype=A rcode=NOERROR answer=203.0.113.77

In the first block, notice what a human would never produce. You see the same name at two in the morning, every fifteen minutes to within a second. It has a sixty-second TTL that guarantees each check-in asks the resolver again. In the second block the usual name has stopped answering (a SERVFAIL, meaning the resolver could not get an answer at all). Within a second the client starts producing twelve-letter names with no vowel pattern, the same length, the same top-level domain. Each one fails. The last line is the one that matters: a name in that same strange shape that resolved. That address is your lead, and your first question is whether any other client on the network has ever been given it.


Two supporting signals: rare and brand-new domains


Both behaviors above are strengthened by two questions you can ask about any domain in the log.


Is it rare? A rare domain is one that only a single client on your network has ever resolved, or only a tiny handful with nothing in common. Legitimate services spread: an update server, a collaboration suite, a news site all get resolved by many clients. A controller name, by contrast, is known only to the machines that were compromised. Rarity across your own network is one of the strongest signals you own, and it costs nothing but a count.


Is it new? "New" has two senses, and both are useful. New to your network means your log has never contained this domain before. You can know that precisely by maintaining a first-seen table built from your own history. New to the world means the domain was registered recently. You can check that fact through public registration data for a given name. Malicious infrastructure is frequently set up shortly before it is used, while the services your business depends on have usually existed for years. You cannot bulk-check registration age for every name in a busy log. But for the handful of rare, first-seen domains a client resolved this week, it is a quick and revealing lookup.


Detection logic, signal by signal


Each signal becomes a report against the parsed query log. The sketches below are generic pseudo-queries; translate them into your collector's search language. The unit of analysis is always the client-and-name pair or the client-and-domain pair. That is because all four signals are about what one machine does, not about the network in aggregate.


Interval regularity per client and name

FROM dns_log WHERE window = last 24h
SELECT client, qname, COUNT(*) AS lookups,
       AVG(gap_seconds) AS mean_gap,
       STDDEV(gap_seconds) AS gap_spread
-- gap_seconds = time since this client's previous lookup of the same qname
GROUP BY client, qname
HAVING lookups > 50 AND gap_spread < 0.2 * mean_gap
ORDER BY gap_spread ASC

The idea: for each client-and-name pair, compute the gaps between consecutive lookups, then ask how consistent those gaps are. A human's lookups are bursty and stop at night. A scheduled check-in produces gaps that cluster tightly around one value, and the report sorts the tightest clusters to the top. The lookups > 50 floor keeps one-off repeats out. If jitter has been added, the spread widens but the mean stays put; looking at a full day rather than an hour lets the average reassert itself.


NXDOMAIN rate per client

FROM dns_log WHERE window = last 1h
SELECT client,
       COUNT(*) AS total,
       SUM(rcode = 'NXDOMAIN') AS failed,
       COUNT(DISTINCT qname WHERE rcode = 'NXDOMAIN') AS distinct_failed
GROUP BY client
HAVING failed > 100 AND distinct_failed > 50
ORDER BY distinct_failed DESC

Two counts matter, not one. Raw failures catch a client stuck retrying a single dead name, which is annoying but usually benign. Distinct failed names catch a client trying many different names, which is the generation pattern. Pair this with a second query that lists the names themselves. That lets you eyeball whether they look like typos, like an application's expected names, or like nothing anyone would type.


First-seen names per client, and rarity

-- maintain a table: domain, first_seen_at, first_seen_by, client_count
FROM dns_log WHERE window = last 7d
SELECT registered_domain(qname) AS domain,
       MIN(timestamp) AS first_seen,
       COUNT(DISTINCT client) AS clients
GROUP BY domain
HAVING first_seen within last 7d AND clients = 1
ORDER BY first_seen DESC

Build the first-seen table once from all the history you have, then update it daily. The report then asks a simple question: which domains appeared for the first time this week, and how many clients resolve them? A new domain resolved by one client is the shape you care about. A new domain resolved by two hundred clients is a rollout, and you probably got an email about it.


Tip: the first-seen table is small enough to keep for years even if raw log lines age out in weeks. When an incident eventually asks "when did this client first talk to that name?", the table answers instantly, long after the original lines are gone.


The legitimate causes that look exactly the same


Every one of these signals has innocent twins, and you will meet all of them in your first week. Knowing them in advance saves you from chasing your own infrastructure.


  • Your own monitoring. The most regular beacon on any network is the monitoring system, polling every device by name on a fixed schedule. Time-synchronization clients, backup agents, and license checks are close behind. Expect the regularity report to be topped by things you installed on purpose; allowlist them by name and move on.
  • Typos and search-suffix churn. When someone types a short name that does not exist, the client appends each entry of its search-suffix list in turn and tries again. That produces a small NXDOMAIN burst from one keystroke. Multiply by a building of people and you get a steady background of failures with obviously human-shaped names.
  • Misconfigured or orphaned applications. A server that was decommissioned last year is still being looked up by the three things nobody told. The names are recognizable, the interval is regular, the answer is always NXDOMAIN, and it has been going on forever. A useful finding, just not a security one.
  • Expired services and dead cloud endpoints. Applications whose vendors retired a hostname keep asking for it, sometimes aggressively. Look for a name that resolved fine until a certain date and has failed ever since.
  • Security tools and browsers. Some endpoint agents deliberately resolve made-up names to test whether the resolver lies about nonexistent domains. Browsers probe for the same reason. Both produce small, occasional bursts of random names from every managed client, which is how you tell them from a single machine's storm.
  • Legitimately rare domains. One accountant uses one supplier's portal that nobody else needs. Rarity alone is a prompt to look, not a verdict; it needs a second signal before it becomes a concern.

Triage: from a hit to a decision


A report has surfaced a client-and-name pair. Work through this sequence; each step narrows the next, and most investigations end early.


  • Identify the client. Address to hostname to owner, using DHCP leases, your inventory, or the directory. Is it a workstation, a server, a device, or something you cannot account for? The last category is a finding in itself.
  • Identify the name. Does the domain belong to a service you use, a vendor you know, or nothing recognizable? Check how many other clients resolve it, when your network first saw it, and, for an unrecognized name, how recently it was registered.
  • Establish the timeline. Search back as far as retention allows. A beacon that started at an identifiable moment is different from one that has always existed. Note the exact start; it is where you will look in every other log.
  • Look for the successful answer. For a storm of failures, find the lines that did not fail. Those names and addresses are the lead. Search the whole network for any other client that resolved them.
  • Check the other logs. Around the start time and around a few of the check-ins, open firewall, proxy, and endpoint logs. Did a connection follow the lookup? To where? Did a new process appear, a new scheduled task, a new browser extension?
  • Decide. Benign: allowlist by name with a reason and a date. Suspicious but unproven: block the domain at the resolver, sinkhole it so you learn who else tries, and keep the client under observation. Confirmed or likely: isolate the client, preserve it, and escalate through your incident process. Blocking a name is not the same as fixing a machine.

One note on the "suspicious but unproven" middle ground, because it is where most findings land. Blocking the name at the resolver stops the current check-in path but tells you nothing new. Sinkholing it makes the name resolve to an internal address that logs every connection. That turns the block into a tripwire that identifies every client with the same problem. The sinkholes and blocklists guide explains the setup.


The signal table


SignalWhat it looks like in the logCommon benign causeWorrying combinationFirst action
Regular repeated lookups (beacon)Same client, same name, tight interval, day and night; short TTL on the answerMonitoring, time sync, backup agents, license checksUnknown domain, one client, started recently, connections follow each lookupCheck how many clients resolve the name and when it was first seen
NXDOMAIN stormOne client, hundreds of distinct failed names in minutes, random-looking, repeating on a scheduleTypos with suffix churn, orphaned application, retired vendor endpointRandom names with a shared structure, plus one or two that resolvedList the failed names; find the successful ones
Rare domainResolved by one client only, across your entire log historyA niche supplier portal, a personal serviceRare plus regular interval, or rare plus recently registeredIdentify the owner of the client and ask
Brand-new domainFirst appears in your log this week; registered recentlyA newly adopted service, a vendor's new endpoint, a marketing campaignNew plus rare plus no recognizable business purposeCheck registration age and other clients
Lookups that never connectName resolves, but firewall shows no session to the answered addressPrefetching, reputation checks, a service that is downSustained for days from one client at a regular intervalCorrelate with flow or firewall logs over a full day

Notice the shape of the "worrying combination" column: it is always two or more signals together. Regularity alone is your monitoring system. Rarity alone is an accountant. Novelty alone is a rollout. Rarity, novelty, and regularity from the same client toward the same name, starting last Tuesday, is a machine that needs a visit today.


Where to go next


You can now recognize the two rhythms a compromised client leaves in DNS: the metronome of a check-in and the stutter of a client guessing names. And you can back either with the questions "has anyone else here ever resolved this?" and "did this domain exist last week?" You have the detection logic for each and a list of the innocent things that mimic them. You also have a triage sequence that ends in a decision rather than a shrug. Tunneling, the other behavior family visible in the log, is covered in recognizing data smuggled in queries. The weekly hunting workflow turns these reports into a thirty-minute habit. All the guides in this topic are collected at DNS as a Threat Sensor.


Put this into practice with SysPeep Monitor

The most regular beacon on your network should be your monitoring system, polling every device by name on schedule. And it helps to know exactly what that looks like so you can allowlist it with confidence. SysPeep Monitor discovers your devices, polls them over SNMP, WMI, and SSH, and shows the results on live dashboards and maps. That way, the check-ins you designed are never mistaken for the ones you did not. Try it free on a Windows machine.

Download Free TrialLearn About SysPeep