Network Behaviour from a Packet Capture
A sample that talks to a server leaves the most useful evidence of all, because network traffic is visible outside the infected host: at the proxy, the DNS resolver, the firewall, a network sensor. In the lab, the sandbox's packet capture shows exactly what the sample said and how often. In production, the same patterns show up in logs across thousands of machines. This lesson reads a capture of the benign lab sample's traffic with tshark, and measures the property that gives most remote-control malware away: beaconing, check-ins at a regular interval.
Packet and protocol basics are in Networking for Security (tshark filters, HTTP in cleartext, DNS messages); Zeek logs and IDS rules are in Network Security.
Definitions
- Beacon: a periodic check-in from an implant to its server ("any commands for me?"). The period is often configurable, with jitter (a random variation of some percent) to look less regular.
- Beacon score: a measure of how regular the intervals between connections from one host to one destination are. A common one is the coefficient of variation (standard deviation divided by mean) of the intervals: near 0 for a timer, large for a human.
- Network indicators: the domain, the resolved addresses, the URL path and parameters, the user agent, TLS details (SNI, certificate, the JA3/JA4 client fingerprints), the payload sizes.
- Simulated Internet: in the lab every answer comes from INetSim or FakeNet, so the requests are real but the responses are not the attacker's.
Building and reading the capture
The session first writes a synthetic pcap with scapy (a stand-in for the sandbox's capture, with fixed timestamps from 2026-01-15 10:00:00 UTC): the analysis VM 10.10.0.20 resolves update.beacon.lab.test and polls it every 60 seconds with ±3 s jitter, while a user browses www.lab.test at irregular times. Then it analyses the file the way an analyst would: DNS first, then HTTP requests, then the intervals per destination.
python3 - <<'PY' 2>/dev/null
from scapy.all import Ether, IP, UDP, TCP, DNS, DNSQR, DNSRR, Raw, wrpcap
import random
T0, r, pkts = 1768471200.0, random.Random(60), [] # 2026-01-15 10:00:00 UTC, fixed seed
E = Ether(src="02:00:00:0a:0a:14", dst="02:00:00:0a:0a:01")
def add(p, t): p.time = T0 + t; pkts.append(p)
def dns(t, name, ip, qid):
add(E/IP(src="10.10.0.20", dst="10.10.0.53")/UDP(sport=53001, dport=53)/DNS(id=qid, rd=1, qd=DNSQR(qname=name)), t)
add(E/IP(src="10.10.0.53", dst="10.10.0.20")/UDP(sport=53, dport=53001)/DNS(id=qid, qr=1, rd=1, ra=1,
qd=DNSQR(qname=name), an=DNSRR(rrname=name, ttl=60, rdata=ip)), t + 0.002)
def http(t, host, ip, uri, ua, sport):
req = f"GET {uri} HTTP/1.1\r\nHost: {host}\r\nUser-Agent: {ua}\r\nAccept: */*\r\n\r\n".encode()
resp = b"HTTP/1.1 200 OK\r\nContent-Length: 2\r\nContent-Type: text/plain\r\n\r\nok"
C, S = E/IP(src="10.10.0.20", dst=ip), E/IP(src=ip, dst="10.10.0.20")
add(C/TCP(sport=sport, dport=80, flags="S", seq=1000), t)
add(S/TCP(sport=80, dport=sport, flags="SA", seq=5000, ack=1001), t + 0.001)
add(C/TCP(sport=sport, dport=80, flags="A", seq=1001, ack=5001), t + 0.002)
add(C/TCP(sport=sport, dport=80, flags="PA", seq=1001, ack=5001)/Raw(req), t + 0.003)
add(S/TCP(sport=80, dport=sport, flags="PA", seq=5001, ack=1001 + len(req))/Raw(resp), t + 0.010)
dns(0.0, "update.beacon.lab.test", "10.10.0.66", 0x2001)
dns(2.0, "www.lab.test", "10.10.0.10", 0x2002)
sport = 50000
for i in range(8): # the lab sample: every 60 s, jitter ±3 s
sport += 1; http(5 + 60 * i + r.uniform(-3, 3), "update.beacon.lab.test", "10.10.0.66",
"/api/v1/ping?id=lab-0001", "LabAgent/1.0", sport)
for t in sorted(r.uniform(4, 470) for _ in range(6)): # a person browsing
sport += 1; http(t, "www.lab.test", "10.10.0.10", r.choice(["/", "/news", "/docs/a.pdf"]),
"Mozilla/5.0 (Windows NT 10.0; Win64; x64)", sport)
pkts.sort(key=lambda p: p.time)
wrpcap("lab-run.pcap", pkts)
PY
capinfos -c -u lab-run.pcap 2>/dev/null | tail -2
echo "== DNS answers"
tshark -r lab-run.pcap -Y 'dns.flags.response == 1' -T fields -e dns.qry.name -e dns.a
echo "== HTTP requests: time, destination, host, URI, user agent"
tshark -r lab-run.pcap -Y http.request -T fields -e frame.time_relative -e ip.dst -e http.host \
-e http.request.uri -e http.user_agent | awk -F'\t' '{printf "%7.1f %s %-22s %-26s %s\n", $1, $2, $3, $4, $5}'
echo "== intervals per destination"
tshark -r lab-run.pcap -Y http.request -T fields -e frame.time_relative -e http.host | python3 -c '
import sys, statistics as st
from collections import defaultdict
times = defaultdict(list)
for line in sys.stdin:
t, host = line.split("\t"); times[host.strip()].append(float(t))
for host, ts in times.items():
gaps = [b - a for a, b in zip(ts, ts[1:])]
cv = st.pstdev(gaps) / st.mean(gaps)
verdict = "BEACON-LIKE" if len(gaps) >= 5 and cv < 0.2 else "irregular"
print(f"{host:<24} requests={len(ts)} mean gap={st.mean(gaps):6.1f}s cv={cv:.2f} {verdict}")
'Number of packets: 74
Capture duration: 426.764472 seconds
== DNS answers
update.beacon.lab.test 10.10.0.66
www.lab.test 10.10.0.10
== HTTP requests: time, destination, host, URI, user agent
3.8 10.10.0.66 update.beacon.lab.test /api/v1/ping?id=lab-0001 LabAgent/1.0
65.5 10.10.0.66 update.beacon.lab.test /api/v1/ping?id=lab-0001 LabAgent/1.0
90.4 10.10.0.10 www.lab.test / Mozilla/5.0 (Windows NT 10.0; Win64; x64)
115.6 10.10.0.10 www.lab.test /news Mozilla/5.0 (Windows NT 10.0; Win64; x64)
123.6 10.10.0.66 update.beacon.lab.test /api/v1/ping?id=lab-0001 LabAgent/1.0
185.7 10.10.0.10 www.lab.test /docs/a.pdf Mozilla/5.0 (Windows NT 10.0; Win64; x64)
186.9 10.10.0.66 update.beacon.lab.test /api/v1/ping?id=lab-0001 LabAgent/1.0
244.8 10.10.0.66 update.beacon.lab.test /api/v1/ping?id=lab-0001 LabAgent/1.0
304.0 10.10.0.66 update.beacon.lab.test /api/v1/ping?id=lab-0001 LabAgent/1.0
314.3 10.10.0.10 www.lab.test / Mozilla/5.0 (Windows NT 10.0; Win64; x64)
367.4 10.10.0.66 update.beacon.lab.test /api/v1/ping?id=lab-0001 LabAgent/1.0
373.6 10.10.0.10 www.lab.test / Mozilla/5.0 (Windows NT 10.0; Win64; x64)
404.6 10.10.0.10 www.lab.test /news Mozilla/5.0 (Windows NT 10.0; Win64; x64)
426.8 10.10.0.66 update.beacon.lab.test /api/v1/ping?id=lab-0001 LabAgent/1.0
== intervals per destination
update.beacon.lab.test requests=8 mean gap= 60.4s cv=0.04 BEACON-LIKE
www.lab.test requests=6 mean gap= 62.8s cv=0.59 irregular
The DNS answer gives the first network indicator; the HTTP list shows two very different clients from the same machine; the interval check separates them by numbers: the sample's gaps cluster tightly around 60 seconds despite the jitter, while the person's browsing is irregular. Look at the mean gaps: 60.4 s and 62.8 s, almost the same. The average rate says nothing; the regularity (cv 0.04 against 0.59) is the signal. The user agent LabAgent/1.0 and the URL path with a fixed id parameter are the indicators to search in proxy logs.
What else to read from a capture
| Question | Where to look |
|---|---|
| What names does it resolve, and do they look generated? | DNS queries; many failed (NXDOMAIN) lookups of random-looking names suggest a domain generation algorithm |
| Is the traffic encrypted? | TLS ClientHello: SNI, ALPN, the client fingerprint (JA3/JA4), and the certificate the server sends |
| How much data leaves? | bytes per direction per connection: a large upload after file reads suggests exfiltration |
| Is the protocol what the port says? | non-HTTP payloads on port 80 or 443, DNS with long TXT records or very long names (tunnelling) |
| Fallbacks | connections to IP addresses with no preceding DNS lookup, or a second domain tried after the first failed |
How beaconing is detected in production
- Proxy and DNS logs: for each (source, destination) pair, compute request count and interval regularity over hours; rank by score; review the top. RITA (Real Intelligence Threat Analytics) and Zeek-based tools implement this on Zeek logs.
- Rare destinations: a domain contacted by one or two hosts in the whole organisation, first seen recently.
- Indicator searches: the domain, URL path and user agent from the analysis, back over the log retention period.
- IDS signatures on payload patterns for the specific family (Suricata and Snort rules).
How it is prevented and contained
- Egress control: clients reach the Internet only through a proxy that logs and can block; direct outbound connections from workstations are dropped (egress filtering).
- DNS control: an internal resolver with response-policy zones (RPZ) to sink-hole known bad domains; block outbound DNS to anything else.
- Containment: when a beacon is confirmed, block the destination at proxy and DNS, isolate the host, and keep capturing: the beacon's attempts after the block show which other hosts are infected.
Pitfalls
- Legitimate beacons: update checks, telemetry, mail clients, chat apps and monitoring agents all poll regularly. Score, then allow-list known software, then review.
- Jitter and sleep: a 50 % jitter or a long sleep (one check-in a day) defeats short-window statistics; look over days.
- Shared infrastructure: a beacon to a big cloud provider or CDN can't be blocked by IP; block the domain or the URL path.
- Simulated responses: in the lab, don't read meaning into the server's answers; they came from INetSim.
Practice
1. Why does the coefficient of variation work better than the raw standard deviation for comparing destinations?
It is relative: a 3 s spread means a lot for a 10 s beacon and little for a 1 hour one. Dividing by the mean makes regularity comparable across periods.
2. Change the jitter in the session to ±25 s. What happens to the sample's cv, and how should a detector adapt?
Each gap is the difference of two jitters, with a standard deviation of s, so the cv rises to about 0.34 (from about 0.04 with ±3 s) and crosses the 0.2 threshold. Detectors look at longer windows, use more robust measures (for example the median absolute deviation, or a histogram of intervals), and combine regularity with rarity and fixed URL patterns.
3. A host makes a connection to 198.51.100.7:443 every 300 seconds, with no DNS lookup before any of them. What two things do you check?
Whether any process on the host legitimately uses a hard-coded IP (EDR network events give the process), and the TLS details (SNI, certificate, JA3/JA4) to see what it claims to be. A hard-coded IP with a regular interval and no DNS is a classic fallback or implant pattern.
Test yourself
What makes beaconing detectable even when the payload is encrypted?
- The encryption algorithm
- The regular timing and the fixed destination of the connections
- The TCP checksum
- The MAC address
Many NXDOMAIN answers for random-looking names from one host suggest what?
- A misconfigured printer
- A domain generation algorithm trying candidate domains
- A DNS server upgrade
- Normal web browsing
In the session, which property most clearly separated the sample from the person browsing?
- The IP version
- The low coefficient of variation of request intervals
- The HTTP status codes
- The TCP window size
Which control lets defenders both log and block workstation web traffic?
- A local hosts file
- Forcing all outbound web traffic through a logging proxy
- Disabling ICMP
- Using IPv6