TExcelTAD
Home › Defensive Security: SOC, SIEM, Detection Engineering & Threat Hunting › DNS Beaconing: Interval and Jitter Analysis

DNS Beaconing: Interval and Jitter Analysis

Malware on a compromised laptop needs instructions, so it "calls home" to its command-and-control (C2) server on a schedule: every five minutes, every hour, with some randomness so it is less obvious. Each call usually starts with a DNS lookup of the C2 domain. People don't browse like that: they click in bursts, take breaks, go to lunch. Beaconing detection looks for that machine-like regularity in DNS (or proxy, or connection) logs. Zeek Logs with pandas found a beacon with a perfectly fixed interval; real implants add jitter, and this lesson measures regularity in a way that survives it.

The mechanism, from the defender's side

A beacon has three observable properties:

  1. Periodicity: the gaps between lookups cluster around a sleep time T.
  2. Jitter: implants randomise each sleep, typically by up to a stated percentage (say ±20 % or ±50 %) of T, so the gaps spread out, but far less than a human's.
  3. Persistence: it continues all day and all night, whether or not anyone uses the machine.

Implants also often use rare domains (only one or two hosts in the company ever resolve them), long or random-looking subdomains when data is carried in DNS itself (DNS tunnelling), and low TTLs.

Measuring regularity

For each (host, domain) pair, take the sorted lookup times and the gaps between them. Useful statistics:

  • Coefficient of variation (CV) = standard deviation of the gaps / mean gap. A perfect clock has CV 0. A beacon with uniform jitter of ±J has CV ≈ J / √3 (about 0.29 for ±50 %). Human activity, closer to random arrivals, has CV around 1 or above.
  • Median absolute deviation (MAD) / median: the same idea, robust to the occasional long gap when a laptop sleeps.
  • Share of gaps within ±25 % of the median gap: high for beacons, low for people.
  • Duration and count: how many hours the pattern lasts, and how many lookups it has; a regular pattern over 10 lookups means little, over 70 it means a lot.
python · try it yourself
import numpy as np, pandas as pd

rng = np.random.default_rng(5)
SPAN = 6 * 3600                                                  # six hours of DNS logs, seconds

def beacon(T, jitter):                                           # sleep T seconds +/- jitter (fraction), uniform
    t, out = 0.0, []
    while t < SPAN:
        t += T * (1 + jitter * rng.uniform(-1, 1)); out.append(t)
    return out

def human(n):                                                    # bursts of activity separated by long pauses
    starts = np.sort(rng.uniform(0, SPAN, n // 6))
    return sorted(s + rng.exponential(40) * k for s in starts for k in range(6))

series = {
    ("ws15", "upd.cdn-lab.example"):  beacon(300, 0.20),         # implant: 5 min, 20 % jitter
    ("ws22", "sync.metrics-lab.example"): beacon(60, 0.50),      # implant: 1 min, 50 % jitter
    ("ws03", "time.lab.test"):        beacon(1024, 0.0),         # NTP client: perfectly periodic, but known
    ("ws08", "docs.example"):         human(90),                 # a person reading documentation
    ("ws11", "news.example"):         human(60),
    ("ws19", "intranet.lab.test"):    human(120),
}
rows = []
for (host, dom), times in series.items():
    gaps = np.diff(np.array(times))
    med = np.median(gaps)
    rows.append({"host": host, "domain": dom, "n": len(times), "median_gap": med,
                 "cv": gaps.std() / gaps.mean(),
                 "mad_ratio": np.median(np.abs(gaps - med)) / med,
                 "near_median": np.mean(np.abs(gaps - med) <= 0.25 * med)})
df = pd.DataFrame(rows).round(2)
print(df.to_string(index=False))

KNOWN_PERIODIC = {"time.lab.test"}                               # allow-list with an owner, see the text
cand = df[(df.cv < 0.4) & (df.mad_ratio < 0.35) & (df.n >= 20) & ~df.domain.isin(KNOWN_PERIODIC)]
print("\nBEACON CANDIDATES")
for r in cand.itertuples():
    print(f"  {r.host} -> {r.domain}: {r.n} lookups, every ~{r.median_gap:.0f} s, CV {r.cv}")
host                   domain   n  median_gap   cv  mad_ratio  near_median
ws15      upd.cdn-lab.example  72      299.16 0.12       0.10         1.00
ws22 sync.metrics-lab.example 367       58.53 0.30       0.26         0.48
ws03            time.lab.test  22     1024.00 0.00       0.00         1.00
ws08             docs.example  90       32.93 3.36       0.72         0.18
ws11             news.example  60       26.28 3.35       0.80         0.14
ws19        intranet.lab.test 120       25.99 2.63       0.88         0.10

BEACON CANDIDATES
  ws15 -> upd.cdn-lab.example: 72 lookups, every ~299 s, CV 0.12
  ws22 -> sync.metrics-lab.example: 367 lookups, every ~59 s, CV 0.3

The two implants stand out from the people by an order of magnitude: CV 0.12 and 0.30 against 2.6 to 3.4 for the three humans, whose bursts of clicks (gaps of seconds) followed by long pauses make the gaps wildly uneven. The NTP client is the most regular of all (CV 0.00, a lookup every 1,024 s) and is removed only by the allow-list. The near_median column shows why the choice of statistic matters: with ±50 % jitter only about half of the ws22 implant's gaps (0.48) lie within ±25 % of the median, so a rule that required 60 % there would have missed it, while CV (0.30) and the MAD ratio (0.26) still separate it clearly from people. Note also the count: 367 lookups in six hours from one laptop to a domain nobody else resolves is a strong signal on its own.

When the interval is less obvious

Attackers know these statistics. Long sleeps (hours) give too few lookups per day for confident statistics; heavy jitter (±80 % and more) pushes CV up; implants that only call home during office hours blend into human activity; and DNS caching means a host may not query again until the record's TTL expires, so the DNS log shows the TTL rhythm rather than the beacon. Counter-measures:

  • Use longer windows (days instead of hours) for long sleeps, and look at connection logs (Zeek conn.log, proxy logs) as well as DNS.
  • Combine regularity with rarity: how many hosts resolve this domain, how old the domain is, whether it has ever been seen before (Baselining).
  • Look at payload sizes: beacons send and receive small, similar amounts each time.
  • Look at time-of-day independence: lookups at 03:00 from a laptop whose user is asleep.

How it is detected and fixed

Detection: run the interval analysis daily over DNS resolver logs (or Zeek dns.log) per (host, domain), score candidates with regularity, rarity and duration, and send the top of the list to an analyst or the hunting queue rather than paging; the SIEM-side version is a scheduled search that computes the same statistics per pair (streamstats gaps in SPL, prev() and stdev() in Sentinel KQL). Open-source tools such as RITA (Real Intelligence Threat Analytics) do this on Zeek logs.

Fix and prevention:

  • Force DNS through your resolvers and block outbound DNS (and DNS over HTTPS to public resolvers) from everything else, so every lookup is logged and filterable (Egress Filtering).
  • Protective DNS / response policy zones: refuse to resolve known-bad and newly registered domains.
  • Egress allow-listing for servers: a server that may only reach its update source cannot beacon anywhere else.
  • On a confirmed beacon: isolate the host, block the domain and its addresses, find the process that made the lookups (EDR or Sysmon Event ID 22 links DNS queries to processes), and hand over to incident response.

Pitfalls

  • Allow-listing by domain suffix. *.example style wildcards hide attacker subdomains on the same cloud provider; allow-list exact names with an owner and expiry.
  • Software that beacons legitimately. Update agents, telemetry, monitoring and chat clients are periodic; they appear at the top of the list on day one. Build the allow-list from that first run, deliberately.
  • NAT and proxies. Behind a proxy, all hosts look like one; analyse where the per-host identity still exists (proxy logs with user, resolver logs from internal clients).

Practice

1. A beacon has T = 600 s and uniform jitter ±30 %. What CV do you expect?

The gap is uniform on [420, 780]: standard deviation = 360 / √12 ≈ 104 s, mean 600 s, CV ≈ 0.17 (= 0.3 / √3). Well below the 0.4 threshold.

2. In the program, raise the jitter of the ws22 implant to 0.9. Which criteria fail?

With ±90 % jitter the gaps are spread uniformly over [6, 114] s: CV ≈ 0.9 / √3 ≈ 0.52 (above 0.4) and the MAD ratio ≈ 0.45 (above 0.35), so both regularity tests fail. The pair would then only be found through the rarity of the domain, the volume (hundreds of lookups from one host) or activity at night.

3. Why is `time.lab.test` allow-listed rather than ignored by raising the CV threshold?

Its CV is 0, the most beacon-like value possible. Changing thresholds to skip it would also skip real beacons with zero jitter. An explicit allow-list entry for a known service, with an owner, keeps the detection sharp.

Test yourself

What does a low coefficient of variation of the gaps between lookups indicate?

  1. Human browsing
  2. Machine-like regularity, as in beaconing or scheduled software
  3. A DNS error
  4. High traffic volume

Uniform jitter of ±50 % on a 60-second beacon gives a CV of about…

  1. 0
  2. 0.29
  3. 1.0
  4. 5

Why can DNS caching hide a beacon's real interval?

  1. Caching encrypts DNS
  2. The host may not query again until the record's TTL expires, so the log shows the TTL's rhythm
  3. Caching deletes logs
  4. It doesn't

Which control makes sure every DNS lookup can be logged and filtered?

  1. Allowing direct outbound DNS to any resolver
  2. Forcing DNS through internal resolvers and blocking other outbound DNS and DoH
  3. Longer TTLs
  4. IPv6