wireshark过滤器使用

来源:互联网 发布:linux 一键改时区 编辑:程序博客网 时间:2024/06/03 00:19

NAME  名称

wireshark-filter - Wireshark filter syntax and reference            过滤器语法和指南

SYNOPSIS   大纲

wireshark [other options][-R "filter expression" ]                    

tshark [other options][-R "filter expression" ]

DESCRIPTION   描述

Wireshark andTShark share a powerful filter engine that helps remove the noise from a packet trace and lets you see only the packets that interest you. If a packet meets the requirements expressed in your filter, then it is displayed in the list of packets. Display filters let you compare the fields within a protocol against a specific value, compare fields against fields, and check the existence of specified fields or protocols.

译文:wireshark和TShark展示了强大的过滤能力,有助于清除掉追踪分组过程中的干扰,使你只看见你感兴趣的分组。  如果一个分组满足了你的过滤器的要求,则其将显示在分组列表里面。显示过滤器使你可以通过一个指定值比较一个协议中某些域,比较域和域之间的区别,以及检测协议中指定域的存在与否。


Filters are also used by other features such as statistics generation and packet list colorization (the latter is only available toWireshark). This manual page describes their syntax. A comprehensive reference of filter fields can be found within Wireshark and in the display filter reference athttps://www.wireshark.org/docs/dfref/.

译文:过滤器也被其他功能使用到例如数据统计和分组表着色(后者的功能目前只在wireshark中存在)。本手册页面描述了它们的语法。  一个综合的过滤器域的指南可以在wireshark(help)和 显示过滤器指南https://www.wireshark.org/docs/dfref/.中找到 

FILTER SYNTAX   过滤器语法

Check whether a field or protocol exists           检测一个域或者协议是否存在

The simplest filter allows you to check for the existence of a protocol or field. If you want to see all packets which contain the IP protocol, the filter would be "ip" (without the quotation marks). To see all packets that contain a Token-Ring RIF field, use "tr.rif".

译文: 最简单的过滤器允许你去检测一个协议或一个域的存在。如果你想见到所有包含IP协议的分组,这个过滤器可以是“ip”(不用双引号标志)。想看所有包含Token-ring RIF字段的数据包,使用“tr.rif

Think of a protocol or field in a filter as implicitly having the "exists" operator.

译文:可以使用“exist”操作符来看一个协议或者字段是否存在

Comparison operators  比较操作符

Fields can also be compared against values. The comparison operators can be expressed either through English-like abbreviations or through C-like symbols:

    eq, ==    Equal    ne, !=    Not Equal    gt, >     Greater Than    lt, <     Less Than    ge, >=    Greater than or Equal to    le, <=    Less than or Equal to

Search and match operators  搜寻和匹配操作符

Additional operators exist expressed only in English, not C-like syntax:


    contains  Does the protocol, field or slice contain a value       matches   Does the protocol or text string match the given Perl regular expression


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:

“contains”操作符允许一个过滤器搜索一串字符,其形式为字符串,或者一串字节,其形式为字节数组。例如在搜索一个HTTP URL地址,可以使用下面的过滤器

    http contains "https://www.wireshark.org"

The "contains" operator cannot be used on atomic fields, such as numbers or IP addresses.

“contains”操作符不能被用于原子型的字段,比如数字和ip地址。


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:

“matches ”操作符允许一个过滤器使用与Perl兼容的正则表达式(PCRE)。“matches” 操作符只能应用于协议或者字符串类型的协议字段。例如:搜索一个给定的wAP WSP User-Agent,你可以这样写过滤器:

    wsp.user_agent matches "(?i)cldc"

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 inhttp://perldoc.perl.org/perlre.html).

这个实例显示了一个有趣的PCRE特性:串匹配选项必须指定(?option)才可以。例如,(?i)实现了该串匹配时大小写敏感。更多关于PCRE的信息可以在pcrepattern手册页(Perl正则表达式在http://perldoc.perl.org/perlre.html中有解释找到)

Functions   函数

The filter language has the following functions:

过滤器的语言还有下面几个函数

upper(string-field) - converts a string field to uppercase 转换一个字符串类型的协议字段变为大写
lower(string-field) - converts a string field to lowercase
转换一个字符串类型的协议字段变为小写


upper() and lower() are useful for performing case-insensitive string comparisons. For example:

upper((和lower((在处理大小写敏感的字符串比较时很有用。例如:

    upper(ncp.nds_stream_name) contains "MACRO"    lower(mount.dump.hostname) == "angel"

Protocol field types       协议字段类型

Each protocol field is typed. The types are:

    ASN.1 object identifier    Boolean    Character string    Compiled Perl-Compatible Regular Expression (GRegex) object    Date and time    Ethernet or other MAC address   以太网地址(6字节)    EUI64 address    Floating point (double-precision)    Floating point (single-precision)    Frame number    Globally Unique Identifier    IPv4 address    IPv6 address    IPX network number    Label    Protocol    Sequence of bytes    Signed integer, 1, 2, 3, 4, or 8 bytes    Time offset    Unsigned integer, 1, 2, 3, 4, or 8 bytes

An integer may be expressed in decimal, octal, or hexadecimal notation. The following three display filters are equivalent:

一个整数可以有三种表示方法,十进制、八进制和十六进制。下面三个例子是相同的:

    frame.pkt_len > 10    frame.pkt_len > 012    frame.pkt_len > 0xa

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, atoken-ring packet's source route field is Boolean. To find any source-routed packets, a display filter would be:

布尔值不是true就是false.在测试一个布尔类型字段的显示过滤器中,"true"的值相当于1或者其它的非0值,"false"就是0。
例如:令牌环数据包中一个源路由字段是布尔型的.找到源路由的数据包,可以这样写显示过滤器:

    tr.sr == 1

Non source-routed packets can be found with:

非源路由数据包可以使用这样的过滤器:

    tr.sr == 0

Ethernet addresses and byte arrays are represented by hex digits. The hex digits may be separated by colons, periods, or hyphens:

以太网地址和字节数组使用十六进制表示.十六进制的数字可以被 ":" "." "-" 分隔。例如:这里不要加双引号

    eth.dst eq ff:ff:ff:ff:ff:ff    aim.data == 0.1.0.d    fddi.src == aa-aa-aa-aa-aa-aa    echo.data == 7a

IPv4 addresses can be represented in either dotted decimal notation or by using the hostname:

IPv4 地址可以被表示成点分十进制或者使用主机名表示。例如:

    ip.dst eq www.mit.edu    ip.src == 192.168.1.1

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.

IPv4地址之间可以和数字之间一样,使用关系符号比较:eq,ne,gt,ge,lt和le。IPv4地址按照主机顺序存储,这样当你在使用显示 过滤器的时候就不用担心IPv4地址的结束了

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:

当使用IPv4子网划分的时候,CIDR表示法也可以使用。例如:以下的过滤器可以找到所有129.111 B类网络地址的数据包

    ip.addr == 129.111.0.0/16

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':

记住,/后面的数组表示网络号的位数。CIDR也可以使用主机名,如下面实例:

    ip.addr eq sneezy/24

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:

IPX网络使用无符号32位整数显示 。你也许更愿意使用十六进制,在你测试IPX网络值时

    ipx.src.net == 0xc0a82c00

Strings are enclosed in double quotes:

字符串使用双引号限制

    http.request.method == "POST"

Inside double quotes, you may use a backslash to embed a double quote or an arbitrary byte represented in either octal or hexadecimal.

字符串里面的引号使用\进行转义

    browser.comment == "An embedded \" double-quote"

Use of hexadecimal to look for "HEAD":

使用十六进制去寻找“HEAD”方法

    http.request.method == "\x48EAD"

Use of octal to look for "HEAD":

使用八进制(感觉这里有错误!

    http.request.method == "\110EAD"  (实际上正确的  'H' --》0x48  = 72 = 64 + 8 = 0110  这里的字符串第一个字符就是'\110' 

This means that you must escape backslashes with backslashes inside double quotes.

双引号里面的\使用'\\'进行转义

    smb.path contains "\\\\SERVER\\SHARE"

looks for \\SERVER\SHARE in "smb.path".

The slice operator  分片操作符  [:]

You can take a slice of a field if the field is a text string or a byte array. For example, you can filter on the vendor portion of an ethernet address (the first three bytes) like this:

你可以选取一个域的一部分如果这个域是一个文本字符串或者字节序列的话。例如,你可以在一个以太网地址的前三个字节上通过以太网网卡供应商进行过滤

    eth.src[0:3] == 00:00:83

Another example is:  另一个例子是:

    http.content_type[0:4] == "text"     http传输的内容类型

You can use the slice operator on a protocol name, too. The "frame" protocol can be useful, encompassing all the data captured by Wireshark orTShark.

你同样可以在一个协议名上使用分片操作符。“frame”协议是有用的,包含了被Wireshark或TShark捕获的所有数据。

    token[0:5] ne 0.0.0.1.1    llc[0] eq aa    frame[100-199] contains "wireshark"

The following syntax governs slices: 下面的语法使用了分片操作符:

    [i:j]    i = start_offset, j = length    [i-j]    i = start_offset, j = end_offset, inclusive.(包括j)    [i]      i = start_offset, length = 1    [:j]     start_offset = 0, length = j    [i:]     start_offset = i, end_offset = end_of_field

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:

偏移量可以是负数,这时候表明是从域的末尾计算的偏移量。域的最后一个字节偏移量-1,倒数第二个是-2,以此类推。下面就是如何检测一个frame的最后四个字节的:

    frame[-4:4] == 0.1.2.3

or

    frame[-4:] == 0.1.2.3

A slice is always compared against either a string or a byte sequence. As a special case, when the slice is only 1 byte wide, you can compare it against a hex integer that 0xff or less (which means it fits inside one byte). This is not allowed for byte sequences greater than one byte, because then one would need to specify the endianness of the multi-byte integer. Also, this is not allowed for decimal numbers, since they would be confused with hex numbers that are already allowed as byte strings. Neverthelss, single-byte hex integers can be convienent:

    frame[4] == 0xff

Slices can be combined. You can concatenate them using the comma operator:

分片也可以结合在一起。你可以使用逗号将几个分片集中到一起:

    ftp[1,3-5,9:] == 01:03:04:05:09:0a:0b

This concatenates offset 1, offsets 3-5, and offset 9 to the end of the ftp data.

The membership operator   成员操作符  {}  中间没有逗号 以空格进行元素之间的间隔

A field may be checked for matches against a set of values simply with the membership operator. For instance, you may find traffic on common HTTP/HTTPS ports with the following filter:

    tcp.port in {80 443 8080}

as opposed to the more verbose:

    tcp.port == 80 or tcp.port == 443 or tcp.port == 8080

Type conversions  类型转换

If a field is a text string or a byte array, it can be expressed in whichever way is most convenient.

So, for instance, the following filters are equivalent:

    http.request.method == "GET"    http.request.method == 47.45.54

A range can also be expressed in either way:

    frame[60:2] gt 50.51    frame[60:2] gt "PQ"

Bit field operations  位字段操作符 &

It is also possible to define tests with bit field operations. Currently the following bit field operation is supported:

    bitwise_and, &      Bitwise AND

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:

当测试TCP SYN同步分组时,可以使用下面的:

    tcp.flags & 0x02


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:

    wsp.pdu_type & 0x40

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:

    ip[42:2] & 40:ff

Logical expressions  逻辑表达式  &&  || !

Tests can be combined using logical expressions. These too are expressible in C-like syntax or with English-like abbreviations:

    and, &&   Logical AND    or,  ||   Logical OR    not, !    Logical NOT

Expressions can be grouped by parentheses as well. The following are all valid display filter expressions:

    tcp.port == 80 and ip.src == 192.168.2.1    not llc    http and frame[100-199] contains "wireshark"    (ipx.src.net == 0xbad && ipx.src.node == 0.0.0.0.0.1) || ip

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:

        ip.addr ne 192.168.4.1    not ip.addr eq 192.168.4.1

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. Ifneither 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:

    ip.dst ne 224.1.2.3

may be too restrictive. Filtering with "ip.dst" selects only thoseIP 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:

    not ip or ip.dst ne 224.1.2.3    not ip.addr eq 224.1.2.3

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.

FILTER FIELD REFERENCE  过滤器字段指南

The entire list of display filters is too large to list here. You can can find references and examples at the following locations:

  • The online Display Filter Reference:https://www.wireshark.org/docs/dfref/

  • Help:Supported Protocols in Wireshark

  • tshark -G fields on the command line

  • The Wireshark wiki: https://wiki.wireshark.org/DisplayFilters

NOTES  注意

The wireshark-filters manpage is part of theWireshark distribution. The latest version ofWireshark can be found athttps://www.wireshark.org.

Regular expressions in the "matches" operator are provided by GRegex in GLib. Seehttp://developer.gnome.org/glib/2.32/glib-regex-syntax.html/ or http://www.pcre.org/ for more information.

This manpage does not describe the capture filter syntax, which is different. See the manual page of pcap-filter(7) or, if that doesn't exist, tcpdump(8), or, if that doesn't exist,https://wiki.wireshark.org/CaptureFilters for a description of capture filters.


0 0
原创粉丝点击