wireshark入门

1,157 阅读3分钟

你将获得 :

  • wireshark常见过滤使用方法

  • wireshark常见统计分析使用


前段时间遇到个线上问题 :

客户现场的在线协同白板功能频繁断线,做了各种调整尝试,两天过去依旧无法解决问题验收,最终需要研发小哥飞的上门处理。最近在梳理wireshark的内容,后来回想,利用wireshark或许远程半个小时即可定位问题。具体的问题和定位方法,在结尾处给出。


接下来先了解下wireshark的用法


一. wireshark架构

1.架构图

Core

Main "glue code" that holds the other blocks together

Epan

Enhanced Packet ANalyzer — the packet analyzing engine

  • Protocol Tree Dissection information for an individual packet

  • Dissectors The various protocol dissectors in epan/dissectors

  • Dissector Plugins Support for implementing dissectors as separate modules

  • Display Filters The display filter engine at epan/dfilter

Wiretap

used to read and write capture files in libpcap, pcapng, and many other file formats

Capture

The interface to the capture engine

Dumpcap

The capture engine itself. This is the only part that executes with elevated privileges

WinPcap / libpcap

2.关于*Pcap

npf利用网卡的混杂模式采集所有经过网卡的数据,wpcap提供pcap在Windows上的实现


二.捕获过滤器

1.wireshark面板

2.BPF(伯克利包过滤)

2.1 expression表达式

Type: host,net,port,portrange

Dir: src, dst

Proto: ether, fddi, tr, wlan, ip, ip6, arp, rarp, decnet, tcp, udp

2.2 支持基于协议域过滤例如:只抓TCP RST包tcp[13]&4 == 4

注意:避免遗漏重要包,例如广播包等



三.显示过滤器

1.报文字段-过滤字段对应关系

mac wireshark: View -> Internals -> Supported Protocols


2.filter expression工具

wireshark提供了可视化的过滤表达式的工具,如果不熟悉可以在工具栏调出(MAC环境:Analyze -> Display Filter Expression)

Relation(过滤值比较)

  • Matches(支持正则)

  • Contains

Value

  • Address

  • String

  • Integer

表达式支持切片和集合操作

  • eth.src[0:3] == AA:BB:CC

  • tcp port in {443 80}



四.统计分析

1.捕获包长分布

2.数据包列表标记符号

3.tcp stream

支持TCP流 时序、吞吐量、RTT、窗口尺寸统计


4.http stream

支持报文数、请求数据、负载分布的统计


5.I/OGraph

展示抓包期间流量的情况,支持自定义filter对比分析

6.Flow graph

可以查看分析每个flow的详细包来往情况

7.专家信息

提供了Error、Warming、Note、chat级别的提示


回到开篇的问题,研发小哥到达现场后更换了跟PC直连的路由器,发现功能恢复正常,原来是路由器有个机制,在当前局域网的连接数超过1000后就会关闭超出的连接,导致了功能的频繁上下线。

如果一开始用wireshark,如何去发现问题呢?

1.沟通梳理网络架构

2.在客户端PC抓包

3.分析包RST信号,如果是路由器直接断开连接,那么TTL会是64(不同的系统可能不相同,不同的网络设备实现也可能不相同,断开连接或者拒绝SYN转发等),而非服务端或者中间其他节点