Wireshark Packet Analysis with Display Filters and tshark
I captured live traffic and analyzed it with Wireshark display filters and headless tshark, isolating protocol anomalies and reconstructing full TCP sessions. Precise filtering turned a noisy multi-gigabyte capture into the handful of packets that mattered.
Objective & Context
Packet analysis is the ground truth of networking and security. This lab builds fluency in capture filters (BPF) versus display filters and in following streams, the same skills used in the IoT recon and SOC labs.
Learning Objectives
- Capture traffic with tshark using BPF capture filters.
- Distinguish capture filters (BPF) from display filters.
- Extract specific fields (SNI, Host) across many packets.
- Reconstruct a full TCP session with the follow-stream feature.
- Reduce a large capture to the relevant flow efficiently.
Environment & Prerequisites
Prerequisites
- Wireshark 4.2 and tshark; capture privileges on the NIC.
- A sample pcap or live traffic to analyze.
- Knowledge of the target protocols (HTTP, DNS, TLS).
- Wireshark 4.2 and tshark installed (sudo apt install -y wireshark tshark).
- Capture privileges on the NIC (membership in the wireshark group or root).
- A sample pcap or live traffic to analyze.
- Knowledge of the target protocols (HTTP, DNS, TLS).
BPF filter] --> P[(pcap)] P --> D[Display filter] D --> F[Follow TCP stream] F --> R[Findings]
Step-by-Step Execution
1. Capture with a BPF filter
sudo tshark -i eth0 -f "host 192.168.20.30 and tcp port 443" -a packets:500 -w tls.pcap ; ls -lh tls.pcapExpected output:
Capturing on 'eth0'
500
500 packets captured
-rw-r--r-- 1 analyst analyst 4.2M Sep 29 12:10 tls.pcap
What this teaches: capture filters decide what gets recorded, so a precise BPF expression keeps pcaps small and relevant.
tshark captures until stopped: -a packets:500 (or -a duration:60) stops it automatically so a forgotten capture cannot fill the disk. The last line is the output of the separate ls -lh command. Capturing needs sudo or membership in the wireshark group on a fresh install.
2. Apply a display filter and extract fields
tshark -r tls.pcap -Y "tls.handshake.type == 1" -T fields -e tls.handshake.extensions_server_nameExpected output:
tyfsadik.org
cloud.tyfsadik.org
What this teaches: display filters operate on decoded fields after capture, which is where protocol knowledge pays off.
3. Reconstruct an HTTP session
tshark -r web.pcap -q -z follow,tcp,ascii,0Expected output:
===================================================================
Follow: tcp,ascii
Filter: tcp.stream eq 0
Node 0: 192.168.20.5:45678
Node 1: 203.0.113.10:80
GET /index.html HTTP/1.1
Host: example.com
HTTP/1.1 200 OK
Content-Length: 612
... (reassembled application payload of stream 0) ...
===================================================================
What this teaches: stream reassembly turns thousands of packets back into the conversation the application actually had.
web.pcap is a sample capture you supply (for example one captured with step 1's command against port 80). The follow output is the reconstructed byte stream, not empty output: change the trailing number to follow a different stream index.
How It Works
Packet analysis has two filter stages with different jobs. Capture filters use BPF syntax and run in the kernel: they decide which packets get recorded at all. Display filters use Wireshark's field syntax and run after capture: they decide which recorded packets you look at. A good workflow captures broadly enough to be useful and displays narrowly enough to be readable.
tshark decodes protocols into named fields, and -T fields with -e extracts just those values across every packet: one line per packet, ready for scripting. This is how analysts pull every SNI from a thousand handshakes or every DNS query from an hour of traffic without clicking through the GUI.
Follow TCP stream reassembles the byte streams in both directions, showing the application-layer conversation as the endpoints saw it. For HTTP this reveals requests and responses; for suspicious sessions it reveals exactly what was transferred, which is why stream following is central to both troubleshooting and forensics.
Validation & Testing
Filter to a single conversation and confirm the reconstructed stream matches the expected request/response. Pass criteria: clean filter isolation, correct SNI/Host extraction, and a coherent followed stream with no missing segments.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| tshark reports no interfaces | Insufficient privileges to capture | Add the user to the wireshark group or run with sudo, then re-login |
| Capture file is empty | BPF filter too restrictive or the wrong interface | Capture unfiltered briefly to confirm traffic exists, then tighten the filter |
| Display filter shows no packets | Field name wrong or the protocol is not decoded as expected | Check the packet details pane for the exact field name Wireshark uses |
| Follow stream shows garbled output | The session is encrypted (TLS) or uses compression | For TLS, provide keylog secrets; for HTTP, check Content-Encoding |
| Huge pcap is slow to open | Full decode of millions of packets | Use capture filters next time; for now, use tshark -Y to extract only what you need |
Advanced: Troubleshooting
- Capture vs display confusion: BPF filters at capture (libpcap syntax); Wireshark filters at display (different syntax).
- Missing packets: capture on the correct interface and disable offload that hides segmentation.
- Encrypted payload: TLS bodies need keys; analyze metadata (SNI, sizes, timing) instead.
Key Results
- Reduced a multi-gigabyte capture to the relevant flow with one display filter.
- Extracted SNI and Host fields across 100% of inspected handshakes.
- Reconstructed full TCP sessions for application-layer review.
- Built reusable tshark one-liners for headless analysis.
Key Takeaways
- Capture with BPF to limit volume; display-filter to focus analysis.
- Field extraction (-T fields -e) scales analysis beyond what the GUI can do.
- Follow streams to see the application conversation, not just packets.
- Always note the capture filter: it defines what the pcap does not contain.
Practice Challenges
Challenge 1: Find the exfiltration
Goal: In a sample pcap, identify which internal host sent the most bytes to an external IP using only tshark field extraction.
Hint: Extract ip.src and frame.len, then aggregate with awk and sort.
Challenge 2: Extract files from HTTP
Goal: Carve every downloaded file out of an HTTP pcap into separate files.
Hint: Use tshark --export-objects http,<dir> to dump the transferred objects.