当前位置:文档之家› 简洁的Pcap文件格式--Wireshark

简洁的Pcap文件格式--Wireshark

PCAP 文件格式协议分析一、基本格式:文件头数据包头数据报数据包头数据报......pcap文件格式结构格式如结构体pcap_file_header格式如pcap_pkthdr数据包格式如pcap_pkthdr数据包格式如pcap_pkthdr数据包二、文件头结构体:sturct pcap_file_header{DWORD magic;WORD version_major;WORD version_minor;DWORD thiszone;DWORD sigfigs;DWORD snaplen;DWORD linktype;}说明:1、标识位:32位的,这个标识位的值是16进制的 0xa1b2c3d4。

a 32-bit magic number ,The magic number has the value hex a1b2c3d4.2、主版本号:16位,默认值为0x2。

a 16-bit major version number,The major version number should have the value 2.3、副版本号:16位,默认值为0x04。

a 16-bit minor version number,The minor version number should have the value 4.4、区域时间:32位,实际上该值并未使用,因此可以将该位设置为0。

a 32-bit time zone offset field that actually not used, so youcan (and probably should) just make it 0;5、精确时间戳:32位,实际上该值并未使用,因此可以将该值设置为0。

a 32-bit time stamp accuracy field tha not actually used,so you can (and probably should) just make it 0;6、数据包最大长度:32位,该值设置所抓获的数据包的最大长度,如果所有数据包都要抓获,将该值设置为65535;例如:想获取数据包的前64字节,可将该值设置为64。

a 32-bit snapshot length" field;The snapshot length field should be the maximum number of bytes perpacket that will be captured. If the entire packet is captured, make it 65535; if you only capture, for example, the first 64 bytes of the packet, make it 64.7、链路层类型:32位,数据包的链路层包头决定了链路层的类型。

a 32-bit link layer type field.The link-layer type depends on the type of link-layer header that thepackets in the capture file have:以下是数据值与链路层类型的对应表0 BSD loopback devices, except for later OpenBSD1 Ethernet, and Linux loopback devices 以太网类型,大多数的数据包为这种类型。

6 802.5 Token Ring7 ARCnet8 SLIP9 PPP10 FDDI100 LLC/SNAP-encapsulated ATM101 raw IP, with no link102 BSD/OS SLIP103 BSD/OS PPP104 Cisco HDLC105 802.11108 later OpenBSD loopback devices (with the AF_value in network byte order)113 special Linux cooked capture114 LocalTalk三、数据包头结构体:struct pcap_pkthdr{struct timeval ts;DWORD caplen;DWORD len;}struct timeval{DWORD GMTtime;DWORD microTime}说明:1、时间戳,包括:秒计时:32位,一个UNIX格式的精确到秒时间值,用来记录数据包抓获的时间,记录方式是记录从格林尼治时间的1970年1月1日 00:00:00 到抓包时经过的秒数;毫秒计时:32位,抓取数据包时的毫秒值。

a time stamp, consisting of:a UNIX-format time-in-seconds when the packet was captured, i.e. the number of seconds since January 1,1970, 00:00:00 GMT (that GMT, *NOT* local time!);the number of microseconds since that second when the packet was captured;2、数据包长度:32位,标识所抓获的数据包保存在pcap文件中的实际长度,以字节为单位。

a 32-bit value giving the number of bytes of packet data that were captured;3、数据包实际长度:所抓获的数据包的真实长度,如果文件中保存不是完整的数据包,那么这个值可能要比前面的数据包长度的值大。

a 32-bit value giving the actual length of the packet, in bytes (which may be greater than the previous number, if you are not saving the entire packet).Wireshark的Pcap文件格式分析前段时间因工作要求,需要对各种数据包进行分析和操作,内容涉及网路协议分析,socket,文件操作等。

在此分享下学习和实践的经验。

首先介绍下网络抓包、协议分析的必备软件Ethereal,新版(Wireshark)以下还以 Ethereal代之,目前最新版本已经支持在无线局域网抓包了。

Linux和Windows均有对应安装包,它们分别是gcc和VC++编译的。

不过 Windows下是基于Winpcap而Linux下则是Libcap。

Ethereal作为网路协议分析、学习、开发的敲门软件,其使用技巧及其原理机制(BPF)网上都有比较详尽的介绍,当初我收集的相关资料随后也会上传,不再多说。

下面主要介绍下Ethereal默认的*.pcap文件保存格式。

Pcap文件头24B各字段说明:Magic:4B:0x1A 2B 3C 4D:用来标示文件的开始Major:2B,0x02 00:当前文件主要的版本号Minor:2B,0x04 00当前文件次要的版本号ThisZone:4B当地的标准时间;全零SigFigs:4B时间戳的精度;全零SnapLen:4B最大的存储长度LinkType:4B链路类型常用类型:0 BSD loopback devices, except for later OpenBSD1 Ethernet, and Linux loopback devices6 802.5 Token Ring7 ARCnet8 SLIP9 PPP10 FDDI100 LLC/SNAP-encapsulated ATM101 "raw IP", with no link102 BSD/OS SLIP103 BSD/OS PPP104 Cisco HDLC105 802.11108 later OpenBSD loopback devices (with the AF_value in network byte order)113 special Linux "cooked" capture114 LocalTalkPacket 包头和Packet数据组成字段说明:Timestamp:时间戳高位,精确到secondsTimestamp:时间戳低位,精确到microsecondsCaplen:当前数据区的长度,即抓取到的数据帧长度,由此可以得到下一个数据帧的位置。

Len:离线数据长度:网络中实际数据帧的长度,一般不大于caplen,多数情况下和Caplen数值相等。

Packet 数据:即 Packet(通常就是链路层的数据帧)具体内容,长度就是Caplen,这个长度的后面,就是当前PCAP文件中存放的下一个Packet数据包,也就是说:PCAP文件里面并没有规定捕获的Packet数据包之间有什么间隔字符串,下一组数据在文件中的起始位置。

我们需要靠第一个Packet包确定。

最后,Packet数据部分的格式其实就是标准的网路协议格式了可以任何网络教材上找得到。

网络抓包、协议分析的强大的软件Ethereal,由自由软件发展而来,由于众多爱好者的不断完善和添加网络协议模块,现在已经能够支持几乎所有常见的网络协议数据的分析。

现在Ethereal改称Wireshark了,目前最新版本已经支持在无线局域网抓包了。

Linux和Windows均有对应安装包,它们分别是gcc和VC++编译的。

不过 Windows下是基于Winpcap而Linux下则是Libcap。

Ethereal作为网路协议分析、学习、开发的专业门软件,其保存网络数据包的格式逐渐成为了一种标准,下面就介绍下Ethereal默认的*.pcap文件保存格式。

Pcap文件头24B各字段说明:Magic:4B:0x1A 2B 3C 4D:用来标示文件的开始Major:2B,0x02 00:当前文件主要的版本号Minor:2B,0x04 00当前文件次要的版本号ThisZone:4B当地的标准时间;全零SigFigs:4B时间戳的精度;全零SnapLen:4B最大的存储长度LinkType:4B链路类型常用类型:0 BSD loopback devices, except for later OpenBSD1 Ethernet, and Linux loopback devices6 802.5 Token Ring7 ARCnet8 SLIP9 PPP10 FDDI100 LLC/SNAP-encapsulated ATM101 "raw IP", with no link102 BSD/OS SLIP103 BSD/OS PPP104 Cisco HDLC105 802.11108 later OpenBSD loopback devices (with the AF_value in network byte order)113 special Linux "cooked" capture114 LocalTalkPacket 包头和Packet数据组成字段说明:Timestamp:时间戳高位,精确到secondsTimestamp:时间戳低位,精确到microsecondsCaplen:当前数据区的长度,即抓取到的数据帧长度,由此可以得到下一个数据帧的位置。

相关主题