四、Linux和Windows以及QT下的网络编程之Wireshark抓包分析

注意: 输入过虑规则时,如果语法有误,显红色,正确,显绿色。

1.基本命令:

1.前面加!号 (加not)         表示否

2.语句之间用 or                   表示或者

3.语句之间用and                 表示和

4.语句之间用&&                     表示且

tcp udp arp icmp http smtp ftp dns msnms ip ssl oicq bootp and or 等等

less than 小于 < lt                 小于等于 le

等于 eq                                 大于 gt

大于等于 ge                          不等 ne

2.IP过滤

例子:ip.src eq 192.168.0.1 or ip.dst eq 192.168.0.1         //指定来源或者目标

例子:ip.addr eq 192.168.0.1                                             // 不指定来源和目标IP       都显示

3.端口过滤

例子:tcp.port eq 80 或者tcp.port == 80                             // 不指定来源和目标端口    都显示

tcp.port eq 80 or udp.port eq 80                                       // 指定tcp  udp   or或

tcp.dstport == 80 or tcp.srcport == 80                              // tcp协议的来源端口 或者 tcp协议的目标端口

tcp.port >= 1 and tcp.port <= 80                                       //过滤端口范围

4.MAC过滤

eth.dst == 01:02:03:04:05:06  or  eth.src eq A0:00:00:04:C5:84    // 过滤来源mac和过滤目标mac

eth.addr eq A0:00:00:04:C5:84                                                       // 过滤来源MAC和目标MAC都等于A0:00:00:04:C5:84的

5.包过滤

udp.length == 1024                                                     //指定长度是指udp本身固定长度加上数据包之和

tcp.len >= 7                                                                 //指的是ip数据包(tcp下面那块数据),不包括tcp本身

ip.len == 94                                                                 //除了以太网头固定长度14,其它都算是ip.len,即从ip本身到最后

frame.len == 119                                                         //整个数据包长度,从eth开始到最后

eth —> ip or arp —> tcp or udp —> data

6.http模式过滤

http.request.method == “GET”  or  http.request.method == “POST”

http.request.uri == “/img/logo-edu.gif”

http contains “GET” or http contains “HTTP/1.”

http.request.method == “GET” && http contains “Host: “// GET包

http.request.method == “GET” && http contains “User-Agent: “

http.request.method == “POST” && http contains “Host: “// POST包

http.request.method == “POST” && http contains “User-Agent: “

http contains “HTTP/1.1 200 OK” && http contains “Content-Type: “// 响应包

http contains “HTTP/1.0 200 OK” && http contains “Content-Type: “

http.host==magentonotes.com
http.host contains magentonotes.com//过滤经过指定域名的http数据包,这里的host值不一定是请求中的域名

http.response.code==302//过滤http响应状态码为302的数据包

http.response==1//过滤所有的http响应包

http.request==1//过滤所有的http请求,貌似也可以使用http.request

http.request.method==POST                              //wireshark过滤所有请求方式为POST的http请求包,注意POST为大写

http.cookie contains guid                                                                //过滤含有指定cookie的http数据包

http.request.uri==”/online/setpoint”                                                 //过滤请求的uri,取值是域名后的部分

http.request.full_uri==” http://task.browser.360.cn/online/setpoint”//过滤含域名的整个url则需要使用http.request.full_uri

http.server contains “nginx”                         //过滤http头中server字段含有nginx字符的数据包

http.content_type == “text/html”                  //过滤content_type是text/html的http响应、post包,即根据文件类型过滤http数据包

http.content_encoding == “gzip”                 //过滤content_encoding是gzip的http包

http.transfer_encoding == “chunked”         //根据transfer_encoding过滤

http.content_length == 279
http.content_length_header == “279″         //根据content_length的数值过滤

http.server                                                  //过滤所有含有http头中含有server字段的数据包

http.request.version == “HTTP/1.1″           //过滤HTTP/1.1版本的http包,包括请求和响应

http.response.phrase == “OK”                   //过滤http响应中的phrase

7.TCP参数过滤

tcp.flags                                              //显示包含TCP标志的封包。

tcp.flags.syn == 0x02                         //显示包含TCP SYN标志的封包。

tcp.window_size == 0 && tcp.flags.reset != 1

8.包内容过滤

前面加!号代表去除该包。

tcp[20]                                                  //表示从20开始,取1个字符

tcp[20:]                                                 //表示从20开始,取1个字符以上

udp[8:3]==81:60:03                              // 偏移8个bytes,再取3个数,是否与==后面的数据相等?

udp[8:1]==32                                        //udp[offset:截取个数]=nValue

eth.addr[0:3]==00:06:5B

9.DHCP

注意:DHCP协议的检索规则不是dhcp/DHCP, 而是bootp

以寻找伪造DHCP服务器为例,介绍Wireshark的用法。在显示过滤器中加入过滤规则,

显示所有非来自DHCP服务器并且bootp.type==0x02(Offer/Ack/NAK)的信息:

bootp.type==0x02 and not ip.src==192.168.1.1