最新消息:

Wireshark 入门详解

Wireshark admin 4144浏览 0评论

目录:

一、 background

二、 how it works

三、包抓取方式

四、 filter in Wireshark

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

五、 Wireshark的安装

六、 Wireshark的实用功能

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

七、 Wireshark的扩展

  •  ip地理信息扩展

八、让Wireshark支持自定义协议

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

九、附录

一、background

Wireshark是一款支持多平台的包抓取分析开源软件,前身是ethereal。

Wireshark基于libpcap on unix-like,winpcap on windows。Tcpdump同样基于libpcap实现。Libpcap来自于BPF,下图是BPF的一个结构图:

eGhoXzAxNjg_581780

二、how it works

eGhoXzAxNjg_662678

三、How packets capture

当前Wireshark支持以下三种包抓取方式:
1. 网络适配器上实时抓取;
2. 远程主机抓取;
3. pipe方式抓取;

这里主要介绍下远程主机的抓取方式,此功能依赖于libpcap/winpcap提供的rpcapd.程序:

eGhoXzAxNjg_761350

首先服务器端建立侦听

eGhoXzAxNjg_795668

然后客户端连接到服务器端

eGhoXzAxNjg_837651

eGhoXzAxNjg_891938

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

eGhoXzAxNjg_975383

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通信

eGhoXzAxNjg_196496

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

  • Statistics

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

eGhoXzAxNjg_253606

  •  Flow graph

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

eGhoXzAxNjg_315860

  •  Tcp stream graph

七、Wireshark extension

  •   ip地理信息扩展

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

eGhoXzAxNjg_407300

eGhoXzAxNjg_437827

八、让Wireshark支持自定义协议

  •  Wireshark中的协议解析器模块

源码下的epan目录

  • Lua编写协议解析插件

Init.lua文件

Lua为何物

eGhoXzAxNjg_512768

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/

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

版权说明

文章标题: Wireshark 入门详解
本文地址: http://www.ttlsa.com/linux/wireshark-detailed/
除非注明,博客文章均为”运维生存时间”原创,转载请标明本文地址

转载请注明:爱开源 » Wireshark 入门详解

您必须 登录 才能发表评论!