Filter Packets in Wireshark
Learn to filter and inspect packets in Wireshark with hands-on steps, troubleshooting tips, and what to study next in the Ethical Hacking track.
Focus: filter and inspect packets in wireshark
Picture this: you've launched Wireshark, watched packets fly by on your network, and now you're staring at thousands of lines of hexadecimal and protocol details. It's overwhelming. The real power of Wireshark isn't in capturing packets — it's in knowing how to filter and inspect packets in Wireshark to find the specific traffic you need, whether that's a suspicious HTTP request, a failed DNS lookup, or a potential data exfiltration. Without filtering skills, you're swimming in noise. This lesson hands you the tools to cut through that noise and zero in on the packets that matter.
The problem this lesson solves
Network capture files are messy. In a typical session, you might capture tens of thousands of packets — ARP broadcasts, background noise, encrypted TLS handshakes, and that one critical HTTP request you need for your investigation. Trying to inspect each packet manually is like looking for a needle in a haystack.
The problem: Wireshark's capture includes everything, but your analysis only needs a tiny fraction. You need a systematic way to filter and inspect packets in Wireshark so you can:
- Isolate traffic to a specific host, protocol, or port.
- Find anomalies like malformed packets or unusual patterns.
- Extract the key details (e.g., HTTP requests, credentials, file transfers) for your assessment.
Without filter mastery, your productivity tanks and you risk missing the very evidence you're hunting for.
Core concept / mental model
Think of Wireshark as a packet traffic camera. The capture is the raw footage — every car that passes. A display filter is like a pair of smart glasses that only shows you red sedans; the footage is still recorded, but you only see what you asked for. A capture filter, on the other hand, is like setting the camera to only record red sedans — it decides what gets recorded in the first place.
In Wireshark, you have two types of filters:
- Capture filters: Applied before/during capture, using the older BPF (Berkeley Packet Filter) syntax. They limit what's written to disk.
- Display filters: Applied after capture, using Wireshark's own filter language. They hide (not delete) packets that don't match.
Pro tip: For most analysis work, you'll use display filters. They're more flexible and don't risk losing data that might become relevant later.
Key terms:
- Protocol: e.g., tcp, udp, http, dns, arp.
- Field: e.g., ip.src, tcp.port, http.request.method.
- Operator: e.g., ==, !=, &&, ||, contains.
How it works step by step
Step 1: Capture packets
Start with a clean capture. Use the capture filter if you know exactly what you need, e.g., tcp port 80 to only record HTTP traffic. Otherwise, capture everything and filter later.
Step 2: Understand the filter syntax
Display filters use this structure: protocol.field operator value.
tcp.port == 443— show only packets to/from port 443.ip.addr == 192.168.1.10— show traffic to/from that IP (note:ip.addrmatches both source and destination).http.request.method == "GET"— show only HTTP GET requests.- Combine with
&&(and),||(or),!(not).
Step 3: Inspect the packet details
When you click a packet, the Packet Details pane shows a hierarchical tree — Ethernet, IP, TCP, and application data. Expand the relevant headers to see things like source/dest IPs, TTL, flags, sequence numbers, and payload.
Step 4: Follow streams
Right-click a packet → Follow → TCP Stream to see the entire conversation as readable text — perfect for inspecting HTTP requests and responses or extracting files.
Hands-on walkthrough
Let's practice with a real scenario. We'll capture some HTTP traffic and filter it down.
1. Capture traffic
# Capture HTTP traffic on interface eth0
sudo tcpdump -i eth0 -w http.pcap 'tcp port 80'
# Stop after ~30 seconds with Ctrl+C, then open in Wireshark
tshark -r http.pcap -Y "http" -T fields -e ip.src -e http.request.uri | head -20
2. Apply display filters
Open the pcap in Wireshark (or use tshark). Let's filter:
# Show only HTTP requests
tshark -r http.pcap -Y "http.request"
# Show traffic to a specific server
tshark -r http.pcap -Y "ip.addr == 93.184.216.34"
# Show POST requests
tshark -r http.pcap -Y "http.request.method == POST"
3. Inspect a single packet in Wireshark
Open the pcap in the GUI, click on a packet, and in the Packet Details pane, expand the Hypertext Transfer Protocol section. You'll see the request method, URI, and headers. For example:
Hypertext Transfer Protocol
GET /index.html HTTP/1.1\r\n
Host: example.com\r\n
User-Agent: Mozilla/5.0\r\n
[Full request URI: http://example.com/index.html]
4. Follow the conversation
Right-click the packet → Follow → TCP Stream to see the raw HTTP exchange:
GET /login HTTP/1.1
Host: server.local
User-Agent: curl/7.68
Accept: */*
HTTP/1.1 200 OK
Date: Mon, 06 Mar 2023 12:00:00 GMT
Content-Type: text/html
Content-Length: 1234
<html>...
Pro tip: Use
tsharkfor scripted filtering — it outputs the same results and is perfect for automating packet analysis in your security scripts.
Compare options / when to choose what
| Filter type | Syntax | Use case | Example |
|---|---|---|---|
| Capture filter | BPF | Limit capture to reduce file size | tcp port 80 |
| Display filter | Wireshark expression | Analyze a large capture | http.request.method == "GET" |
| tshark filter | Display filter | Command-line / automation | -Y "tcp.port == 443" |
When to use what: Use capture filters when you know exactly what you need and want to avoid bloated files. Use display filters when you have a broad capture and want to explore. For scripting, use tshark with display filters.
Troubleshooting & edge cases
Issue: My filter returns nothing.
- Check if the filter syntax is correct (look for color coding in the filter box — red means invalid).
- Verify the packet contains that field; e.g., http.request only works on HTTP packets, not all TCP.
- Remember ip.addr includes both source and destination — if you need a specific direction, use ip.src or ip.dst.
Issue: Capture filter dropped packets I needed. - Capture filters are applied during capture and cannot be undone. If you're unsure, capture everything and filter later.
Issue: Filter is too slow on large files.
- Wireshark handles millions of packets, but complex filters on giant files can lag. Try narrowing your time range first (e.g., frame.time >= "2023-01-01").
What you learned & what's next
You've learned to filter and inspect packets in Wireshark — how to use capture and display filters, combine expressions, inspect packet details, and follow streams. This skill is essential for network analysis in ethical hacking, whether you're investigating suspicious traffic, doing reconnaissance, or verifying your own exploits during a security audit.
Next lesson will build on this by teaching you to extract artifacts from network captures — files, credentials, and images — a natural next step in your ethical hacking journey.
Practice recap
Capture a few minutes of your own web browsing traffic (with permission), then practice filtering for http, dns, and tcp.port == 443. Follow a TCP stream to view an HTTP exchange, and use tshark to list all destination IPs. This hands-on exercise will solidify your ability to filter and inspect packets in Wireshark.
Common mistakes
- Using
ip.srcwhen you want any traffic involving an IP — useip.addrfor both directions. - Forgetting that display filters are case-sensitive:
httpworks, butHTTPdoesn't. - Setting a capture filter too narrow (e.g.,
port 80) and losing HTTPS traffic that would have been useful later. - Typing invalid filter expressions that Wireshark marks red — always check the box background for errors.
Variations
- Use
tsharkcommand-line tool for automated filtering and packet inspection in scripts. - Combine Wireshark filters with
grep/awkon exported CSV or JSON for complex post-processing. - Save custom filters in Wireshark (via the filter expression dialog) to reuse frequently used queries.
Real-world use cases
- Analyzing a suspicious HTTP POST to a rogue server during an incident response investigation.
- Filtering DNS queries to detect potential DNS tunneling or data exfiltration attempts.
- Isolating traffic from a specific IP in a packet capture to verify a command-and-control communication.
Key takeaways
- Display filters are your primary tool for analyzing existing captures; use capture filters only when you know exactly what you need.
- The syntax
protocol.field operator valueis the foundation of every display filter — master it. - Combine filters with operators like
&&and||to refine your search efficiently. - The Packet Details pane reveals layer-by-layer information — expand each header to inspect important fields.
- Use Follow TCP Stream to read entire conversations in plain text, which is crucial for extracting HTTP data.
- Always verify your filter syntax — Wireshark colors the filter box green for valid and red for invalid.
Keep learning
Related tutorials, quizzes, and articles for this topic.
Discussion
Questions, corrections, and tips help everyone reading this page.
0 comments
Add a comment
No comments yet — start the thread.