t-tcpdump
文章目錄
- 寫入和讀取數(shù)據(jù)包
- 抓取數(shù)據(jù)包
- 抓取指定網(wǎng)卡流量
- 指定數(shù)據(jù)的輸出格式
- 數(shù)據(jù)包抓取的方向
- 輸出信息的詳細(xì)程度的可控選項(xiàng)
- 抓取指定協(xié)議的數(shù)據(jù)包
- 表達(dá)式介紹
- 邏輯連接符的使用
- type的確定
寫入和讀取數(shù)據(jù)包
在工作或者生活中的網(wǎng)絡(luò)故障排除時(shí)最有力的方式就是抓包分析網(wǎng)絡(luò)狀況,從而找到網(wǎng)絡(luò)故障的原因。所以將數(shù)據(jù)包保存到文件中,可以方便得進(jìn)行分析取證。
數(shù)據(jù)包的寫入命令
tcpdump -w test1.txt
數(shù)據(jù)包的讀取命令
tcpdump -r test1.txt
數(shù)據(jù)包的多個(gè)文件讀取
tcpdump -V pack.txt 其中pack.txt中包含多個(gè)數(shù)據(jù)包文件test1.txt,test2.text,test3.txt
抓取數(shù)據(jù)包
停止抓取數(shù)據(jù)包:
ctrl+c- 終止
tcpdump進(jìn)程 - 抓取指定數(shù)量的數(shù)據(jù)包
tcpdump -c 5
數(shù)據(jù)包的狀態(tài)
captured當(dāng)前tcpdump抓取的數(shù)據(jù)包個(gè)數(shù)received by filter系統(tǒng)接收的數(shù)據(jù)包,tcpdump不一定過濾所有通過系統(tǒng)的數(shù)據(jù)包,系統(tǒng)數(shù)據(jù)包多于tcpdump抓取的數(shù)據(jù)包dropped by filtertcpdump丟棄的數(shù)據(jù)包
抓取指定網(wǎng)卡流量
一臺(tái)網(wǎng)絡(luò)服務(wù)器可能有多個(gè)網(wǎng)卡連接不同的網(wǎng)絡(luò)(可能即連接交換機(jī),又連接路由器),對(duì)于分析不同的網(wǎng)絡(luò)狀態(tài),需要針對(duì)指定的網(wǎng)卡進(jìn)行分析
- 查看網(wǎng)卡
tcpdum -D
其中標(biāo)記為up的為可以抓取的網(wǎng)卡root@ubuntu:/home/zhanghuigui/Desktop/tcpdum# tcpdump -D 1.ens33 [Up, Running] 2.any (Pseudo-device that captures on all interfaces) [Up, Running] 3.lo [Up, Running, Loopback] 4.bluetooth0 (Bluetooth adapter number 0) 5.nflog (Linux netfilter log (NFLOG) interface) 6.nfqueue (Linux netfilter queue (NFQUEUE) interface) 7.usbmon1 (USB bus number 1) 8.usbmon2 (USB bus number 2)
或者使用ifconfig -a獲取網(wǎng)卡信息 - 指定網(wǎng)卡的數(shù)據(jù)流量的抓取
tcpdum -i ens33即可
指定數(shù)據(jù)的輸出格式
-
默認(rèn)情況下輸出域名,而非ip地址和端口
tcpdum以及tcpdum host比如嘗試訪問百度的公共域名服務(wù)器,則只會(huì)看到抓取的數(shù)據(jù)包中包好域名信息,并未有ip地址和端口號(hào)
-
抓取的數(shù)據(jù)包中格式包含對(duì)應(yīng)主機(jī)的ip和端口號(hào)
tcpdum -n或者tcpdump host 180.76.76.76 -n
可以看到如下圖中將原來(lái)的"域名+服務(wù)"轉(zhuǎn)換為 “ip + 端口”,如public-dns-a.baidu.com.http轉(zhuǎn)換為180.76.76.76.80
數(shù)據(jù)包抓取的方向
- 抓取從目標(biāo)ip流入當(dāng)前設(shè)備的數(shù)據(jù)包 使用
-Q參數(shù),或者--direction參數(shù)也可以
tcpdum host 180.76.76.76 -n -Q in
- 抓取從當(dāng)前設(shè)備流入目標(biāo)ip的數(shù)據(jù)包
tcpdump host 180.76.76.76 -n -Q out - 抓取從當(dāng)前設(shè)備的指定網(wǎng)卡 流入目標(biāo)ip的數(shù)據(jù)包
tcpdump host 180.76.76.76 -n -Q out -i ens33
輸出信息的詳細(xì)程度的可控選項(xiàng)
- 輸出鏈路層的mac地址通信信息
tcpdump host 180.76.76.76 -n -e
- 快速打印見面信息
tcpdump host 180.76.76.76 -n -q
- 更加詳細(xì)得打印數(shù)據(jù)內(nèi)容
以16進(jìn)制形式打印,并用ascsII碼輸出打印的內(nèi)容
tcpdump host 180.76.76.76 -n -X
更加詳細(xì)的打印使用命令
tcpdump host 180.76.76.76 -n -XX - 抓取過程中抓取相信信息并輸出
tcpdump host 180.76.76.76 -n -v或者tcpdump host 180.76.76.76 -n -vv或者tcpdump host 180.76.76.76 -n -vvv;-v的個(gè)數(shù)越多,則打印的信息越相信
抓取指定協(xié)議的數(shù)據(jù)包
tcpdump icmp -n -v 僅抓取服務(wù)器接收到的 icmp協(xié)議的數(shù)據(jù)包
表達(dá)式介紹
表達(dá)式可以用來(lái)篩選想要的數(shù)據(jù)包內(nèi)容,使用man pcap-filter包含過濾器的過濾規(guī)則和語(yǔ)法
tcpdump的表達(dá)式使用規(guī)則如下:
tcpdump [option] [not] proto dir type
其中
option是可選項(xiàng),代表子命令-Q/-v/-n/-e/-cnot可選項(xiàng),表示取反,即表示抓取不符合not之后寫的過濾規(guī)則的數(shù)據(jù)包proto是必選項(xiàng),表示支持的協(xié)議tcp/udp/arp/ip/icmp等dir是流入流出控制,src/dst/src and dst/src or dsttype是篩選特定的ip和端口host/net/port/portrange指定的ip,端口號(hào),端口范圍篩選
邏輯連接符的使用
tcpdump -n -v dst 180.76.76.76 and tcp 抓取發(fā)送終點(diǎn)為180.76.76.76服務(wù)器且協(xié)議為tcp的數(shù)據(jù)包
type的確定
常用的type為:host/port/portrange
tcpdump -q -n host 180.76.76.76 抓取type是host,ip地址為180.76.76.76的數(shù)據(jù)包
tcpdump -n -v host 180.76.76.76 and port 80 抓取ip地址為180.76.76.76端口為80的數(shù)據(jù)包
tcpdump -n -v net 180.76 and port 80 抓取范圍為180.76.0.0 - 180.76.255.255,端口為80的數(shù)據(jù)包
tcpdump -n -v dst port 80 篩選目標(biāo)端口為80端口的數(shù)據(jù)包
tcpdump -n -v dst port 80 and dst net 180.76篩選目標(biāo)端口為80,網(wǎng)段為180.76.0.0-180.76.255.255范圍的數(shù)據(jù)包
總結(jié)
- 上一篇: 微信好听的个性签名女
- 下一篇: 老式十几年前没有前加力四不像拖拉机车值多