+
Wireshark使用WinPcap作为接口,直接与网卡进行数据报文交换。Wireshark的使用环境大致分为两种,一种是电脑直连互联网的单机环境,另一种是连接交换机的互联网环境,也就是应用比较多的情况。
常用语法
2.1. 过滤IP
ip.src == 192.168.106.141 or ip.dst == 192.168.106.77
ip.addr == 192.0.2.1 and tcp.port not in {80, 25}
not ip.src == 192.168.106.141
在Filter编辑框中,输入过滤规则时,如果语法有误,框会显红色,如正确,会是绿色。
2.2. 过滤端口
tcp.port == 80 // 不管端口是来源的还是目标的都显示
tcp.dstport == 80 // 只显tcp协议的目标端口80
tcp.srcport == 80 // 只显tcp协议的来源端口80
tcp.port >= 1 and tcp.port <= 80
ip.addr == 192.168.106.77 and tcp.port == 80
2.3. 过滤协议
tcp, udp, arp, icmp, http, smtp, ftp, dns, msnms, ip, ssl, oicq, bootp
2.4. 过滤MAC地址
eth.dst == A0:00:00:04:C5:84 // 过滤目标MAC
eth.src == A0:00:00:04:C5:84 // 过滤来源MAC
eth.addr == A0:00:00:04:C5:84 // 过滤来源和目标MAC都等于A0:00:00:04:C5:84的
2.5. 包长度过滤
udp.length == 26 // 这个长度是指UDP本身固定长度8加上UDP下面那块数据包之和
tcp.len >= 7 // 指的是IP数据包(tcp下面那块数据),不包括tcp本身
ip.len == 94 // 除了以太网头固定长度14,其余都算是ip.len,即从ip本身到最后
frame.len == 119 // 整个数据包长度,从eth开始到最后
2.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: "
这些修正保持了原始意图的同时,清理了一些格式和语法错误,确保更准确地反映Wireshark的过滤语法。