1. Wireshark 1.1 Wireshark使用的环境 1.2 特征 2. 安装 2.1 安装组件(手册章节2.3.1) 2.2 安装 Npcap(手册章节2.3.4) 3. 主窗口(手册章节3.3) 3.1 数据显示区布局 3.2 数据包列表-时间显示格式 3.3 主窗口导航(手册章节3.3.1) 3.4 数据包列表-设置显示列 3.5 数据包列表-显示列设置参考 4. 导出数据包 5. Filters 5.1 过滤器语法及參考 5.2 (捕获/显示)过滤器示例
1. Wireshark
Wireshark(旧称 Ethereal)是一个开源的网络数据包分析器,可实时从网络接口捕获数据包中的数据。
它尽可能详细地显示捕获的数据以供用户检查它们的内容,并支持多协议的网络数据包解析。
Wireshark 适用于 Windows 和 UNIX 操作系统。
它可被用于检查安全问题和解决网络问题,也可供开发者调试协议的实现和学习网络协议的原理。
在 Linux、BSD 和 macOS 上,使用libpcap 1.0.0 或更高版本,Wireshark 1.4 及更高版本还可以将无线网络接口控制器置于监控模式。
在 GNU 通用公共许可证的保障下,用户可免费获得软件与源代码,并拥有对源代码修改及定制的权利。
Wireshark 允许用户将网络接口控制器置于混杂模式(如果网络接口控制器支持),这样他们就可以查看该接口上可见的所有流量,包括未发送到该网络接口控制器MAC 地址的单播流量。
但是,当使用混杂模式下的数据包分析器在网络交换机的端口上捕获数据包时,并非所有流经交换机的流量都会发送到捕获数据包的端口,因此,在混杂模式下捕获数据包并不一定能够查看所有网络流量。
端口镜像或各种网络分路器可以将捕获范围扩展到网络上的任何点。简单的被动分路器具有极强的抗篡改能力。
1.1 Wireshark使用的环境
- 单机情况下,Wireshark直接抓取本机网卡的网络流量;
- 交换机情况下,Wireshark通过端口镜像、ARP欺骗等方式获取局域网中的网络流量。
- 端口镜像:利用交换机的接口,将局域网的网络流量转发到指定电脑的网卡上。
- ARP欺骗:交换机根据MAC地址转发数据,伪装其他终端的MAC地址,从而获取局域网的网络流量。
1.2 特征
Wireshark 是一个数据捕获程序,它能够“理解”不同网络协议的结构(封装)。
它可以解析并显示不同网络协议指定的字段及其含义。
Wireshark 使用pcap来捕获数据包,因此它只能捕获 pcap 支持的网络类型的数据包。
- 可以从实时网络连接中“在线”捕获数据,也可以从已捕获的数据包文件中读取数据。
- 可以从不同类型的网络中读取实时数据,包括以太网、IEEE 802.11、PPP和环回。
- 可以通过GUI或实用程序 TShark 的终端(命令行)版本浏览捕获的网络数据。
- 捕获的文件可以通过命令行开关以编程方式编辑或转换为“editcap”程序。
- 可以使用显示过滤器来优化数据显示。
- 可以创建插件来解析新的协议。
- 捕获的流量中可以检测到VoIP呼叫。如果使用兼容的编码,甚至可以播放媒体流。
- 可以捕获原始USB流量。
- 只要无线连接穿过受监控的以太网,它们也可以被过滤。
- 可以设置各种设置、计时器和过滤器来提供过滤捕获流量输出的功能。
- Wireshark 还可以用于捕获大多数网络仿真工具(如ns和OPNET Modeler)的数据包。
Wireshark 的原生网络追踪文件格式是 libpcap 格式,可由libpcap、WinPcap 和 Npcap读写,因此它可以与使用相同格式的其他应用程序(包括tcpdump和CA NetMaster)交换捕获的网络追踪信息,也可以与较新版本的 libpcap 读取 pcapng 格式的网络追踪信息。
它还可以读取其他网络分析工具的捕获信息,例如snoop 、Network General的Sniffer和Microsoft Network Monitor。
2. 安装
安装Wireshark软件, 通过主页下载安装即可, 下面主要介绍安装组件.
2.1 安装组件(手册章节2.3.1)
在安装程序的选择组件页面上,您可以从以下内容中进行选择:
- Wireshark, 网络协议分析器
- Tshark, 一款命令行网络协议分析器。
- External Capture (extcap), 外部捕获接口
- Androiddump, 提供来自 Android 设备的捕获接口。
- Etwdump, 提供一个接口来读取 Windows 事件跟踪 (ETW) 事件跟踪 (ETL)。
- Randpktdump, 提供随机数据包生成器的接口。(另请参阅 randpkt)
- Sshdump、Ciscodump 和 Wifidump, 通过 SSH 提供远程捕获。(tcpdump、Cisco EPC、wifi)
- UDPdump, 提供捕获接口来接收从网络设备流式传输的 UDP 数据包。
2.2 安装 Npcap(手册章节2.3.4)
Wireshark 安装程序包含最新的 Npcap 安装程序。
如果您未安装 Npcap,您将无法捕获实时网络流量,但仍然可以打开已保存的捕获文件。
默认情况下,系统会安装最新版本的 Npcap。
如果您不想安装最新版本,或者希望重新安装 Npcap,您可以根据需要勾选“安装 Npcap”复选框。
有关 Npcap 的更多信息,请参阅
3. 主窗口(手册章节3.3)
Wireshark 的主窗口由许多其他 GUI 程序中常见的部分组成。
- 上方, 菜单操作区
- 菜单栏: 用于启动操作。
- 工具栏: 常用功能的快捷方式
- 过滤栏: 指定过滤条件,过滤数据包
- 中间, 数据显示区
- 数据包列表: 核心区域,每一行就是一个数据包
- 数据包详情: [列表]中选择数据包的详细数据
- 数据包字节: 选择数据包对应的字节流,二进制
- 数据包图窗格: 将数据包列表中选择的数据包显示为教科书风格的图表。(默认不显示)
- 下方, 状态栏
- 状态栏: 显示有关当前程序状态和捕获数据的一些详细信息。
3.1 数据显示区布局
对于中间, 数据显示区又分为主数据列表, 和3种详细数据显示(下面3中显示方式, 3选2展示)
菜单栏: 编辑\首选项(P)... \外观\布局 (Ctrl+Shift+P)
- 通常[主数据列表], 即[分组列表]是必选的;
- 然后是可读的[数据包详情], 即[分组详情], 也是必选的吧;
- 最后就是不可直接阅读的[数据包字节]和[数据包图窗格]2选一展示. 默认显示的是字节流
3.2 数据包列表-时间显示格式
菜单栏: 视图\时间显示格式(T)
也可以通过快捷键快速切换(Ctrl + Alt + [1~8]), 不同快捷键的效果可以在上面菜单里看到.
比如(Ctrl + Alt + 2), 省略日期, 只显示可读的时间.
3.3 主窗口导航(手册章节3.3.1)
数据包列表和详细信息的导航完全可以通过键盘完成。
表 3.1 “键盘导航”列出了一些快捷键,可帮助您在捕获文件中快速移动。
- Analyze 分析. 此菜单包含用于操作显示过滤器、启用或禁用协议解析、配置用户指定解码以及跟踪 TCP 流的选项。
- Statistics 统计数据. 此菜单包含显示各种统计信息窗口的菜单项,包括已捕获数据包的摘要、显示协议层次结构的统计信息等等。
- Telephony 电话. 此菜单包含显示各种电话相关统计信息窗口的菜单项,包括媒体分析、流程图、显示协议层次结构统计信息等等。
- Wireless 无线的. 此菜单包含显示蓝牙和 IEEE 802.11 无线统计信息的项目。
- Tools 工具. 此菜单包含 Wireshark 中的各种可用工具,例如创建防火墙 ACL 规则。
3.4 数据包列表-设置显示列
[数据包列表] 是最常用的模块之一,列表中有一些默认显示的列,我们可以添加、删除、修改显示的列。
添加显示列, 有2种方式.
- [数据包详情] 中, 左键选中想要添加为列的字段,右键选择 [应用为列]。可快捷的将该类型字段添加到[数据包列表]中.
- 右键列标题, 选择[列首选项], 这里可以手动添加更多, 更加细致的字段. 后面会附上添加列的示例列表.
3.5 数据包列表-显示列设置参考
整理摘录自以下博文:
| Type | Title | 类型 | Fields | Field Occurence |
Resolved | 备注 |
| MAC | Source MAC | Hw src addr (unresolved) | ||||
| MAC | Destination MAC | Hw dest addr (unresolved) | ||||
| Port | Source Port | Src port (unresolved) | 确定特定应用程序(如 HTTP、DNS、FTP)使用的端口。 | |||
| Port | Destination Port | Dest port (unresolved) | ||||
| TCP | TCP.SYN | Custom | tcp.flags.syn | 0 | 1 | TCP Flags: 显示 TCP 数据包的控制标志(SYN, ACK, FIN). 这些标志对于分析 TCP 握手, 连接的建立和关闭非常重要. |
| TCP | TCP.ACK | Custom | 0 | |||
| TCP | TCP.FIN | Custom | 0 | |||
| TCP | TCP Retransmission | Custom | tcp.analysis.retransmission | 0 | 显示 TCP 重传的数据包。 在高丢包率的网络中,TCP 重传的频率较高, 查看此字段有助于检测网络性能问题。 |
|
| TCP | TCP Dup ACK | Custom | tcp.analysis.duplicate_ack | 0 | 显示 TCP 重复确认包,分析网络拥塞或丢包的情况。 | |
| Http | Http Host | Custom | http.host | 0 | 显示 HTTP 请求头的主机名,分析 Web 流量时非常有用. | |
| Http | Http Method | Custom | http.request.method | 0 | 显示 HTTP 请求的方法类型(如 GET、POST、PUT)。 该字段有助于你快速了解 Web 流量的性质。 |
|
| Http | Http URI | Custom | http.request.uri | 0 | 显示 HTTP 请求中的 URI(Uniform Resource Identifier, 统一资源标识符),即请求的路径信息。 通过这个字段,你可以分析 HTTP 请求访问的具体资源。 |
|
| DNS | DNS Query Name | Custom | dns.qry.name | 0 | 显示 DNS 查询请求的域名。帮助分析域名解析的过程。 | |
| DNS | DNS Response Name | Custom | dns.resp.name | 0 | 显示 DNS 响应中的域名解析结果。 如果你正在排查 DNS 问题,这个字段非常有用。 |
|
| ICMP | ICMP Type | Custom | icmp.type | ICMP Type 和 Code: ICMP 数据包的类型和代码。 排查 ping 或 traceroute 详细问题。 |
||
| ICMP | ICMP Code | Custom | icmp.code |
4. 导出数据包
选中数据包,点击左上角的「文件」,点击「导出特定分组」。
- 导出单个数据包: 在「导出分组界面」,选择第二个 「Selected packets only」,只保存选中的数据包。
- 导出多个数据包: 在「导出分组界面」,勾选第三个 「Marked packets only」,只导出标记的数据包。
保存選項
- Captured 已捕获的包
- Displayed 已显示的包
- All Packets 所有包
- Selected Packets 选中的包
- Marked Packets 做了标记的包
- First to last Marked 从第一个标记到最后一个标记的包
- Range [ ] 选择范围, 支持多个范围,
5. Filters
5.1 过滤器语法及參考
构建显示过滤表达式(手册章节6.4)
显示过滤器语法和参考
显示过滤器协议字段的主列表
捕获过滤器(例如tcp port 80)不应与显示过滤器(例如tcp.port == 80)混淆。
- CaptureFilters 捕获过滤器, 用于减小原始数据包捕获的大小。 在开始数据包捕获之前设置,并且在捕获过程中无法修改。
- DisplayFilters 显示过滤器, 用于隐藏数据包列表中的某些数据包。可随时更改
5.2 (捕获/显示)过滤器示例
5.2.1.0 CaptureFilters 捕获过滤器
Capture only traffic to or from IP address 172.18.5.4: 仅捕获往返于 IP 地址 172.18.5.4 的流量:
[[[host 172.18.5.4 ]]]
Capture traffic to or from a range of IP addresses: 捕获往返于某个 IP 地址范围的流量:
[[[net 192.168.0.0/24 ]]]
or
[[[net 192.168.0.0 mask 255.255.255.0 ]]]
Capture traffic from a range of IP addresses: 捕获来自某个 IP 地址范围的流量:
[[[src net 192.168.0.0/24 ]]]
or
[[[src net 192.168.0.0 mask 255.255.255.0 ]]]
Capture traffic to a range of IP addresses: 捕获发往某个 IP 地址范围的流量:
[[[dst net 192.168.0.0/24 ]]]
or
[[[dst net 192.168.0.0 mask 255.255.255.0 ]]]
Capture only DNS (port 53) traffic: 仅捕获 DNS(端口 53)流量:
[[[port 53 ]]]
Capture non-HTTP and non-SMTP traffic on your server (both are equivalent): 捕获服务器上的非 HTTP 和非 SMTP 流量(两者等效):
[[[host www.example.com and not (port 80 or port 25)]]]
[[[host www.example.com and not port 80 and not port 25 ]]]
Capture except all ARP and DNS traffic: 捕获除所有 ARP 和 DNS 流量之外的流量:
[[[port not 53 and not arp ]]]
Capture traffic within a range of ports 捕获某个端口范围内的流量
[[[(tcp[0:2] > 1500 and tcp[0:2] < 1550) or (tcp[2:2] > 1500 and tcp[2:2] < 1550) ]]]
or, with newer versions of libpcap (0.9.1 and later): 或者,使用较新版本的 libpcap(0.9.1 及更高版本):
[[[tcp portrange 1501-1549 ]]]
Capture only Ethernet type EAPOL: 仅捕获以太网类型 EAPOL:
[[[ether proto 0x888e ]]]
Reject ethernet frames towards the Link Layer Discovery Protocol Multicast group: 拒绝发往链路层发现协议 (LLDP) 多播组的以太网帧:
[[[not ether dst 01:80:c2:00:00:0e ]]]
Capture only IPv4 traffic - the shortest filter, but sometimes very useful to get rid of lower layer protocols like ARP and STP: 仅捕获 IPv4 流量 - 最短的过滤器,但有时对于去除 ARP 和 STP 等低层协议非常有用:
[[[ip ]]]
Capture only unicast traffic - useful to get rid of noise on the network if you only want to see traffic to and from your machine, not, for example, broadcast and multicast announcements: 仅捕获单播流量 – 如果您只想查看往返于您设备的流量(例如,不包含广播和多播公告),则此方法有助于消除网络上的噪音:
[[[not broadcast and not multicast ]]]
Capture IPv6 "all nodes" (router and neighbor advertisement) traffic. Can be used to find rogue Ras: 捕获 IPv6 “所有节点”(路由器和邻居通告)流量。可用于查找恶意 RA:
[[[dst host ff02::1 ]]]
Capture HTTP GET requests. This looks for the bytes 'G', 'E', 'T', and ' ' (hex values 47, 45, 54, and 20) just after the TCP header. "tcp[12:1] & 0xf0) >> 2" figures out the TCP header length. 捕获 HTTP GET 请求。这将查找紧跟 TCP 报头之后的字节 'G', 'E', 'T', and ' ' (hex values 47, 45, 54, and 20)。"tcp[12:1] & 0xf0) >> 2"可计算出 TCP 报头的长度。
[[[port 80 and tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x47455420 ]]]
5.2.1.1 Useful Filters
Blaster and Welchia are RPC worms.
Blaster worm:
[[[dst port 135 and tcp port 135 and ip[2:2]==48 ]]]
Welchia worm:
[[[icmp[icmptype]==icmp-echo and ip[2:2]==92 and icmp[8:4]==0xAAAAAAAA ]]]
The filter looks for an icmp echo request that is 92 bytes long and has an icmp payload that begins with 4 bytes of A's (hex). It is the signature of the welchia worm just before it tries to compromise a system. 此过滤器查找长度为 92 字节且有效载荷以 4 个字节 A(十六进制)开头的 ICMP 回显请求。 这是韦尔奇亚蠕虫在试图入侵系统之前的签名。
Many worms try to spread by contacting other hosts on ports 135, 445, or 1433. This filter is independent of the specific worm instead it looks for SYN packets originating from a local network on those specific ports. Please change the network filter to reflect your own network. 许多蠕虫试图通过连接其他主机的 135、445 或 1433 端口进行传播。 此过滤器与特定蠕虫无关,而是在这些特定端口上查找来自本地网络的 SYN 数据包。 请根据您自己的网络更改网络过滤器。
[[[dst port 135 or dst port 445 or dst port 1433 and tcp[tcpflags] & (tcp-syn) != 0 and tcp[tcpflags] & (tcp-ack) = 0 and src net 192.168.0.0/24 ]]]
Heartbleed Exploit: 漏洞
[[[tcp src port 443 and (tcp[((tcp[12] & 0xF0) >> 4 ) * 4] = 0x18) and (tcp[((tcp[12] & 0xF0) >> 4 ) * 4 + 1] = 0x03) and (tcp[((tcp[12] & 0xF0) >> 4 ) * 4 + 2] < 0x04) and ((ip[2:2] - 4 * (ip[0] & 0x0F) - 4 * ((tcp[12] & 0xF0) >> 4) > 69)) ]]]
5.2.1.2 Default Capture Filters 默认捕获过滤器
Wireshark tries to determine if it's running remotely (e.g. via SSH or Remote Desktop), and if so sets a default capture filter that should block out the remote session traffic. It does this by checking environment variables in the following order: Wireshark 会尝试确定蠕虫是否在远程运行(例如通过 SSH 或远程桌面),如果是,则设置一个默认捕获过滤器来阻止远程会话流量。 它通过按以下顺序检查环境变量来实现这一点:
Environment Variable Resultant Filter 环境变量 结果过滤器
SSH_CONNECTION
[[[not (tcp port srcport and addr_family host srchost and tcp port dstport and addr_family host dsthost)]]]
SSH_CLIENT
[[[not (tcp port srcport and addr_family host srchost and tcp port dstport)]]]
REMOTEHOST
[[[not addr_family host host ]]]
DISPLAY
[[[not addr_family host host ]]]
CLIENTNAME
[[[not tcp port 3389]]]
5.2.1.3 Discussion
BTW, the Symantec page says that Blaster probes 135/tcp, 4444/tcp, and 69/udp. 顺便说一句,赛门铁克的页面上显示 Blaster 会探测 135/tcp、4444/tcp 和 69/udp。
[[[(tcp dst port 135 or tcp dst port 4444 or udp dst port 69) and ip[2:2]==48 ]]]
Q: What is a good filter for just capturing SIP and RTP packets? 问:如果只捕获 SIP 和 RTP 数据包,有什么好的过滤器?
A: On most systems, for SIP traffic to the standard SIP port 5060, 答:在大多数系统上,对于发送到标准 SIP 端口 5060 的 SIP 流量,
[[[tcp port sip ]]]
should capture TCP traffic to and from that port, 应该捕获往返于该端口的 TCP 流量,
[[[udp port sip ]]]
should capture UDP traffic to and from that port, and 应该捕获往返于该端口的 UDP 流量,并且
[[[port sip ]]]
应该捕获往返于该端口的 TCP 和 UDP 流量 (如果其中一个过滤器出现“解析错误”,请尝试使用 5060 而不是 sip)。 对于往返于其他端口的 SIP 流量,请使用该端口号而不是 sip。
In most cases RTP port numbers are dynamically assigned. You can use something like the following which limits the capture to UDP, even source and destination ports, a valid RTP version, and small packets. It will capture any non-RTP traffic that happens to match the filter (such as DNS) but it will capture all RTP packets in many environments. 大多数情况下,RTP 端口号是动态分配的。 您可以使用类似下面的方法,将捕获范围限制为 UDP,甚至源端口和目标端口、有效的 RTP 版本以及小数据包。 它将捕获任何恰好符合过滤器(例如 DNS)的非 RTP 流量,但在许多环境中它将捕获所有 RTP 数据包。
[[[udp[1] & 1 != 1 && udp[3] & 1 != 1 && udp[8] & 0x80 == 0x80 && length < 250 ]]]
Capture WLAN traffic without Beacons: 捕获不使用信标的 WLAN 流量:
[[[link[0] != 0x80 ]]]
Capture all traffic originating (source) in the IP range 192.168.XXX.XXX: 捕获 IP 地址范围为 192.168.XXX.XXX 的所有流量:
[[[src net 192.168 ]]]
Capture PPPoE traffic: 捕获 PPPoE 流量:
[[[pppoes ]]]
[[[pppoes and (host 192.168.0.0 and port 80) ]]]
Capture VLAN traffic: 捕获 VLAN 流量:
[[[vlan ]]]
[[[vlan and (host 192.168.0.0 and port 80) ]]]
5.2.2.0 显示过滤器 Examples
Show only SMTP (port 25) and ICMP traffic: 仅显示 SMTP(端口 25)和 ICMP 流量:
[[[tcp.port eq 25 or icmp]]]
Show only traffic in the LAN (192.168.x.x), between workstations and servers -- no Internet: 仅显示 LAN(192.168.x.x)中工作站和服务器之间的流量 – 无互联网连接:
[[[ip.src==192.168.0.0/16 and ip.dst==192.168.0.0/16]]]
TCP buffer full -- Source is instructing Destination to stop sending data TCP 缓冲区已满 – 源设备指示目标设备停止发送数据
[[[tcp.window_size == 0 && tcp.flags.reset != 1]]]
Filter on Windows -- Filter out noise, while watching Windows Client - DC exchanges Windows 上的过滤器 - 过滤掉噪音,同时监视 Windows 客户端与 DC 之间的数据交换
[[[smb || nbns || dcerpc || nbss || dns]]]
Sasser worm: --What sasser really did-- Sasser 蠕虫:--Sasser 的真正作用--
[[[ls_ads.opnum==0x09]]]
Match packets containing the (arbitrary) 3-byte sequence 0x81, 0x60, 0x03 at the beginning of the UDP payload, skipping the 8-byte UDP header. Note that the values for the byte sequence implicitly are in hexadecimal only. (Useful for matching homegrown packet protocols.) 匹配 UDP 有效载荷开头包含(任意)3 字节序列 0x81、0x60、0x03 的数据包,跳过 8 字节UDP 报头。 请注意,字节序列的值隐式地仅以十六进制表示。(用于匹配自主开发的数据包协议。)
[[[udp[8:3]==81:60:03]]]
The "slice" feature is also useful to filter on the vendor identifier part (OUI) of the MAC address, see the Ethernet page for details. Thus you may restrict the display to only packets from a specific device manufacturer. E.g. for DELL machines only: “切片”功能也可用于过滤 MAC 地址的供应商标识符部分 (OUI),详情请参阅以太网页面。 这样,您可以将显示限制为仅显示来自特定设备制造商的数据包。 例如,仅适用于 DELL 机器:
[[[eth.addr[0:3]==00:06:5B]]]
It is also possible to search for characters appearing anywhere in a field or protocol by using the contains operator. 还可以使用 contains 运算符搜索字段或协议中任何位置出现的字符。
Match packets that contains the 3-byte sequence 0x81, 0x60, 0x03 anywhere in the UDP header or payload: 匹配 UDP 报头或有效载荷中任何位置包含 3 字节序列 0x81、0x60、0x03 的数据包:
[[[udp contains 81:60:03]]]
Match packets where SIP To-header contains the string "a1762" anywhere in the header: 匹配 SIP To 报头在报头任何位置包含字符串“a1762”的数据包:
[[[sip.To contains "a1762"]]]
The matches, or ~, operator makes it possible to search for text in string fields and byte sequences using a regular expression, using Perl regular expression syntax. Note: Wireshark needs to be built with libpcre in order to be able to use the matches operator. matches(或 ~)运算符可以使用正则表达式(使用 Perl 正则表达式语法)在字符串字段和字节序列中搜索文本。 注意:Wireshark 需要使用 libpcre 构建才能使用 matches 运算符。
Match HTTP requests where the last characters in the uri are the characters "gl=se": 匹配 URI 中最后一个字符为“gl=se”的 HTTP 请求:
[[[http.request.uri matches "gl=se$"]]]
Note: The $ character is a PCRE punctuation character that matches the end of a string, in this case the end of http.request.uri field. 注意:$ 字符是 PCRE 标点符号,用于匹配字符串的结尾,在本例中是 http.request.uri 字段的结尾。
Filter by a protocol ( e.g. SIP ) and filter out unwanted Ips: 按协议(例如 SIP)过滤并滤除不需要的 IP:
[[[ip.src != xxx.xxx.xxx.xxx && ip.dst != xxx.xxx.xxx.xxx && sip]]]
With Wireshark 4.0+ you can select a specific a specific occurrence of a field. To use the layer operator, just put a number sign and a layer number after a field. For example, if we have a GRE packet with both outer and inner IPv4 layers, 使用 Wireshark 4.0 及以上版本,您可以选择字段的特定出现位置。 要使用层运算符,只需在字段后添加一个数字符号和一个层编号即可。 例如,如果我们有一个包含内外 IPv4 层的 GRE 数据包,
[[[ip.src#1 == 10.1.2.3]]]
will match the outer address, 将匹配外部地址,
[[[ip.src#2 == 10.1.2.3]]]
will match the inner address, and 将匹配内部地址,
[[[ip.src == 10.1.2.3]]]
will match either address. 将匹配任一地址。
5.2.2.1 Gotchas 陷阱
Some filter fields match against multiple protocol fields. For example, "ip.addr" matches against both the IP source and destination addresses in the IP header. The same is true for "tcp.port", "udp.port", "eth.addr", and others. 某些过滤字段会匹配多个协议字段。 例如,“ip.addr”会同时匹配 IP 报头中的源 IP 地址和目标 IP 地址。 “tcp.port”、“udp.port”、“eth.addr”等字段也是如此。
[[[ip.addr == 10.43.54.65]]]
is equivalent to 相当于
[[[ip.src == 10.43.54.65 or ip.dst == 10.43.54.65]]]
Before Wireshark 3.6, this can be counterintuitive in some cases. Suppose we want to filter out any traffic to or from 10.43.54.65. We might try the following: 在 Wireshark 3.6 之前的版本中,这在某些情况下可能违反直觉。 假设我们想要过滤掉所有往返于 10.43.54.65 的流量。 我们可以尝试以下代码:
[[[ip.addr != 10.43.54.65]]]
which is equivalent to
[[[ip.src != 10.43.54.65 or ip.dst != 10.43.54.65]]]
This translates to "pass all traffic except for traffic with a source IPv4 address of 10.43.54.65 and a destination IPv4 address of 10.43.54.65", which isn't what we wanted. 这相当于“除了源 IPv4 地址为 10.43.54.65 和目标 IPv4 地址为 10.43.54.65 的流量之外,所有流量都通过”,但这并非我们想要的结果。
Instead we need to negate the expression, like so: 相反,我们需要对表达式取反,如下所示:
[[[! ( ip.addr == 10.43.54.65 )]]]
which is equivalent to
[[[! (ip.src == 10.43.54.65 or ip.dst == 10.43.54.65)]]]
This translates to "pass any traffic except with a source IPv4 address of 10.43.54.65 or a destination IPv4 address of 10.43.54.65", which is what we wanted. 这相当于“除了源 IPv4 地址为 10.43.54.65 或目标 IPv4 地址为 10.43.54.65 的流量外,其他流量均可通过”,这正是我们想要的。
This can also happen if, for example, you have tunneled protocols, so that you might have two separate IPv4 or IPv6 layers and two separate IPv4 or IPv6 headers, or if you have multiple instances of a field for other reasons, such as multiple IPv6 "next header" fields. 例如,如果您使用隧道协议,则可能有两个独立的 IPv4 或 IPv6 层以及两个独立的 IPv4 或 IPv6 报头;或者由于其他原因(例如多个 IPv6“下一个报头”字段)某个字段有多个实例,则也可能发生这种情况。
If you have a filter expression of the form name op value, where name is the name of a field, op is a comparison operator such as == or != or < or..., and value is a value against which you're comparing, it should be thought of as meaning "match a packet if there is at least one instance of the field named name whose value is (equal to, not equal to, less than, ...) value". The negation of that is "match a packet if there are no instances of the field named name whose value is (equal to, not equal to, less than, ...) value"; simply negating op, e.g. replacing == with != or < with >=, give you another "if there is at least one" check, which is not the negation of the original check. 如果您有一个 name op value 形式的过滤器表达式,其中 name 是字段名称,op 是比较运算符(例如 == 或 != 或 < 等),value 是要比较的值,则应该将其理解为“如果至少有一个名为 name 的字段实例的值为(等于、不等于、小于……)value,则匹配该数据包”。 它的否定形式是“如果不存在名为 name 的字段实例,且其值为(等于、不等于、小于……)value,则匹配数据包”; 简单地否定操作符,例如将 == 替换为 != 或将 < 替换为 >=,会给出另一个“如果至少有一个”的检查,而这并不是对原始检查的否定。
With Wireshark 3.6+ the display filter syntax interpretation has been modified to prevent such easy mistakes. The original interpretation is still available, under a slightly different syntax. See the User's Guide for more information. Wireshark 3.6+ 版本修改了显示过滤器的语法解释,以避免此类容易犯的错误。 原始解释仍然可用,但语法略有不同。 有关更多信息,请参阅用户指南。
没有评论:
发表评论