在设计wiresharek的抓包过滤器时,会用到IP、TCP、UPD、ICMP等协议的包头部中的属性字段值,下面的链接总结了此方面的内容,可以作为参考。
(1)母链接:http://www.packetlevel.ch/html/tcpdumpf.html
(2)子链接:http://www.packetlevel.ch/html/txt/byte_offsets.txt
下面举几个通过使用IP的包头部的属性字段设计的抓包过滤器:
(1)抓取特定长度(如62字节)的IP数据包
ip[2:2] == 62
说明:其中62表示并指定IP包头中的“IP包总长度”字段值
(2)抓取特定TTL(生存时间)的IP数据包
ip[8] == <TTL_value>
说明:其中TTL_value表示IP包头中的“TTL”字段值
(3)抓取特定协议类型的IP数据包
ip[9] == 6
说明:其中6表示IP包头中的“协议类型”字段值为6,在数据包IP头部中会显示为:Protocol : TCP (6),即抓取TCP协议的数据包
1表示ICMP、17表示UDP、6表示TCP等等。
(4)抓取源IP地址和目标IP地址相同的IP数据包
ip[12:4] == ip[16:4]
此部分的原理见下图所示:
下面是母链接给出协议头部中所有属性字段的byte_offset内容获取方法:
common Filters
ip IP
arp arp
tcp tcp
udp udp
icmp icmp
ip multicast IP Multicast
ether multicast Ethernet Multicast
IP Filters
ip[0] & 0x0f low nibble: header length in 4octet words. should be 5
ip[1] type of service/QoS/DiffServ
ip[2:2] total length of datagram in octets
ip[4:2] IP ID number
ip[6] & 0x80 reserved bit (possibly used for ECN)
ip[6] & 0x40 DF bit
ip[6] & 0x20 MF bit
ip[6:2] & 0x1fff fragment offset (number of 8octet blocks)
ip[8] ttl
ip[9] protocol
ip[10:2] header checksum
ip[12:4] source IP
ip[16:4] destination IP
Samples
(ip[12:4] = ip[16:4]) Src IP = Dest IP (land attack)
ip[0] & 0xf0 high nibble: IP version. almost always 4
(ip[0] & 0xf0 != 0x40) IP versions !=4
(ip[0:1] & 0x0f > 5) IP with options set
(ip[19] = 0xff) Broadcasts to x.x.x.255
(ip[19] = 0x00) Broadcasts to x.x.x.0
(ip and ip[1] & 0xfc == 0xb8) search for EF in DSCP
(ip and ip[1] &