顯示具有 抓封包 標籤的文章。 顯示所有文章
顯示具有 抓封包 標籤的文章。 顯示所有文章

2010年5月19日

Cisco switch port mirror (2924 / 3750) 實作方式

----- Cisco 3750 -----
情境:將 f0/5 port mirror 到 f0/6

en
conf t
monitor session 1 source int f0/5
monitor session 1 destination int f0/6


上面的 1 為 session 代號,可為 1 - 66

查看 mirror 狀態
sh monitor session 1

----- Cisco 2924 -----
情境 : 將 f0/5 port mirror 到 f0/6 (直接進入 destination port, 再把要偵測的 port 流量導入)

en
conf t
int f0/6
port monitor f0/5


查看 mirror 狀態
sh port monitor

P.S 以上均可設定多 port mirror 至同一個 destination port, 也可設定單 port mirror 到多個 destination

這樣就可以把有安裝抓封包軟體的電腦接在 switch 的 destination port 上來 monitor source port 的狀態了,利用 Linux 文字模式抓封包程序可參照 Linux 環境下,利用Wireshark或Tcpdump擷取封包

2009年2月18日

Linux 環境下,利用Wireshark或Tcpdump擷取封包

在這邊我們利用 Wireshark 跟 Tcpdump 兩種方式來抓封包,觀看問題

法1: 使用 Wireshark的文字版 tshark

語法 tshark -i -f
Ex. 抓預設 eth0 的 80 Port 的封包
# tshark -i eth0 -f "tcp port 80"

Ex. 看 eth1 並標準化時間,然後只抓有關於 203.67.21.33 並儲存在 /tmp/test.pcap ,同時也即時show在螢幕上
# tshark -i eth1 -t ad host 203.67.21.33 -w /tmp/test.cap -S

Ex. 讀取封包
#tshark -r /tmp/test.cap

Ex. 讀取並過濾封包,只要看 sip 號碼是 070123456 的並存檔為 070123456.cap
tshark -r dhcp_0120_1737_1807.cap.gz -R "sip contains 070123456" -w 070123456.cap


此外wireshark有內建許多統計功能,只要使用 -z 選項配合相關的參數使用,例如要看packet summary,只要使用 tshark -z io,stat,1 -q -n -i eth0,然後再搭配shell與RRD等,就可以畫出統計圖表。

法2: 使用 Tcpdump

Ex.抓封包
# tcpdump -i eth0 -w abc.cap

Ex. 抓封包,分割每個儲存的封包(size 1500bytes)
# tcpdump -i eth0 -s 1500 -w a.cap

Ex. 讀封包
# tcpdump -r abc.cap

P.S 大部分抓封包都需切換成 Root 權限才能使用