Linux之tcpdump
出處:https://blog.csdn.net/Jerry_1126/article/details/73732727
tcpdump命令-->用來(lái)將網(wǎng)絡(luò)中傳送的數(shù)據(jù)包的"頭"完全截獲下來(lái)提供分析,常見(jiàn)的有Wireshark
【命令作用】
該命令支持針對(duì)網(wǎng)絡(luò)層、協(xié)議、主機(jī)、網(wǎng)絡(luò)或端口的過(guò)濾,并提供and、or、not等邏輯語(yǔ)句來(lái)幫助你去掉無(wú)用的信息。tcpdump就是一種免費(fèi)的網(wǎng)絡(luò)分析工具,尤其其提供了源代碼,公開了接口,因此具備很強(qiáng)的可擴(kuò)展性,對(duì)于網(wǎng)絡(luò)維護(hù)和入侵者都是非常有用的工具。tcpdump存在于基本的FreeBSD系統(tǒng)中,由于它需要將網(wǎng)絡(luò)界面設(shè)置為混雜模式,普通用戶不能正常執(zhí)行,但具備root權(quán)限的用戶可以直接執(zhí)行它來(lái)獲取網(wǎng)絡(luò)上的信息。因此系統(tǒng)中存在網(wǎng)絡(luò)分析工具主要不是對(duì)本機(jī)安全的威脅,而是對(duì)網(wǎng)絡(luò)上的其他計(jì)算機(jī)的安全存在威脅。經(jīng)典的系統(tǒng)管理員分析工具!
【常用關(guān)鍵字】
tcpdump命令中幾種關(guān)鍵字:
第一種:類型關(guān)鍵字,包括:host,net,port
第二種:傳輸方向關(guān)鍵字,包括:src,dst ?
第三種:協(xié)議關(guān)鍵字,包括: ip,arp,tcp,udp等類型 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
第四種:其他關(guān)鍵字,包括:gateway,broadcast,less,greater,not,!,and,&&,or,||
【備注說(shuō)明】
1) 抓取回環(huán)網(wǎng)口的包: ? ? ? ?$ tcpdump -i lo
2) 防止包截?cái)嗟姆椒?#xff1a; ? ? ? ?$ tcpdump -s 0
3) 以數(shù)字顯示主機(jī)及端口: ? ?$ tcpdump -n
【命令詳解】
$ tcpdump tcp -i eth1 -t -s0 -c 100 and dst port ! 22 and src net 192.168.1.0/24 -w ./target.cap
1)tcp: ? ? ? ? ? ? ? ? ? ? #?ip,icmp,arp,rarp,udp這些選項(xiàng)要放第一個(gè)參數(shù),用來(lái)過(guò)濾數(shù)據(jù)報(bào)的類型
2)-i eth1 ? ? ? ? ? ? ? ? ?# 只抓經(jīng)過(guò)網(wǎng)口eth1的包
3)-t ? ? ? ? ? ? ? ? ? ? ? # 不顯示時(shí)間戳
4)-s 0 ? ? ? ? ? ? ? ? ? ? # 抓取數(shù)據(jù)包時(shí)默認(rèn)抓取長(zhǎng)度為68字節(jié)。加上-s 0 后可以抓到完整的數(shù)據(jù)包
5)-c 100 ? ? ? ? ? ? ? ? ? # 只抓取100個(gè)數(shù)據(jù)包
6)dst port ! 22 ? ? ? ? ? ?# 不抓取目標(biāo)端口是22的數(shù)據(jù)包
7)src net 192.168.1.0/24 ? # 數(shù)據(jù)包的源網(wǎng)絡(luò)地址為192.168.1.0/24
8)-w ./target.cap ? ? ? ? ?# 保存成cap文件,方便用wireshark工具進(jìn)行分析
【其他命令】
$ tcpdump host 192.168.0.1 and /(192.168.0.2 or 192.168.0.3 /) ?#?截取主機(jī)1與主機(jī)2或3之間的通信包
$ tcpdump ip host 192.168.0.1 and ! 192.168.0.2 ? ? ? ? #?截取主機(jī)1除了和主機(jī)2之外所有主機(jī)通信的ip包
$ tcpdump tcp port 23 host 210.27.48.1 ? ? ? ? ? ? ? ? ?#?截取主機(jī)192.168.0.1接收或發(fā)出的telnet包
$ tcpdump -i eth0 host ! 192.168.0.1 and ! 192.168.0.2 and dst port 80 #?截獲除了主機(jī)1、2外訪問(wèn)本機(jī)http端口的數(shù)據(jù)包:
總結(jié)
以上是生活随笔為你收集整理的Linux之tcpdump的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Linux之文件查找命令
- 下一篇: linux 其他常用命令