| |||||
| |||||
Search Irongeek.com:
Help Irongeek.com pay for bandwidth and research equipment: |
Back To MAN Pages From BackTrack 5 R1 Master List
tshark [other options]
[ -R ``filter expression'' ]
Filters are also used by other features such as statistics generation and
packet list colorization (the latter is only available to Wireshark). This
manual page describes their syntax. A comprehensive reference of filter fields
can be found within Wireshark and in the display filter reference at
<http://www.wireshark.org/docs/dfref/>.
Think of a protocol or field in a filter as implicitly having the ``exists''
operator.
The ``contains'' operator allows a filter to search for a sequence of
characters, expressed as a string (quoted or unquoted), or bytes,
expressed as a byte array. For example, to search for a given HTTP
URL in a capture, the following filter can be used:
The ``contains'' operator cannot be used on atomic fields,
such as numbers or IP addresses.
The ``matches'' operator allows a filter to apply to a specified
Perl-compatible regular expression (PCRE). The ``matches'' operator is only
implemented for protocols and for protocol fields with a text string
representation. For example, to search for a given WAP WSP User-Agent,
you can write:
This example shows an interesting PCRE feature: pattern match options have to
be specified with the (?option) construct. For instance, (?i) performs
a case-insensitive pattern match. More information on PCRE can be found in the
pcrepattern(3) man page (Perl Regular Expressions are explained in
<http://www.perldoc.com/perl5.8.0/pod/perlre.html>).
Note: the ``matches'' operator is only available if Wireshark or TShark
have been compiled with the PCRE library. This can be checked by running:
or selecting the ``About Wireshark'' item from the ``Help'' menu in Wireshark.
upper() and lower() are useful for performing case-insensitive string
comparisons. For example:
An integer may be expressed in decimal, octal, or hexadecimal notation.
The following three display filters are equivalent:
Boolean values are either true or false. In a display filter expression
testing the value of a Boolean field, ``true'' is expressed as 1 or any
other non-zero value, and ``false'' is expressed as zero. For example, a
token-ring packet's source route field is Boolean. To find any
source-routed packets, a display filter would be:
Non source-routed packets can be found with:
Ethernet addresses and byte arrays are represented by hex
digits. The hex digits may be separated by colons, periods, or hyphens:
IPv4 addresses can be represented in either dotted decimal notation or
by using the hostname:
IPv4 addresses can be compared with the same logical relations as numbers:
eq, ne, gt, ge, lt, and le. The IPv4 address is stored in host order,
so you do not have to worry about the endianness of an IPv4 address
when using it in a display filter.
Classless InterDomain Routing (CIDR) notation can be used to test if an
IPv4 address is in a certain subnet. For example, this display filter
will find all packets in the 129.111 Class-B network:
Remember, the number after the slash represents the number of bits used
to represent the network. CIDR notation can also be used with
hostnames, as in this example of finding IP addresses on the same Class C
network as 'sneezy':
The CIDR notation can only be used on IP addresses or hostnames, not in
variable names. So, a display filter like ``ip.src/24 == ip.dst/24'' is
not valid (yet).
IPX networks are represented by unsigned 32-bit integers. Most likely
you will be using hexadecimal when testing IPX network values:
Strings are enclosed in double quotes:
Inside double quotes, you may use a backslash to embed a double quote
or an arbitrary byte represented in either octal or hexadecimal.
Use of hexadecimal to look for ``HEAD'':
Use of octal to look for ``HEAD'':
This means that you must escape backslashes with backslashes inside
double quotes.
looks for \\SERVER\SHARE in ``smb.path''.
Another example is:
You can use the slice operator on a protocol name, too.
The ``frame'' protocol can be useful, encompassing all the data captured
by Wireshark or TShark.
The following syntax governs slices:
Offsets can be negative, in which case they indicate the
offset from the end of the field. The last byte of the field is at offset
-1, the last but one byte is at offset -2, and so on.
Here's how to check the last four bytes of a frame:
or
You can concatenate slices using the comma operator:
This concatenates offset 1, offsets 3-5, and offset 9 to the end of the ftp
data.
So, for instance, the following filters are equivalent:
A range can also be expressed in either way:
The bitwise AND operation allows testing to see if one or more bits are set.
Bitwise AND operates on integer protocol fields and slices.
When testing for TCP SYN packets, you can write:
That expression will match all packets that contain a ``tcp.flags'' field
with the 0x02 bit, i.e. the SYN bit, set.
Similarly, filtering for all WSP GET and extended GET methods is achieved with:
When using slices, the bit mask must be specified as a byte string, and it must
have the same number of bytes as the slice itself, as in:
Expressions can be grouped by parentheses as well. The following are
all valid display filter expressions:
Remember that whenever a protocol or field name occurs in an expression, the
``exists'' operator is implicitly called. The ``exists'' operator has the highest
priority. This means that the first filter expression must be read as ``show me
the packets for which tcp.port exists and equals 80, and ip.src exists and
equals 192.168.2.1''. The second filter expression means ``show me the packets
where not (llc exists)'', or in other words ``where llc does not exist'' and hence
will match all packets that do not contain the llc protocol.
The third filter expression includes the constraint that offset 199 in the
frame exists, in other words the length of the frame is at least 200.
A special caveat must be given regarding fields that occur more than
once per packet. ``ip.addr'' occurs twice per IP packet, once for the
source address, and once for the destination address. Likewise,
``tr.rif.ring'' fields can occur more than once per packet. The following
two expressions are not equivalent:
The first filter says ``show me packets where an ip.addr exists that
does not equal 192.168.4.1''. That is, as long as one ip.addr in the
packet does not equal 192.168.4.1, the packet passes the display
filter. The other ip.addr could equal 192.168.4.1 and the packet would
still be displayed.
The second filter says ``don't show me any packets that have an
ip.addr field equal to 192.168.4.1''. If one ip.addr is 192.168.4.1,
the packet does not pass. If neither ip.addr field is 192.168.4.1,
then the packet is displayed.
It is easy to think of the 'ne' and 'eq' operators as having an implicit
``exists'' modifier when dealing with multiply-recurring fields. ``ip.addr
ne 192.168.4.1'' can be thought of as ``there exists an ip.addr that does
not equal 192.168.4.1''. ``not ip.addr eq 192.168.4.1'' can be thought of as
``there does not exist an ip.addr equal to 192.168.4.1''.
Be careful with multiply-recurring fields; they can be confusing.
Care must also be taken when using the display filter to remove noise
from the packet trace. If, for example, you want to filter out all IP
multicast packets to address 224.1.2.3, then using:
may be too restrictive. Filtering with ``ip.dst'' selects only those
IP packets that satisfy the rule. Any other packets, including all
non-IP packets, will not be displayed. To display the non-IP
packets as well, you can use one of the following two expressions:
The first filter uses ``not ip'' to include all non-IP packets and then
lets ``ip.dst ne 224.1.2.3'' filter out the unwanted IP packets. The
second filter has already been explained above where filtering with
multiply occurring fields was discussed.
Regular expressions in the ``matches'' operator are provided with libpcre,
the Perl-Compatible Regular Expressions library: see http://www.pcre.org/.
This manpage does not describe the capture filter syntax, which is
different. See the manual page of pcap-filter(4) or, if that doesn't exist,
tcpdump(8), or, if that doesn't exist, <http://wiki.wireshark.org/CaptureFilters>
for a description of capture filters.
15 most recent posts on Irongeek.com:
|
If you would like to republish one of the articles from this site on your
webpage or print journal please contact IronGeek.
Copyright 2020, IronGeek
Louisville / Kentuckiana Information Security Enthusiast