tcpdump與WireShark是Linux下的兩個常用,功能強大的抓包工具,下面列出這兩個工具的簡單用法。
| tcpdump用法 |
tcpdump用法:
sudo tcpdump -i ens33 src 192.168.0.19 port 80 -xx -Xs 0 -w test.cap
sudo tcpdump -i ens33 src port 80 -xx -Xs 0 -w test.cap
參數說明:
-i: 指定網卡
src: 指明包的來源
port: 指明端口號
-xx: 指抓到的包以16進制顯示
-X: 指以ASCII碼顯示
-s 0: 指明抓整個包
-w: 寫到文件中
| WireShark過慮用法 |
【WireShark中的邏輯運算】
與: and 或 &&
或: or 或 ||
非: not 或!
WireShark中的判斷語句
等於: eq 或 ==
大於: gt 或 >
小於: lt 或 <
大於等於: ge 或 >=
小於等於: le 或 <=
不等於: ne 或 !=
組合符(小括號)
()
包含與正由表達式匹配運算符
contains
matches
注意:matches 后的關鍵字是不區分大小寫的,contains后面的關鍵字區分大小寫。
【協議過濾】
在表達式輸入框中輸入協議名稱即可。
注意:協議名稱為小寫,大寫會報錯
http
udp
tcp
arp
icmp
smtp
pop
dns
ip
ssl
ftp
telnet
ssh
rdp
rip
ospf
捕獲多種協議,只需要對協議進行邏輯組合
http or udp
排除某種協議的數據包
not arp not tcp
【http域名與url過濾】
按內容長度過濾
http.content_length <= 100
http.content_length_header <= 100
針對數據包內容的過濾
匹配http請求中含有/api/member/health/check 的請求信息
http.request.uri matches "/api/member/health/check"
查詢url中包含/api/member/home/test.html? 字符串的信息
http.request.uri contains "/api/member/home/test.html?"
按域名過濾
http.host == "jd.com" #精確過濾
http.host contains "jd.com" #模糊過慮
過濾請求的uri,取值是域名后的部分
http.request.uri=="/online/setpoint"
過濾完整的url
http.request.full_uri=="https://passport.jd.com/uc/login"
按http響應的狀態過慮
http.response.code==302
http.response.code==401
過濾所有的http響應包
http.request==1
http.response==1
過濾所有請求方式為POST或GET的http請求包,注意POST或GET為大寫
http.request.method==GET
http.request.method==POST
過濾含有指定cookie的http數據包
http.cookie contains userid
過濾http頭中server字段含有nginx字符的數據包
http.server contains "nginx"
過濾content_type是text/html的http響應
http.content_type == "text/html"
過濾content_type是application/json的http響應
http.content_type == "application/json"
過濾content_encoding是gzip的http包
http.content_encoding == "gzip"
過濾所有含有http頭中含有server字段的數據包
http.server
過濾HTTP/1.1版本的http包,包括請求和響應
http.request.version == "HTTP/1.1"
過濾http響應中的phrase
http.response.phrase == "OK"
【ip與端口過濾】
按目標地址過濾
ip.dst==192.168.0.19
按源地址過濾
ip.src==192.168.0.26
按目標地址或源地址過濾
ip.addr==192.168.0.19
按目標端口或源端口過濾
tcp.port==1935
udp.port==2365
按源端口過濾
tcp.srcport==2365
udp.srcport==2365
按目標端口過濾
tcp.dstport==1935
udp.dstport==1935
【數據過濾】
按包長度過濾
tcp.length < 300
udp.length < 300
過濾指定長度的udp數據包
udp.length == 20
過濾指定長度的tcp數據包
tcp.length == 20
過濾data部分長度為8的數據包
data.len==8
過濾指定內容的數據包
data.data == 00:08:30:03:00:00:00:00
【捕獲經過指定ip的數據包】
抓取192.168.0.1 收到和發出的所有數據包
host 192.168.0.9
源地址192.168.0.1發出的所有數據包
src host 192.168.0.9
目標地址192.168.0.1收到的所有數據包
dst host 192.168.0.9
根據主機名過濾
src host hostnam
根據MAC地址過濾
ether host 80:05:09:03:E4:35
網絡過濾,過濾整個網段
net 192.168.0
src net 192.168
dst net 192
【MAC地址過濾】
過濾目標或源地址是00:11:22:33:44:55的數據包
eth.addr== 00:11:22:33:44:55
過濾源地址是00:11:22:33:44:55的數據包
eth.src== 00:11:22:33:44:55
過濾目標地址是00:11:22:33:44:55的數據包
eth.dst== 00:11:22:33:44:55
【組合過濾】
捕獲udp源端口等於3457,源ip等於3457,或者udp目標端口等於1091,目標ip等於192.168.0.10的數據包
(upd.srcport==3457 and ip.src=192.168.0.9) or (upd.dstport==1091 and ip.dst=192.168.0.10)
抓取所有目的網絡是192.168,但目的主機不是192.168.0.2 的TCP數據
(tcp) and ((dst net 192.168) and (not dst host 192.168.0.2))
抓取所有目標MAC 地址是80:05:09:03:E4:35 的ICMP 數據
(icmp) and ((ether dst host 70:03:09:15:F4:12))
icmp && eth.dst==70:03:09:15:F4:12
