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
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
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
等等
排除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 // 偏移8個bytes,再取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中含有0x7c7c7d7d的UDP數據包,不一定是從第一字節匹配。
例子:
得到本地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模式過濾
dns
10.DHCP
以 尋找偽造DHCP服務器為例,介紹 Wireshark 的用法。在顯 示 過濾 器中加入 過 濾 規則,
顯示所有非來自DHCP服務器並且bootp.type==0x02(Offer/Ack)的信息:
bootp.type==0x02 and not ip.src==192.168.1.1
11.msn
msnms && tcp[23:1] == 20 // 第四個是0x20的msn數據包
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
MSN Messenger 協議分析
http://blog.csdn.net/Hopping/archive/2008/11/13/3292257.aspx
MSN 協議分析
http://blog.csdn.net/lzyzuixin/archive/2009/03/13/3986597.aspx
12 過濾域名
http.host == "baidu.com"
http.host contains baidu.com
更詳細的說明
<< wireshark 過 濾 表達式實例介紹>>
http://www.csna.cn/viewthread.php?tid=14614
參考:
https://blog.51cto.com/lansemouzi/1537095