天天看點

tcpdump的使用#yyds幹貨盤點#

(一)tcpdump的安裝:

(1) yum -y install tcpdump

(二)tcpdump的參數介紹:

(1)參數幫助:

①i:接口資訊

②port:隻捕捉80端口

③v:顯示詳細資訊,2個vv顯示更詳細的資訊,vvv就詳細的不得了

④w:儲存為檔案

Usage: tcpdump [-aAbdDefhHIJKlLnNOpqStuUvxX#] [ -B size ] [ -c count ]

               [ -C file_size ] [ -E algo:secret ] [ -F file ] [ -G seconds ]

               [ -i interface ] [ -j tstamptype ] [ -M secret ] [ --number ]

               [ -Q|-P in|out|inout ]

               [ -r file ] [ -s snaplen ] [ --time-stamp-precision precision ]

               [ --immediate-mode ] [ -T type ] [ --version ] [ -V file ]

               [ -w file ] [ -W filecount ] [ -y datalinktype ] [ -z postrotate-command ]

               [ -Z user ] [ expression ]

(三)抓包示範:

(1)普通捕獲:

①tcpdump -i eth0 -s 0 -w file.pcap   //捕獲網卡eth0的,儲存大包的大小為(68位元組),0就是預設的為68位元組

②tcpdump  -i eth0  port 22          //捕獲網卡為eth0并且端口為22的資料包

(2)關鍵字比如host,port:

① tcpdump  host 10.54.67.7    //捕獲10.54.67.7的所有資料通信

②tcpdump  net  192.168.1.0/24  //捕獲該網段的所有資料

③tcpdump  -nn host 192.168.1.2 and '(192.168.1.3 or 192.168.116.150)'  //捕獲主機某個位址和某幾個個位址段之間的通信

④tcpdump -nn host 192.168.1.2 and !  192.168.1.3  /捕獲主機192.168.1.2和192.168.1.3通信的資料

⑤tcpdump host 192.168.1.2 and port //捕獲主機192.168.1.2的端口80收到和發出的資料

(3)傳輸方向關鍵字的捕獲,主要有src,dst,dst or src,dst and src,這些關鍵字指明了傳輸的方向,預設了src和dst:

①tcpdump -nn src 192.168.1.2 and dst 192.168.1.3   //捕獲源為192.168.1.2目标為192.168.1.3之間的資料包

②tcpdump -nn src 192.168.1.2 and src port  80 and dst  192.168.1.3 and dst  port 22 //捕獲源為192.168.1.2端口為80,并且目标為192.168.1.3的22端口的資料

(4)協定關鍵字:主要是包括ip,arp,tcp,udp,icmp等類型

①tcpdump  -nn host  192.168.1.2 and port 22 and tcp  //捕獲源為192.168.1.2端口為22并且協定為tcp

②tcpdump -i eth0  -s 1400 -nn host 192.168.1.2  and ! 192.168.1.3 and icmp -e //捕獲網口為eth0上192.168.1.2和192.168.1.3外的其他主機之間的icmp封包

(四)讀取抓封包件:

①tcpdump  -r file.pcap     //-r是讀取的意思

②tcpdump -n src host 192.168.1.2  -r file.pcap //隻顯示源為192.168.1.2的主機的