簡單使用 tcpdump GNU Linux 範例

man tcpdump

https://my.oschina.net/chuangpoyao/blog/60901

 

------------------------------------------------------------------------------------------------------

全文來至 managing security with snort and ids tools, Cox & Gerg

目前尚不懂作者提出不要在本機使用,應 ssh 到另一臺機使用,應會一直收到本機 terminal 的信息???

作者強力要求暸解 tcp/ip header 包頭


精密讀通信

tcpdump -v

以十六進制顯示

tcpdump -x

作者建議不要直接讀,應寫出記錄檔

寫出記錄檔,可後再用 wireshark 讀

tcpdump -w /tmp/差刹诧.out

tcpdump -r /tmp/插茶诧.out

使用 tcpdump 記錄過濾條件

tcpdump -F /home/tmd/tcp.filter

不要轉换 ip 地址成名稱

tcpdump -n

不要轉换 ip 地址,協議,端口成名稱

tcpdump -nn

不要轉换 ip 地址,只顯示 mac 位址

tcpdump -e

只抓 100 個包

tcpdump -c 100

限制捕包長度

tcpdump -s 1500

不捕端口 22 或 ssh

tcpdump -r /tmp/tcpdump.out not port ssh

作者強力要求暸解 tcp/ip header 包頭,有利用於過濾條件

只捕特定 ip 位址,且不捕端口 22 或 ssh

tcpdump -r /tmp/tcpdump.out host 192.168.10.5 and not port ssh

只捕特定 ip 位址,特定端口,不轉换 ip 地址

tcpdump -r /tmp/tcpdump.out -n host 192.168.10.5 and port 80

只捕兩 ip 地址的通信

tcpdump -r /tmp/tcpdump.out host 192.168.10.5 and host 192.168.10.10

---------------------------------------------------------------------------------------------

 

全文來至 Ethereal Packet Sniffing,Orebaugh

指定 IPv4 位置

tcpdump host 12.34.56.刹叉诧 

指定 IPv6 位置

tcpdump host 2::8100:2:301:c392:fc5a

指定主機名稱或域名系統

tcpdump host gnu-linux-debian
tcpdump host www.oschina.net

指定信息源

tcpdump host src 192.168.1.1
或可免 host
tcpdump src 192.168.1.1

指定目地源

tcpdump dst host 192.168.1.1
或可免 host
tcpdump dst 192.168.1.1

無類别域間路由

tcpdump src net 192.168.100.0/24

指定 MAC 地址

tcpdump ether host ff:ff:ff:ff:ff:ff

tcpdump ether dst host ff:ff:ff:ff:ff:ff

tcpdump ether dst ff:ff:ff:ff:ff:ff
tcpdump ether src host 00:f9:06:aa:01:03

tcpdump ether src 00:f9:06:aa:01:03

指定端口

tcpdump port 80

指定協議和端口

tcpdump tcp port 80

如果 http 有解識在 /etc/services

tcpdump port http

嗅探 UDP 要求 DNS 服務器

tcpdump udp dst port 53

嗅探 DNS 服務器 的 UDP 回應

tcpdump udp src port 53

除端口 53

tcpdump not port 53

www.oschina.net 的 telenet 端口

tcpdump host www.oschina.net and port telnet

端口 telnet 或 端口 ssh

tcpdump port telnet or port ssh

開源中國的端口 telent 或 開源中國的端口 ssh

tcpdump host www.oschina.net and ( port telnet or port ssh )

開源中國的端口 telent 或 端口 ssh

tcpdump host www.oschina.net and port telnet or port ssh

除協議 IPX

tcpdump not ipx

有些協議有在包裡告知加載協議,IP 在 /etc/protocols 有表明

tcpdump ip proto 6
有如
tcpdump tcp

指定 ICMPv4 type,[0]為第一個 byte,ICMP 是 Type

tcpdump 'icmp[0] == 8' # ping request

tcpdump 'icmp[0] == 0' # ping replies 

指定 ICMPv4 type,關鍵字

tcpdump 'icmp[icmptype] == icmp-echo'

tcpdump 'icmp[icmptype] == icmp-echoreply'

只有 TCP SYN 旗

tcpdump 'tcp[tcpflag] == 0x02'

tcpdump 'tcp[tcpflag] == tcp-syn'

只要有 TCP SYN 旗

tcpdump tcp[tcpflag] & 'tcp-syn == 0x02'

tcpdump tcp[tcpflag] & 'tcp-syn == tcp-syn'

小於 100 bytes

tcpdump 'len < 100'

IP 包大於 255 個 octets,IP 第二個兩個 byte 是 Total Length???

tcpdump 'ip[2:2] > 0xff'

 

不限長度捕抓封包寫至 capture_all 檔

tcpdump -s 0 -w capture

不限長度捕抓 ICMPv4 封包寫至 icmp_capture 檔

tcpdump -s 0 -w icmp_capture ip proto \\icmp

不限長度捕抓目地 192.168.1.1 TCP 端口二十一封包寫至 ftp_capture 檔

tcpdump -s 0 0w ftp_capture 'dst host 192.168.1.1 && tcp port 21'

不限長度捕抓 TCP 封包超精密以十六進制,ASCII 寫至 tcp_capture 檔

tcpdump -vvv -X -s 0 -w tcp_capture ip[9]=6

讀取 etheral_capture 檔並顯示

tcpdump -r ethereal_capture

 

TCPDUMP 只捉前六十八字節

 

你可能感兴趣的:(linux,tcpdump,gnu,snort,tshark)