Network Forensics
Network forensics recovers what happened from the packets themselves: connection records, protocol conversations, DNS queries and, where full capture exists, the exact bytes that crossed the wire. Its distinctive advantage is that network evidence is written by infrastructure rather than by the compromised host, so an attacker who clears logs and timestomps files still leaves traces in firewalls, proxies and packet stores. Its distinctive limitation is equally important â capture is incomplete by design, and understanding what your taps could never see is what keeps conclusions honest.
What network evidence can and cannot prove
A packet capture can prove that a connection was made, when it was made, its volume, and often its content. It cannot, on its own, prove who sat at the keyboard, and encrypted payloads mean content is frequently unavailable even when metadata is rich. That combination makes network forensics strongest for establishing scope, direction and timing: which internal hosts talked to which external destinations, how much data left the estate, and whether an indicator seen on an endpoint also appears in flow records.
| Evidence source | Retains | Typical retention | Best used for |
|---|---|---|---|
| Full packet capture | Headers and payload | Hours to days | Reconstructing sessions, extracting files |
| NetFlow or IPFIX | Connection metadata | Weeks to months | Volume analysis, beaconing detection |
| DNS logs | Queries and responses | Weeks to months | Domain generation and C2 discovery |
| Firewall and proxy logs | Decision plus URL | Months | Attribution of allowed connections |
| TLS certificate logs | Handshake metadata | Months | Identifying endpoints and renewals |
Because retention differs so sharply, the first question in any network investigation is what still exists. A two-week-old incident may have lost every packet but keep months of flow data, and the investigation plan should be rebuilt around what is left rather than mourn what expired.
Capture architecture: taps, spans and ring buffers
Forensic-grade capture starts with placement. A span port mirrors traffic to an appliance but silently drops packets when oversubscribed; a physical tap copies without that risk, which matters when the evidence must withstand challenge. Capture at the boundaries where trust changes â the internet edge, remote-access terminations, and the paths into cardholder or patient data zones â and size storage from a calculation rather than a guess.
#!/usr/bin/env bash
# Forensic capture plan for an internet-edge sensor.
set -euo pipefail
IFACE=eth1
DIR=/evidence/net/$(date -u +%Y%m%d)
mkdir -p "$DIR"
# 1) Continuous capture with a ring buffer: 10 files of 2 GB, overwriting oldest.
# Fixed size keeps the sensor from filling the disk during an incident.
timeout 3600 tcpdump -i "$IFACE" -s 0 -w "$DIR/edge-%03d.pcap" \
-C 2048 -W 10 -Z root
# 2) Hash the set the moment acquisition stops; record who ran it.
sha256sum "$DIR"/*.pcap | tee "$DIR/HASHES.txt"
stat -c '%n %y %s' "$DIR"/*.pcap | tee "$DIR/MANIFEST.txt"
# 3) Parallel metadata capture for correlation while packets age out.
nfdump -r /var/log/nfcapd/current -o csv > "$DIR/flows.csv"
kafka-console-consumer --bootstrap-server logs:9092 --topic dns \
--from-beginning --max-messages 500000 > "$DIR/dns.jsonl"
# 4) Compress and move to write-once storage before the next cycle.
tar -C "$DIR" -czf "$DIR.tgz" . && aws s3 cp "$DIR.tgz" s3://forensics-bucket/net/ \
--storage-class GLACIER
The manifest matters as much as the packets: file sizes, timestamps, capture host and operator turn a pile of PCAPs into an evidence set with a defensible chain of custody.
Reconstructing sessions from packets
Once capture exists, reconstruction groups packets into conversations, reassembles TCP streams in sequence order, and hands analysts readable sessions. The usual failure is ordering: packets arrive out of sequence, retransmissions duplicate payloads, and naive concatenation corrupts the stream. Tools such as tshark and NetworkMiner handle this for you; when you script it, retransmission and sequence handling must be explicit.
"""Group packets into TCP streams and flag the ones worth a human look."""
from collections import defaultdict
from scapy.all import IP, TCP, Raw, rdpcap
def build_streams(path):
streams = defaultdict(list)
for i, pkt in enumerate(rdpcap(path)):
if IP in pkt and TCP in pkt:
key = tuple(sorted([(pkt[IP].src, pkt[TCP].sport),
(pkt[IP].dst, pkt[TCP].dport)]))
streams[key].append((i, pkt[TCP].seq, bytes(pkt[TCP].payload or b"")))
return streams
def score_stream(packets):
"""Rank by bytes outbound and by whether application data exists at all."""
total = sum(len(data) for _, _, data in packets)
outbound = sum(len(data) for _, _, data in packets if data)
return {"packets": len(packets), "bytes": total, "payload_bytes": outbound}
def interesting(streams, byte_threshold=500_000):
for key, packets in streams.items():
stats = score_stream(packets)
if stats["payload_bytes"] > byte_threshold:
yield key, stats, bytes(b"".join(d for _, _, d in packets)[:2048])
if __name__ == "__main__":
for key, stats, preview in interesting(build_streams("edge-000.pcap")):
print(key, stats)
print(" preview:", preview[:120])
Reassembled streams are where you recover attacker tooling, credential submissions, web-shell commands and exfiltrated files â artifacts that no flow record could ever contain.
Corroborating with DNS, TLS and flow data
Metadata is not a consolation prize; in most investigations it carries more weight than payload, because it survives encryption. DNS answers tell you which infrastructure was resolved and when. JA3-style TLS fingerprints identify client software across connections even when content is sealed. Flow records quantify exfiltration: a host sending forty gigabytes outbound at 3 a.m. is visible without a single payload byte.
| Question | Primary source | Corroborating source |
|---|---|---|
| Did this host contact malicious infrastructure? | DNS query logs | Firewall deny/allow records |
| Was data exfiltrated? | NetFlow byte counts | Proxy upload records, packet sample |
| Which tool did the attacker run? | Reassembled stream payload | Endpoint process evidence |
| Was the channel encrypted end to end? | TLS handshake metadata | Certificate and ALPN fields |
| When did activity begin and end? | Packet timestamps | SIEM correlation of log sources |
The discipline is to require two independent sources for any timeline claim. One source is a clue; two is a finding you can defend.
Building the timeline
Timelines from capture are built from connection start times, DNS resolutions, and the protocol-level events inside streams â authentication exchanges, HTTP requests, and the intervals that reveal beaconing. Regularity is the tell: an endpoint phoning home every sixty seconds looks different from a user browsing, and interval analysis finds it even when the destination is legitimate infrastructure.
#!/usr/bin/env bash
# Convert a capture into an event timeline an analyst can read.
set -euo pipefail
PCAP=edge-000.pcap
# Connection-level timeline with resolved names where available.
tshark -r "$PCAP" -Y "dns.flags.response == 0" \
-T fields -e frame.time_epoch -e ip.src -e dns.qry.name > dns-queries.tsv
# HTTP requests inside the capture, with host, method and URI.
tshark -r "$PCAP" -Y "http.request" \
-T fields -e frame.time -e ip.src -e http.host -e http.request.method \
-e http.request.uri > http-requests.tsv
# Beacon hunting: sort outbound connection intervals and look for repeats.
tshark -r "$PCAP" -Y "tcp.flags.syn == 1 && tcp.flags.ack == 0" \
-T fields -e frame.time_epoch -e ip.dst | sort -k2,2 -k1,1n > syn-times.tsv
awk '{ delta[$2] = ($1 - last[$2]); last[$2] = $1; count[$2]++ }
END { for (h in count) if (count[h] > 5) print h, count[h] }' syn-times.tsv \
| sort -k2,2nr | head -20
Regular intervals across dozens of connections to one destination, from a workstation with no scheduled task behind it, are the kind of pattern that turns a suspicious flow into a confirmed beacon.
None of these conclusions should be drawn from a capture you have not characterized. Before analysis, record where the sensor sat, what its drop counters said during the window, which interfaces were mirrored, and whether any TLS interception was in place. Those four facts determine whether silence in the data means an event did not happen or means your sensor could never have seen it. Analysts who state the difference explicitly are trusted the second time; analysts who do not discover the difference during cross-examination.
Capture gaps and honest conclusions
Every capture setup has blind spots, and naming them before you write the report prevents the most common reversal an investigator faces under questioning. A span port that oversubscribes drops packets silently, so reassembled streams may show gaps that never existed on the wire. Capture on one segment sees only traffic crossing that segment: east-west movement inside a flat internal network may never touch a sensor placed solely at the internet edge. And encrypted transports mean payload is frequently absent even when capture was technically perfect.
đĄCapture what encryption will hide
Prioritize metadata pipelines â DNS, NetFlow, proxy and certificate logs â before packet capture. Payload is increasingly unavailable, and retention on flow data is far longer than on full capture, which often decides whether a three-week-old investigation is possible at all.
Retention, privacy and legal boundaries
Full packet capture is content, and content attracts regulation. Retention windows should be short enough to limit exposure of credentials and personal data, storage must be access-controlled and encrypted, and capture scope should follow the same justified boundaries as any other collection. Where works councils or privacy rules apply, capture locations and durations are negotiable items that must be documented before an incident forces the conversation.
Practical safeguards: restrict payload capture to segments where it is genuinely needed, rely on metadata elsewhere, log every access to the evidence store, and hash at acquisition so the integrity of the set can be re-verified after each transfer. Organizations that treat packet stores as routine telemetry tend to discover during an investigation that nobody can say who has been reading them.
Common Mistakes
Assuming full packet capture still exists weeks later
Fix: Check retention first and rebuild the plan around flows and DNS when packets have aged out.
Concatenating TCP payloads without sequence handling
Fix: Use a reassembly-aware tool or handle retransmissions and ordering explicitly in code.
Drawing conclusions from a single log source
Fix: Require two independent sources before placing anything on the timeline.
Capturing payload everywhere for completeness
Fix: Limit content capture to justified segments and rely on metadata across the rest.
Ignoring capture performance
Fix: Account for span oversubscription and verify packet counts so drops are visible.
Best Practices
- Size storage with a ring-buffer calculation and monitor drops on every sensor.
- Hash and manifest evidence at the moment acquisition stops.
- Keep metadata pipelines â DNS, flows, proxy â on longer retention than payload.
- Build timelines from corroborated events with consistent, documented timestamps.
- Document capture scope, retention and access in advance of any incident.
Key Takeaways
- Network evidence is written by infrastructure, so it survives host-side log wiping.
- Retention differences decide the investigation: check what exists before planning.
- Reassembled sessions recover files, commands and credentials that flow data cannot.
- Encrypted traffic shifts weight to DNS, TLS and flow metadata, which should be retained longest.
- Beacon detection comes from interval regularity, not from payload inspection.
- Two independent sources per timeline claim is the standard that survives challenge.