Configuring byte offset and payload matching filters

Byte offset and payload matching filters come to provide us with a flexible tool for configuring self-defined filters (filters for fields that are not defined in the Wireshark dissector and filters for proprietary protocols). By understanding the protocols that we work with and understanding their packet structure, we can configure filters that will watch a specific string in the captured packets, and filter packets according to it. In this recipe we will learn how to configure these types of filters, and we will also see some common and useful examples of the subject.

Getting ready

To configure byte offset and payload matching filters, start Wireshark and follow the instructions in the Configuring capture filters recipe in the beginning of this chapter.

How to do it...

  1. String matching filters comes to check a specific string in the packet header. It comes in the following format:
    proto [Offset: bytes]

    With this filter we can create filters for strings over IP, TCP, and UDP.

  2. For IP string-matching filters you can create the following filter:
    ip [Offset:Bytes]
    
  3. For matching application data, that is, to look into the application data that is carried by TCP or UDP, the most common uses of it are: tcp[Offset:Bytes] Or udp[Offset:Bytes].

How it works…

The general structure of offset filter is:

proto [Offset in bytes from the start of the header : Number of bytes to check]

Common examples for string matching filters are:

  1. For filtering destination TCP ports between 50 and 100, configure (tcp[2:2] > 50 and tcp[2:2] < 100).

    Here we count two bytes from the beginning of the TCP header, and check the next two bytes to be lower than 100 and higher than 50.

    How it works…
  2. For checking TCP window size smaller then 8192, configure tcp[14:2] < 8192.

    Here we count two bytes from the beginning of the TCP header, and check the next two bytes (the window size) to be less than 8192.

    How it works…

    There's a nice string-matching capture filter generator in http://www.wireshark.org/tools/string-cf.html

There's more...

You can also see additional filters in the tcpdump man pages:

  1. To print all IPv4 HTTP packets to and from port 80, (that is to print only packets that contain data, not, for example, SYN, FIN or ACK-only packets), configure the following filter: tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0).
  2. To print the start and end packets (the SYN and FIN packets) of each TCP conversation that involves a non-local host, configure tcp[tcpflags] & (tcp-syn|tcp-fin) != 0 and not src and dst net <localnet>.
  3. To print IP broadcast or multicast packets that were not sent via Ethernet broadcast or multicast, configure ether[0] & 1 = 0 and ip[16] >= 224.
  4. To print all ICMP packets that are not echo requests/replies (that is, not ping packets), configure icmp[icmptype] != icmp-echo and icmp[icmptype] != icmp-echoreply.

See also

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.46.58