Wireshark 入门详解

默北 LinuxWireshark 入门详解已关闭评论30,1844字数 2334阅读7分46秒阅读模式

目录:

一、 background

二、 how it works文章源自运维生存时间-https://www.ttlsa.com/linux/wireshark-detailed/

三、包抓取方式文章源自运维生存时间-https://www.ttlsa.com/linux/wireshark-detailed/

四、 filter in Wireshark文章源自运维生存时间-https://www.ttlsa.com/linux/wireshark-detailed/

  •   Capture filter例子
  • 抓取所有本主机发送的报文,本机为2.2.2.2
  • 抓取与主机1.1.1.1.的1033端口的所有通信
  • 抓取所有的tcp RST报文

五、 Wireshark的安装文章源自运维生存时间-https://www.ttlsa.com/linux/wireshark-detailed/

六、 Wireshark的实用功能文章源自运维生存时间-https://www.ttlsa.com/linux/wireshark-detailed/

  • l Follow tcp stream
  • l Statistics
  • l Flow graph
  • l Tcp stream graph

七、 Wireshark的扩展文章源自运维生存时间-https://www.ttlsa.com/linux/wireshark-detailed/

  •  ip地理信息扩展

八、让Wireshark支持自定义协议文章源自运维生存时间-https://www.ttlsa.com/linux/wireshark-detailed/

  •  Wireshark中的协议解析器模块
  • l Lua编写协议解析插件
  1.  Lua为何物
  2. Wireshark与lua的关系
  3. 使用lua编写自定义协议解析器

九、附录文章源自运维生存时间-https://www.ttlsa.com/linux/wireshark-detailed/

一、background

Wireshark是一款支持多平台的包抓取分析开源软件,前身是ethereal。文章源自运维生存时间-https://www.ttlsa.com/linux/wireshark-detailed/

Wireshark基于libpcap on unix-like,winpcap on windows。Tcpdump同样基于libpcap实现。Libpcap来自于BPF,下图是BPF的一个结构图:文章源自运维生存时间-https://www.ttlsa.com/linux/wireshark-detailed/

ethereal文章源自运维生存时间-https://www.ttlsa.com/linux/wireshark-detailed/

二、how it works

ethereal文章源自运维生存时间-https://www.ttlsa.com/linux/wireshark-detailed/

三、How packets capture

当前Wireshark支持以下三种包抓取方式:
1. 网络适配器上实时抓取;
2. 远程主机抓取;
3. pipe方式抓取;文章源自运维生存时间-https://www.ttlsa.com/linux/wireshark-detailed/

这里主要介绍下远程主机的抓取方式,此功能依赖于libpcap/winpcap提供的rpcapd.程序:文章源自运维生存时间-https://www.ttlsa.com/linux/wireshark-detailed/

ethereal文章源自运维生存时间-https://www.ttlsa.com/linux/wireshark-detailed/

首先服务器端建立侦听文章源自运维生存时间-https://www.ttlsa.com/linux/wireshark-detailed/

ethereal文章源自运维生存时间-https://www.ttlsa.com/linux/wireshark-detailed/

然后客户端连接到服务器端文章源自运维生存时间-https://www.ttlsa.com/linux/wireshark-detailed/

ethereal文章源自运维生存时间-https://www.ttlsa.com/linux/wireshark-detailed/

ethereal文章源自运维生存时间-https://www.ttlsa.com/linux/wireshark-detailed/

现在能看见远程主机网卡上的流量了

ethereal

Packet由libpcap抓取之后通过管道传送到wireshark,由此远程抓包只是流量重定向而已。

四、filter in Wireshark

Wireshark中提供了两种filter:

1. Capture filter;

2. Display filter;

其中capture filter来自于libpcap,语法如下 

[direction] [[type] value] [proto]

Direction: src dst

Type: host net port

Proto: ether tcp udp arp ...

Capture filter在libpcap实现,只有满足过滤器的包之后才会送往应用程序。

l  Capture filter例子

  • 抓取所有本主机发送的报文,本机为2.2.2.2

src host 2.2.2.2

  • 抓取与主机1.1.1.1.的1033端口的所有通信

host 1.1.1.1 && port 1033

  • 抓取所有的tcp RST报文

tcp[13]&4==4 || tcp[13]&4==14       #tcp的flag在偏移13字节的地方,占据1字节

Display filter来自于Wireshark,用于对捕获包的显示过滤。Wireshark利用此filter还是实现了coloring rules,statistics等功能。

五、Wireshark install

Wireshark依赖于libpcap/winpcap,于是在应用程序安装之前,首先安装此库。

六、Wireshark utility

  •  Follow tcp stream

Wireshark将通信抽象成流的概念,按照Wireshark的解释,流是“The stream content is displayed in the same sequence as it appeared on the network”,就是一个序列号下来的通信,主要针对tcp通信

ethereal

红方表示发送方,蓝方表示回送方

  • Statistics

可以按照协议,按照endpoint,按照packet length进行统计显示

ethereal

  •  Flow graph

将网络通信以时序图的方式展现出来

ethereal

  •  Tcp stream graph

七、Wireshark extension

  •   ip地理信息扩展

maxmind是一个在线ip地理信息提供商GeoIP,http://www.maxmind.com,它提供了一个离线数据库文件,Wireshark加载此文件,可以在显示捕获包的同时显示该包中的IP的地理信息;

ethereal

ethereal

八、让Wireshark支持自定义协议

  •  Wireshark中的协议解析器模块

源码下的epan目录

  • Lua编写协议解析插件

Init.lua文件

Lua为何物

ethereal

Wireshark与lua的关系

  1.  wireshark内置了lua解释器
  2.  Lua作为wireshark的扩展通道,为wireshark提供支持自定义的协议解析的能力

a) 侦听时分析

b) 显示时分析

3. Wireshark通过init.lua进入其他的lua程序

使用lua编写自定义协议解析器

1. 步骤

a)   定义协议

b)  定义解析函数

c)   在全局解析函数table中加入解析规则

九、附录

最初的libpcap论文:http://www.tcpdump.org/papers/bpf-usenix93.pdf
Capture filter语法:http://www.Wireshark.org/docs/wsug_html_chunked/ChCapCaptureFilterSection.html
Wireshark提供了display filter功能,该语法介绍如下:http://www.Wireshark.org/docs/wsug_html_chunked/ChWorkBuildDisplayFilterSection.html
Wiki上对于GeoIP的说明:http://wiki.Wireshark.org/HowToUseGeoIP
GeoIP的下载页面:http://dev.maxmind.com/geoip/legacy/downloadable/

本文由网友李文博提供。希望大家加入我们,一起成长。

weinxin
我的微信
微信公众号
扫一扫关注运维生存时间公众号,获取最新技术文章~
默北
  • 本文由 发表于 16/07/2014 08:32:32
  • 转载请务必保留本文链接:https://www.ttlsa.com/linux/wireshark-detailed/
  • ethereal
  • Wireshark