立即注册 登录
51学通信技术论坛 返回首页

linyuxuan的个人空间 http://www.51xuetongxin.com/bbs/?364 [收藏] [复制] [分享] [RSS]

日志

/* WireShark 过滤语法 */(1)

已有 968 次阅读2011-8-4 01:03 |个人分类:工具分析

/* WireShark 过滤语法 */

1.
过滤IP,如来源IP或者目标IP等于某个IP
例子:
ip.src eq 192.168.1.107 or ip.dst eq 192.168.1.107
或者
ip.addr eq 192.168.1.107 //
都能显示来源IP和目标IP
!tcp and !gsm  删除tcp协议 和gsm协议
2.
过滤端口
例子:
tcp.port eq 80 //
不管端口是来源的还是目标的都显示
tcp.port == 80
tcp.port eq 2722
tcp.port eq 80 or udp.port eq 80
tcp.dstport == 80 //
只显tcp协议的目标端口80
tcp.srcport == 80 //
只显tcp协议的来源端口80

gtp.imsi==460....

udp.port eq 15000

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

3.
过滤协议
例子:
tcp
udp
arp
icmp
http
smtp
ftp
dns
msnms
ip
ssl
oicq
bootp

gprs_map

等等

排除arp包,如!arp   或者   not arp

4.
过滤MAC
太以网头过滤
eth.dst == A0:00:00:04:C5:84 //
过滤目标mac
eth.src eq A0:00:00:04:C5:84 //
过滤来源mac
eth.dst==A0:00:00:04:C5:84
eth.dst==A0-00-00-04-C5-84
eth.addr eq A0:00:00:04:C5:84 //
过滤来源MAC和目标MAC都等于A0:00:00:04:C5:84

less than
小于 < lt
小于等于 le

等于 eq
大于 gt
大于等于 ge
不等 ne

5.
包长度过滤
例子:
udp.length == 26
这个长度是指udp本身固定长度8加上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"
http.request.method == "POST"
http.request.uri == "/img/logo-edu.gif"
http contains "GET"
http contains "HTTP/1."

// GET

http.request.method == "GET" && http contains "Host: "
http.request.method == "GET" && http contains "User-Agent: "
// POST

http.request.method == "POST" && http contains "Host: "
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: "
一定包含如下
Content-Type:


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个字符以上
tcp[20:8]
表示从20开始,取8个字符
tcp[offset,n]

udp[8:3]==81:60:03 //
偏移8bytes,再取3个数,是否与==后面的数据相等?
udp[8:1]==32  
如果我猜的没有错的话,应该是udp[offset:截取个数]=nValue
eth.addr[0:3]==00:06:5B

例子:
判断upd下面那块数据包前三个是否等于0x20 0x21 0x22
我们都知道udp固定长度为8
udp[8:3]==20:21:22

判断tcp那块数据包前三个是否等于0x20 0x21 0x22
tcp
一般情况下,长度为20,但也有不是20的时候
tcp[8:3]==20:21:22
如果想得到最准确的,应该先知道tcp长度

matches(
匹配)contains(包含某字符串)语法
ip.src==192.168.1.107 and udp[8:5] matches "\\x02\\x12\\x21\\x00\\x22"
ip.src==192.168.1.107 and udp contains 02:12:21:00:22
ip.src==192.168.1.107 and tcp contains "GET"
udp contains 7c:7c:7d:7d
匹配payload中含有0x7c7c7d7dUDP数据包,不一定是从第一字节匹配。

例子:
得到本地qq登陆数据包(判断条件是第一个包==0x02,第四和第五个包等于0x00x22,最后一个包等于0x03)
0x02 xx xx 0x00 0x22 ... 0x03
正确
oicq and udp[8:] matches "^\\x02[\\x00-\\xff][\\x00-\\xff]\\x00\\x22[\\x00-\\xff]+\\x03$"
oicq and udp[8:] matches "^\\x02[\\x00-\\xff]{2}\\x00\\x22[\\x00-\\xff]+\\x03$" //
登陆包
oicq and (udp[8:] matches "^\\x02[\\x00-\\xff]{2}\\x03$" or tcp[8:] matches "^\\x02[\\x00-\\xff]{2}\\x03$")
oicq and (udp[8:] matches "^\\x02[\\x00-\\xff]{2}\\x00\\x22[\\x00-\\xff]+\\x03$" or tcp[20:] matches "^\\x02[\\x00-\\xff]{2}\\x00\\x22[\\x00-\\xff]+\\x03$")

不单单是00:22才有QQ号码,其它的包也有,要满足下面条件(tcp也有,但没有做):
oicq and udp[8:] matches "^\\x02[\\x00-\\xff]+\\x03$" and !(udp[11:2]==00:00) and !(udp[11:2]==00:80)
oicq and udp[8:] matches "^\\x02[\\x00-\\xff]+\\x03$" and !(udp[11:2]==00:00) and !(udp[15:4]==00:00:00:00)
说明:
udp[15:4]==00:00:00:00
表示QQ号码为空
udp[11:2]==00:00
表示命令编号为00:00
udp[11:2]==00:80
表示命令编号为00:80
当命令编号为00:80时,QQ号码为00:00:00:00

得到msn登陆成功账号(判断条件是"USR 7 OK ",即前三个等于USR,再通过两个0x20,就到OK,OK后面是一个字符0x20,后面就是mail)
USR xx OK mail@hotmail.com
正确
msnms and tcp and ip.addr==192.168.1.107 and tcp[20:] matches "^USR\\x20[\\x30-\\x39]+\\x20OK\\x20[\\x00-\\xff]+"

9.
dns
模式过滤
10.
DHCP
以寻找伪造DHCP服务器为例,介绍Wireshark的用法。在显示过滤器中加入过滤规则,
显示所有非来自DHCP服务器并且bootp.type==0x02Offer/Ack)的信息:
bootp.type==0x02 and not ip.src==192.168.1.1

11.
msn
msnms && tcp[23:1] == 20 //
第四个是0x20msn数据包
msnms && tcp[20:1] >= 41 && tcp[20:1] <= 5A && tcp[21:1] >= 41 && tcp[21:1] <= 5A && tcp[22:1] >= 41 && tcp[22:1] <= 5A
msnms && tcp[20:3]=="USR" //
找到命令编码是USR的数据包
msnms && tcp[20:3]=="MSG" //
找到命令编码是MSG的数据包
tcp.port == 1863 || tcp.port == 80

如何判断数据包是含有命令编码的MSN数据包?
1)
端口为1863或者80,:tcp.port == 1863 || tcp.port == 80
2)
数据这段前三个是大写字母,:
tcp[20:1] >= 41 && tcp[20:1] <= 5A && tcp[21:1] >= 41 && tcp[21:1] <= 5A && tcp[22:1] >= 41 && tcp[22:1] <= 5A
3)
第四个为0x20,:tcp[23:1] == 20
4)msn
是属于TCP协议的,tcp



路过

鸡蛋

鲜花

握手

雷人

评论 (0 个评论)

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 立即注册

站长邮箱|Archiver|51学通信 ( 粤ICP备11025688 )

GMT+8, 2024-5-7 12:35 , Processed in 0.013339 second(s), 14 queries .

Powered by Discuz! X2

© 2001-2011 Comsenz Inc.

回顶部