3. Display Filters & Advanced Expressions
Display Filter Syntax and Operators
Display filters in Wireshark allow you to isolate specific traffic from a capture file. Unlike capture filters, these are applied to traffic already captured. The syntax relies on boolean and comparison operators to refine search results.
We utilize operators like and, or, and not for logic, while comparison operators such as eq (==), ne (!=), contains, and matches handle data evaluation. The following table provides a breakdown of common operators.
not to exclude specific noise, like 'not arp' to hide Address Resolution Protocol broadcast traffic.
| Operator | Function |
|---|---|
| == or eq | Equality check |
| != or ne | Not equal check |
| contains | Checks if a string or byte sequence exists |
| matches | Perl-compatible regex pattern match |
Filtering by Protocol and Metadata
Protocol-specific filtering enables deep-dive analysis of network stacks. By targeting specific fields, you can isolate conversations or errors. For example, 'ip.src == 192.168.1.5' identifies all packets originating from a specific host.
When performing automated analysis via TShark, you can pass these filters directly to the command line to generate summaries or extract packet counts.
tshark -r capture.pcap -Y 'http.request or dns.flags.response' -T fields -e ip.src -e http.host
Slice Operators for Raw Byte Inspection
Raw byte inspection allows you to query packet data at the hexadecimal level. Slice operators follow the format field[offset:length]. This is essential for identifying non-standard headers or obfuscated payloads.
The following Python script simulates checking a frame's Ethernet header bytes (the first 6 bytes representing the destination MAC) to demonstrate how byte-level data is extracted.
import struct def inspect_bytes(data): # Simulate raw packet slice: first 6 bytes mac_bytes = data[0:6] return mac_bytes.hex(':') packet_data = b'\x00\x11\x22\x33\x44\x55\x08\x00' print(f'Destination MAC extracted: {inspect_bytes(packet_data)}')
Saving, Exporting, and Merging PCAPs
After filtering, you often need to save your work. Exporting specified packets allows you to create a subset capture that contains only the relevant forensic evidence, reducing file size and complexity.
You can merge files using the mergecap utility, which is standard in the Wireshark suite, or filter while exporting using the GUI's 'Export Specified Packets' feature.
mergecap -w combined.pcap part1.pcap part2.pcap # Exporting via tshark to a new file: tshark -r original.pcap -Y 'ip.addr == 10.0.0.1' -w isolated_host.pcap
Knowledge Check
Ready to test your understanding of 3. Display Filters & Advanced Expressions?