From Network Security Wiki

Filtering Packets

Information related to Packet filtering is as follows:

Filtering a Cap File

dumpcap -i eth0 -f "host and udp port 53" -w /tmp/dns.cap -b duration:3600 -b files:25

Wireshark Common Filters

More Details: Reference

Description Filter
Sets a filter for any packet with, as either the source or dest ip.addr ==
Sets a conversation filter between the two defined IP addresses ip.addr== && ip.addr==
Sets a filter to display all http and dns http or dns
Sets a filter for any TCP packet with 4000 as a source or dest port tcp.port==4000
Displays all TCP resets tcp.flags.reset==1
Display all SYN packets tcp.flags.syn==1
Filter packets using Identification Field (across multiple traces) ip.id==518
Displays all HTTP GET requests http.request
Displays all TCP packets that contain the word ‘traffic’.
Excellent when searching on a specific string or user ID
tcp contains traffic
Masks out arp, icmp, dns, or whatever other protocols may be background noise.
Allowing you to focus on the traffic of interest
!(arp or icmp or dns)
Sets a filter for the HEX values of 0x33 0x27 0x58 at any offset udp contains 33:27:58
Displays all retransmissions in the trace.
Helps when tracking down slow application performance and packet loss
Fragmented Traffic ip.flags.mf == 1 or ip.frag_offset > 0
ICMP Fragmentation needed packets icmp.type==3 and icmp.code==4
Combination of above two ip[0,9,20:2]==4501:0304||ip[6:2]&3fff
Starting and Ending sessions tcp.flags&7 or (tcp.seq==1 and tcp.ack==1 and !tcp.window_size_scalefactor==-1 and tcp.len==0)

Wireshark Column Filters

Value to display Filter
TTL ip.ttl
Flags tcp.flags
SEQ tcp.seq
ACK tcp.ack
MSS tcp.options.mss_val
In-Flight tcp.analysis.bytes_in_flight
Payload tcp.len
Window tcp.window_size
Content-Length http.content_length_header

Advanced Packet Filtering

Use Case:

I am analyzing an SMB issue. I have 50 PCAP files, each of 100 MB, generated by the intermediate devices.
I am not sure which all files contain the interesting traffic. Searching each file manually using wireshark is hectic.
Client addresses are and Server address is Protocol is SMB2 (port 445).
We can use Tshark or TCPDump for this exercise. Tshakr is slow in Linux & TCPDump is very fast.

Wireshark Filter:

((ip.addr== or ip.addr== and ip.addr== and smb

List all Pcap files using any of the below commands:

find . -type f | egrep "All.pcap"
find . -type f | egrep ".pcap"
find . -type f | egrep "*.pcap"
find . -type f | grep ".pcap"
find . -type f | grep "pcap"

List interesting traffic from all the PCAP files:

 for i in `find . -type f | egrep "All.pcap"`; do echo $i; tshark -r $i '((ip.addr== or ip.addr== and ip.addr== and smb' ; echo -e "\n"; done 

Filter out errors:

 for i in `find . -type f | egrep "All.pcap"`; do echo $i; tshark -r $i '((ip.addr== or ip.addr== and ip.addr== and smb2' ; echo -e "\n"; done | grep -E '(error|unknown|denied)'

Filter out errors and save output to text file in background:

 for i in `find . -type f | egrep "All.pcap"`; do echo $i; tshark -r $i '((ip.addr== or ip.addr== and ip.addr== and smb2' ; echo -e "\n"; done | grep -E '(error|unknown|denied)' > errors.txt &

Show Timestamps in the output and save it to a text file:

 for i in `find . -type f | egrep "All.pcap"`; do echo $i; tshark -t ad -r $i '((ip.addr== or ip.addr== and ip.addr== and smb2' ; echo -e "\n"; done > smb-time.txt

 a       absolute time (local time in your time zone, actual time the packet was captured)
 ad      absolute with date
 u       Absolute UTC time
 ud      Absolute UTC time with date

Search for keywords in the text files created along with traces:

for i in `find . -type f | egrep ".txt"`; do echo $i; cat $i ; echo -e "\n"; done | grep smb2.lock

More Filters

Filter traffic in time range
  • Show traffic from 10:27 to 10:29
tshark -r trace1.cap -t ud | egrep -E '2017-07-25 10:2[7-9].'
  • Show traffic from 10:27 to 10:29
   Ambox notice.png     This filter is not tested successfully yet.
tshark -r trace1.cap -t ud '(frame.time >= "July 25, 2017 10:26:00.0") && (frame.time == "July 25, 2017 10:30:00.0")'
Decode SSL encrypted Traffic using Private Key
   Ambox notice.png     This filter is not tested successfully yet.
tshark -r trace1.cap -t ud -o ssl.keys_list:"","443","http","/home/aman/Downloads/Trace/trace.sslkeys"
Decode SSL encrypted Traffic using Pre Master Secret Key
   Ambox notice.png     This filter is not tested successfully yet.
tshark -r trace1.cap -t ud -o ssl.keys_list:/home/aman/Downloads/Trace/trace.sslkeys


  • In IE, disable HTTP1.1 in Advanced options to see the traffic being sent in HTTP1.0 version. Now you will be able to see traffic in Clear text in wireshark captures. HTTP1.1 uses gzip to compress html, so it is not read in clear text. You will find multiple connections for a single webpage.
  • In Wireshark, anyting you see in square brackets - [bla bla] is the wireshar analysis of the information & is not the part of the packet captured.

Non-Root Capture in Ubuntu

sudo apt-get install libcap2-bin
sudo groupadd wireshark
sudo usermod -a -G wireshark user
newgrp wireshark
sudo chgrp wireshark /usr/bin/dumpcap
sudo chmod 750 /usr/bin/dumpcap
sudo setcap cap_net_raw,cap_net_admin=eip /usr/bin/dumpcap


getcap /usr/bin/dumpcap     =>   /usr/bin/dumpcap = cap_net_admin,cap_net_raw+eip

If still unable to capture:

sudo dpkg-reconfigure wireshark-common
sudo chmod +x /usr/bin/dumpcap


  • Installation:
sudo apt-get install tshark
  • Filter Traffic from capture file:
tshark -r lotsapackets.cap -R dns -w trace.cap
tshark -r lotsapackets.cap -R "dns or tcp.port==80" -w trace.cap
  • Information about the capture file:
capinfos web.cap
  • Split capture file:
editcap -c 50000 lotsapackets.cap fewerpackets.cap
  • Extract data from any HTTP requests:
-T        Specify to extract Fields 
-e        Mention which fields to Extract
tshark -i wlan0 -Y http.request -T fields -e http.host -e http.user_agent
google.com	Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:36.0) Gecko/20100101 Firefox/36.0
  • Extracts both the DNS query and the response address:
tshark -i wlan0 -f "src port 53" -n -T fields -e dns.qry.name -e dns.a

Even more details:

tshark -i wlan0 -f "src port 53" -n -T fields -e frame.time -e ip.src -e ip.dst -e dns.qry.name -e dns.a
Apr 22, 2015 23:20:16.922103000 wprecon.com

  • Tshark can use stdout to manipulate/clean output:
tshark -i wlan0 -Y 'http.request.method == POST and tcp contains "password"' | grep password
  • Tshark 2.4 is required for some features, Install it in Ubuntu:
sudo add-apt-repository ppa:dreibh/ppa
sudo apt-get update && sudo apt-get install wireshark tshark
  • Extract files from an SMB stream:
tshark -nr test.pcap --export-objects smb,tmpfolder
  • Extract files from HTTP stream:
tshark -nr test.pcap --export-objects http,tmpfolder 

  • Detailed output:

Figure out the Frame number:

tshark -r ~/dhcp.pcap bootp.option.dhcp == 1

View Full details:

tshark -r ~/dhcp.pcap -V frame.number == 12


{{#widget:DISQUS |id=networkm |uniqid=Wireshark |url=https://aman.awiki.org/wiki/Wireshark }}