linux下的抓包工具tcpdump

來源:互聯網
上載者:User

linux下的抓包工具tcpdump
 
 
這篇講linux下的抓包工具。
 
抓包工具比較好用的有兩個,一個是snort,一個是tcpdump,這次不說snort了,覺得這個工具雖然很強大,但是比較複雜,還是tcpdump比較簡單。tcpdump windows、linux版本均有。linux版本可以在以下網站下載:www.tcpdump.org.
 
安裝好tcpdump之後,運行tcpdump:
 
1. tcpdump -D 擷取網路介面卡列表,以下是在windows上擷取到的結果:
 
1.\Device\PssdkLoopback (PSSDK Loopback Ethernet Emulation Adapter)
2.\Device\{CF587901-C85F-4FD6-896F-D977DEFE76EC} (Intel(R) PRO/100 VE Network Co
nnection)
 
 
 
 
2. tcpdump -i <需要監控的網路介面卡編號>,例如我想監控lo(127.0.0.1),即上面列表中的1.\Device\PssdkLoopback: (windows上特有的,linux不適用)
 
tcpdump -i 1
 
 
 
 
如果不使用-i來定義監控適配器的話,預設使用列表中的第一個;
 
3. 監控主機為192.9.200.59上8000連接埠的tcp協議:
 
tcpdump host 192.9.200.59 and tcp port 8000
 
 
 
 
4. 如果想要顯示資料包的內容,需要使用-X參數,如,我想要顯示捕獲的http資料包http header的內容:
 
tcpdump -X host 192.9.200.59 and tcp port 8000
 
 
 
 
顯示結果如下:
 
22:13:19.717472 IP testhost59.12535 > liujuan59.8000: . 1:330(329) ack 1 win 327
8
0x0000: 4500 0171 e616 0000 8006 cb2b 0000 0000 E..q.......+....
0x0010: c009 c83b 30f7 1f40 0000 0002 0000 0002 ...;0..@........
0x0020: 5010 8000 b066 0000 504f 5354 202f 2048 P....f..POST./.H
0x0030: 5454 502f 312e 310d 0a43 6f6e 7465 6e74 TTP/1.1..Content
0x0040: 2d54 7970 653a 2074 6578 742f 786d 6c3b -Type:.text/xml;
0x0050: 2063 .c
 
 
 
 
可以看到該結果只顯示了http頭的一部分,沒有顯示全,是因為tcpdump預設將顯示的資料長度截斷了,可以使用-s後面加資料長度,來設定資料顯示長度:
 
tcpdump -X -s 0 host 192.9.200.59 and tcp port 8000
 
 
 
 
以上的例子中,-s 0 表示自動化佈建長度使其能夠顯示所有資料。
 
5. 捕獲的資料太多,不斷刷屏,可能需要將資料內容記錄到檔案裡,需要使用-w參數:
 
tcpdump -X -s 0 -w aaa host 192.9.200.59 and tcp port 8000
 
 
 
 
則將之前顯示在螢幕中的內容,寫入tcpdump可執行檔同級目錄下的aaa檔案中。
 
檔案查看方式如下,需要使用-r參數:
 
tcpdump -X -s 0 -r aaa host 192.9.200.59 and tcp port 8000
 
 
 
 
如果這樣寫:
 
tcpdump -r aaa
 
 
 
 
則只能看到最簡單的資料轉送互動過程,看不到資料包內容,查看時也需要使用相應的參數。
 
6.總結
 
總結一下,tcpdump的參數分兩個部分,選項(Options)和運算式(expression):
 
tcpdump[-adeflnNOpqRStuvxX] [-ccount]
[-Cfile_size] [-Ffile]
[-iinterface] [-mmodule] [-rfile]
[-ssnaplen] [-Ttype] [-wfile]
[-Ealgo:secret] [expression]
 
 摘自 fallenleaves

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.