wireshark基本用法及過慮規則

jopen 9年前發布 | 16K 次閱讀 網絡工具包 Wireshark

Wireshark 基本語法,基本使用方法,及包過慮規則:

1.過濾IP,如來源IP或者目標IP等于某個IP

<DIV style=></div>

例子:

ip.src eq 192.168.1.107 or ip.dst eq 192.168.1.107

或者

ip.addr eq 192.168.1.107 // 都能顯示來源IP和目標IP


<P style=>linux上運行的wireshark圖形窗口截圖示例,其他過慮規則操作類似,不再截圖。 </p>

<P style=>ip.src eq 10.175.168.182 </p>

<P style=>截圖示例:
</span></p>

<P style=> </p>

<P style=>提示: 在Filter編輯框中,收入過慮規則時,如果語法有誤,框會顯紅色,如正確,會是綠色。 </p>

<P style=>
</p>

<DIV style=></div> </div>

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

<P style=>udp.port eq 15000 </p>

<DIV style=>過濾端口范圍 </div> <DIV style=>tcp.port >= 1 and tcp.port <= 80 </div>

<DIV style=>
</div>

<DIV style=></div> </div>

3.過濾協議

例子:

tcp

udp

arp

icmp

http

smtp

ftp

dns

msnms

ip

ssl

oicq

bootp

等等

<P style=>排除arp包,如!arp   或者   not arp </p>

<P style=>
</p>

<DIV style=></div> </div>

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的

<DIV style=>less than 小于 < lt  </div> <DIV style=>小于等于 le </div>

<DIV style=>等于 eq </div> <DIV style=>大于 gt </div>

<DIV style=>大于等于 ge </div>

<DIV style=>不等 ne </div>

<DIV style=>
</div>

<DIV style=></div> </div>

5.包長度過濾

例子:

udp.length == 26 這個長度是指udp本身固定長度8加上udp下面那塊數據包之和

tcp.len >= 7   指的是ip數據包(tcp下面那塊數據),不包括tcp本身

ip.len == 94 除了以太網頭固定長度14,其它都算是ip.len,即從ip本身到最后

frame.len == 119 整個數據包長度,從eth開始到最后

<P style=>eth —> ip or arp —> tcp or udp —> data </p>

<P style=>
</p>

<DIV style=></div> </div>

6.http模式過濾

<DIV style=></div>

例子:

http.request.method == “GET”

http.request.method == “POST”

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

http contains “GET”

http contains “HTTP/1.”

<DIV style=>// GET包 </div> <DIV style=>http.request.method == “GET” && http contains “Host: “ </div>

<DIV style=>http.request.method == “GET” && http contains “User-Agent: “ </div>

<DIV style=>// POST包 </div>

<DIV style=>http.request.method == “POST” && http contains “Host: “ </div>

<DIV style=>http.request.method == “POST” && http contains “User-Agent: “ </div>

<DIV style=>// 響應包 </div>

<DIV style=>http contains “HTTP/1.1 200 OK” && http contains “Content-Type: “ </div>

<DIV style=>http contains “HTTP/1.0 200 OK” && http contains “Content-Type: “ </div>

<DIV style=>一定包含如下 </div>

<DIV style=>Content-Type: </div>

<DIV style=>
</div>

7.TCP參數過濾

<DIV style=></div> </div>

<DIV style=></div>

tcp.flags 顯示包含TCP標志的封包。

tcp.flags.syn == 0x02     顯示包含TCP SYN標志的封包。

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


8.包內容過濾

<DIV style=></div> </div>

<DIV style=></div> <DIV style=>-----------------------------------------------</span> </div>

<DIV style=>tcp[20]表示從20開始,取1個字符 </div>

tcp[20:]表示從20開始,取1個字符以上

<DIV style=>

注: 些兩虛線中的內容在我的wireshark(linux)上測試未通過。

--------------------------------------------------
     </div>

tcp[20:8]表示從20開始,取8個字符

tcp[offset,n]

<DIV style=>udp[8:3]==81:60:03 // 偏移8個bytes,再取3個數,是否與==后面的數據相等? </div> <DIV style=>udp[8:1]==32   如果我猜的沒有錯的話,應該是udp[offset:截取個數]=nValue </div>

<DIV style=>eth.addr[0:3]==00:06:5B </div>

<DIV style=>例子: </div> <DIV style=>判斷upd下面那塊數據包前三個是否等于0x20 0x21 0x22 </div>

<DIV style=>我們都知道udp固定長度為8 </div>

<DIV style=>udp[8:3]==20:21:22 </div>

<DIV style=>判斷tcp那塊數據包前三個是否等于0x20 0x21 0x22 </div> <DIV style=>tcp一般情況下,長度為20,但也有不是20的時候 </div>

<DIV style=>tcp[8:3]==20:21:22 </div>

<DIV style=>如果想得到最準確的,應該先知道tcp長度 </div>

<DIV style=>matches(匹配)和contains(包含某字符串)語法</span></span> </div> <DIV style=>ip.src==192.168.1.107 and udp[8:5] matches “\\x02\\x12\\x21\\x00\\x22″        ------???--------</span> </div>

<DIV style=>ip.src==192.168.1.107 and udp contains 02:12:21:00:22</span> </div>

ip.src==192.168.1.107 and tcp contains “GET”

<DIV style=>udp contains 7c:7c:7d:7d 匹配payload中含有0x7c7c7d7d的UDP數據包,不一定是從第一字節匹配。</span> </div>

<DIV style=>
</div>

<DIV style=>-------------------------------------- 不理解 Begin------------------------------------------------------------------------------------ </div>

<DIV style=>例子: </div>

得到本地qq登陸數據包(判斷條件是第一個包==0x02,第四和第五個包等于0x00x22,最后一個包等于0x03)

<DIV style=>0x02 xx xx 0x00 0x22 … 0x03</span> </div>

<DIV style=>如何拼寫過慮條件??? </div>

    
<DIV style=>udp[11:2]==00:00 表示命令編號為00:00 </div>

<DIV style=>udp[11:2]==00:80 表示命令編號為00:80 </div>

<DIV style=>當命令編號為00:80時,QQ號碼為00:00:00:00 </div>

<DIV style=>得到msn登陸成功賬號(判斷條件是”USR 7 OK “,即前三個等于USR,再通過兩個0x20,就到OK,OK后面是一個字符0x20,后面就是mail了) </div> <DIV style=>USR xx OK mail@hotmail.com </div>

<DIV style=>正確 </div>

<DIV style=>msnms and tcp and ip.addr==192.168.1.107 and tcp[20:] matches “^USR\\x20[\\x30-\\x39]+\\x20OK\\x20[\\x00-\\xff]+” </div>

<DIV style=>

-------------------------------------不理解End---------------------------------------------------------------------------------------


</div>

<DIV style=></div> </div>

9.dns模式過濾

<DIV style=></div> <DIV style=>
</span></div>

<DIV style=></div> </div>

10.DHCP

<DIV style=></div> <DIV style=>注意:DHCP協議的檢索規則不是dhcp/DHCP, 而是bootp</span> </div>

以尋找偽造DHCP服務器為例,介紹Wireshark的用法。在顯示過濾器中加入過濾規則,

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

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


<DIV style=></div> </div>

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 協議分析



更詳細的說明
<<wireshark過濾表達式實例介紹>>
http://www.csna.cn/viewthread.php?tid=14614



Wireshark 主界面的操作菜單中英對比
http://www.csna.cn/viewthread.php?tid=9645&extra=page=1

12. wireshark字符串過慮語法字符

如下內容轉自:http://www.csna.cn/viewthread.php?tid=14614

類似正則表達式的規則。

 1、wireshark基本的語法字符


\d          0-9的數字
\D          \d的補集(以所以字符為全集,下同),即所有非數字的字符
\w          單詞字符,指大小寫字母、0-9的數字、下劃線
\W          \w的補集
\s          空白字符,包括換行符\n、回車符\r、制表符\t、垂直制表符\v、換頁符\f
\S          \s的補集
.          除換行符\n外的任意字符。 在Perl中,“.”可以匹配新行符的模式被稱作“單行模式”
.*       匹配任意文本,不包括回車(\n)? 。 而,[0x00-0xff]*        匹配任意文本,包括\n
[…]          匹配[]內所列出的所有字符
[^…]          匹配非[]內所列出的字符



—————————————————————————————-
2、定位字符  所代表的是一個虛的字符,它代表一個位置,你也可以直觀地認為“定位字符”所代表的是某個字符與字符間的那個微小間隙。



^          表示其后的字符必須位于字符串的開始處
$          表示其前面的字符必須位于字符串的結束處
\b          匹配一個單詞的邊界
\B          匹配一個非單詞的邊界



—————————————————————————————-
3、重復描述字符



{n}          匹配前面的字符n次
{n,}          匹配前面的字符n次或多于n次
{n,m}          匹配前面的字符n到m次
?          匹配前面的字符0或1次
+          匹配前面的字符1次或多于1次
*          匹配前面的字符0次或式于0次



—————————————————————————————-
4、and or 匹配



and 符號 并
or  符號 或
例如:
tcp and tcp.port==80
tcp or udp



—————————————————————————————-
5、wireshark過濾匹配表達式實例



5.1、搜索按條件過濾udp的數據段payload(數字8是表示udp頭部有8個字節,數據部分從第9個字節開始udp[8:])
udp[8]==14        (14是十六進制0x14)匹配payload第一個字節0x14的UDP數據包
udp[8:2]==14:05 可以udp[8:2]==1405,且只支持2個字節連續,三個以上須使用冒號:分隔表示十六進制。 (相當于 udp[8]==14 and udp[9]==05,1405是0x1405)
udp[8:3]==22:00:f7 但是不可以udp[8:3]==2200f7
udp[8:4]==00:04:00:2a,匹配payload的前4個字節0x0004002a
而udp contains 7c:7c:7d:7d 匹配payload中含有0x7c7c7d7d的UDP數據包,不一定是從第一字節匹配。
udp[8:4] matches “\\x14\\x05\\x07\\x18″
udp[8:] matches “^\\x14\\x05\\x07\\x18\\x14″



5.2、搜索按條件過濾tcp的數據段payload(數字20是表示tcp頭部有20個字節,數據部分從第21個字節開始tcp[20:])
tcp[20:] matches “^GET [ -~]*HTTP/1.1\\x0d\\x0a”
等同http matches “^GET [ -~]*HTTP/1.1\\x0d\\x0a”



tcp[20:] matches “^GET (.*?)HTTP/1.1\\x0d\\x0a”
tcp[20:] matches “^GET (.*?)HTTP/1.1\\x0d\\x0a[\\x00-\\xff]*Host: (.*?)pplive(.*?)\\x0d\\x0a”
tcp[20:] matches “^GET (.*?)HTTP/1.1\\x0d\\x0a[\\x00-\\xff]*Host: “
tcp[20:] matches “^POST / HTTP/1.1\\x0d\\x0a[\\x00-\\xff]*\\x0d\\x0aConnection: Keep-Alive\\x0d\\x0a\\x0d\\x0a”



檢測SMB頭的smb標記,指明smb標記從tcp頭部第24byte的位置開始匹配。
tcp[24:4] == ff:53:4d:42



檢測SMB頭的smb標記,tcp的數據包含十六進制ff:53:4d:42,從tcp頭部開始搜索此數據。
tcp contains ff:53:4d:42
tcp matches “\\xff\\x53\\x4d\\x42″



檢測tcp含有十六進制01:bd,從tcp頭部開始搜索此數據。
tcp matches “\\x01\\xbd”



檢測MS08067的RPC請求路徑
tcp[179:13] == 00:5c:00:2e:00:2e:00:5c:00:2e:00:2e:00
                  \      .     .     \     .     .
5.3、其他
http.request.uri matches “.gif$” 匹配過濾HTTP的請求URI中含有”.gif”字符串,并且以.gif結尾(4個字節)的http請求數據包($是正則表達式中的結尾表示符)
注意區別:http.request.uri contains “.gif$” 與此不同,contains是包含字符串”.gif$”(5個字節)。匹配過濾HTTP的請求URI中含有”.gif$”字符串的http請求數據包(這里$是字符,不是結尾符)


eth.addr[0:3]==00:1e:4f 搜索過濾MAC地址前3個字節是0x001e4f的數據包。

來自:http://blog.csdn.net/hzhsan/article/details/43453251

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!