Author: Xu FC
TCPDUMP 参数
-
-c <number>
: 指定抓包个数
tcpdump -c 2
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on atcp_veth0, link-type EN10MB (Ethernet), capture size 65535 bytes
05:55:13.756478 IP 193.1.3.11.ssh > 193.1.3.2.51871: Flags [P.], seq 2630991455:2630991651, ack 3844704184, win 255, length 196
05:55:13.757398 IP 193.1.3.11.ssh > 193.1.3.2.51871: Flags [P.], seq 196:376, ack 1, win 255, length 180
2 packets captured
2 packets received by filter
0 packets dropped by kernel
-
-i <interface>
: 指定目标端口
tcpdump -i eth0 -c 1
05:28:56.313349 IP 193.1.3.11.ssh > 193.1.3.2.51871: Flags [P.], seq 645536:645700, ack 365, win 255, length 164
1 packets captured
1 packets received by filter
0 packets dropped by kernel
-
-q
: 打印少量协议相关内容
tcpdump -i any -q -c 1
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on any, link-type LINUX_SLL (Linux cooked), capture size 65535 bytes
05:56:23.517366 IP 193.1.3.11.ssh > 193.1.3.2.51871: tcp 196
1 packet captured
17 packets received by filter
0 packets dropped by kernel
-
-v
: 显示详细内容,-vv
,-vvv
tcpdump -i any -c 1 -vvv
tcpdump: listening on any, link-type LINUX_SLL (Linux cooked), capture size 65535 bytes
05:57:29.524244 IP (tos 0x10, ttl 64, id 57549, offset 0, flags [DF], proto TCP (6), length 172)
193.1.3.11.ssh > 193.1.3.2.51871: Flags [P.], cksum 0x88ae (incorrect -> 0x2d8b), seq 2630995235:2630995367, ack 3844705656, win 255, length 132
1 packet captured
18 packets received by filter
0 packets dropped by kernel
-
-w <file_name>
: 将抓包结果保存到文件中
tcpdump -i any -c 1 -w file.cap
tcpdump: listening on any, link-type LINUX_SLL (Linux cooked), capture size 65535 bytes
1 packet captured
1 packet received by filter
0 packets dropped by kernel
-
-r <file_name>
: 从文件中读取数据
tcpdump -r file.cap
reading from file file.cap, link-type LINUX_SLL (Linux cooked)
05:58:16.533695 IP 193.1.3.11.ssh > 193.1.3.2.51871: Flags [P.], seq 2630996863:2630996995, ack 3844706644, win 255, length 132
基于协议过滤
-
arp
: 过滤 ARP
tcpdump -c 2 arp
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on ens3, link-type EN10MB (Ethernet), capture size 262144 bytes
01:24:22.276090 ARP, Request who-has 193.1.2.52 tell 193.1.2.141, length 46
01:24:22.276140 ARP, Request who-has 193.1.2.62 tell 193.1.2.141, length 46
2 packets captured
2 packets received by filter
0 packets dropped by kernel
-
icmp
,tcp
,udp
...
tcpdump -c 1 tcp
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on ens3, link-type EN10MB (Ethernet), capture size 262144 bytes
01:25:44.395200 IP 193.1.1.231.ssh > 193.1.1.110.52972: Flags [P.], seq 2915666324:2915666440, ack 3897014413, win 264, length 116
1 packet captured
7 packets received by filter
0 packets dropped by kernel
基于 IP 地址的过滤
-
host <IP address>
: 过滤源 IP 或者目的 IP 为指定 IP 地址的包
tcpdump -c 1 host 193.1.3.11
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on atcp_veth0, link-type EN10MB (Ethernet), capture size 65535 bytes
06:01:59.130264 IP 193.1.3.11.ssh > 193.1.3.2.51871: Flags [P.], seq 2631002191:2631002387, ack 3844711220, win 255, length 196
1 packet captured
1 packet received by filter
0 packets dropped by kernel
-
src/dst <IP address>
: 过滤源/目的 IP
tcpdump -c 1 src 193.1.3.11
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on atcp_veth0, link-type EN10MB (Ethernet), capture size 65535 bytes
06:06:12.125502 IP 193.1.3.11.ssh > 193.1.3.2.51871: Flags [P.], seq 2631002819:2631003015, ack 3844711340, win 255, length 196
1 packet captured
3 packets received by filter
0 packets dropped by kernel
-
net <sub net>
: 过滤源 IP 或者目的 IP 在指定子网的包
tcpdump -c 1 net 193.1.3.0/24
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on atcp_veth0, link-type EN10MB (Ethernet), capture size 65535 bytes
06:09:01.518140 IP 193.1.3.11.ssh > 193.1.3.2.51871: Flags [P.], seq 2631005067:2631005263, ack 3844712968, win 255, length 196
1 packet captured
1 packet received by filter
0 packets dropped by kernel
-
src/dst net <sub net>
: 过滤源/目的 IP 地址在指定子网范围的包
tcpdump -c 1 src net 193.1.3.0/24
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on atcp_veth0, link-type EN10MB (Ethernet), capture size 65535 bytes
06:10:27.133894 IP 193.1.3.11.ssh > 193.1.3.2.51871: Flags [P.], seq 2631005711:2631005907, ack 3844713104, win 255, length 196
1 packet captured
1 packet received by filter
0 packets dropped by kernel
基于 port 过滤
-
port <port>
: 过滤源 port 或者目的 port 为指定 port 的包
tcpdump -c 1 port 22
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on atcp_veth0, link-type EN10MB (Ethernet), capture size 65535 bytes
06:12:44.258223 IP 193.1.3.11.ssh > 193.1.3.2.51871: Flags [P.], seq 2631006339:2631006535, ack 3844713224, win 255, length 196
1 packet captured
1 packet received by filter
0 packets dropped by kernel
-
src/dst port
: 过滤源/目的 port
tcpdump -c 1 src net 193.1.3.0/24 and not src port 22
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on atcp_veth0, link-type EN10MB (Ethernet), capture size 65535 bytes
06:13:44.650217 IP 193.1.3.2.51871 > 193.1.3.11.ssh: Flags [.], ack 2631007195, win 16321, length 0
1 packet captured
1 packet received by filter
0 packets dropped by kernel
基于 TCP flag 过滤
-
tcp[13] & 2!=0
: 过滤 SYN
tcpdump -c 2 net 193.0.0.0/8 and "tcp[13] & 2 != 0"
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on ens3, link-type EN10MB (Ethernet), capture size 262144 bytes
01:22:49.679842 IP 193.1.1.110.53106 > 193.1.1.231.ssh: Flags [S], seq 423562932, win 8192, options [mss 1460,nop,wscale 2,nop,nop,sackOK], length 0
01:22:49.679922 IP 193.1.1.231.ssh > 193.1.1.110.53106: Flags [S.], seq 1364181361, ack 423562933, win 29200, options [mss 1460,nop,nop,sackOK,nop,wscale 7], length 0
2 packets captured
2 packets received by filter
0 packets dropped by kernel
-
tcp[13] & 16 !=0
: 过滤 ACK
tcpdump -c 2 net 193.0.0.0/8 and "tcp[13] & 16!=0"
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on ens3, link-type EN10MB (Ethernet), capture size 262144 bytes
01:27:47.239368 IP 193.1.1.231.ssh > 193.1.1.110.52972: Flags [P.], seq 2915667924:2915668120, ack 3897015017, win 264, length 196
01:27:47.245847 IP 193.1.1.231.ssh > 193.1.1.110.52972: Flags [P.], seq 196:376, ack 1, win 264, length 180
2 packets captured
2 packets received by filter
0 packets dropped by kernel
-
tcp[13]=18
: 过滤 SYN ACK
tcpdump net 193.0.0.0/8 and "tcp[13]=18"
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on ens3, link-type EN10MB (Ethernet), capture size 262144 bytes
01:30:13.419672 IP 193.1.1.231.ssh > 193.1.1.110.53677: Flags [S.], seq 1820623300, ack 1594275082, win 29200, options [mss 1460,nop,nop,sackOK,nop,wscale 7], length 0
^C
1 packet captured
1 packet received by filter
0 packets dropped by kernel
-
tcp[13] & 4!=0
: 过滤 RST
tcpdump "tcp[13] & 4!=0"
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on ens3, link-type EN10MB (Ethernet), capture size 262144 bytes
01:31:43.821051 IP 193.1.1.231.microsoft-ds > 193.1.1.62.56513: Flags [R.], seq 0, ack 3270176790, win 0, length 0
-
tcp[13] & 1!=0
: 过滤 FIN
tcpdump "tcp[13] & 1!=0"
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on ens3, link-type EN10MB (Ethernet), capture size 262144 bytes
01:33:36.082121 IP 193.1.1.231.ssh > 193.1.1.110.53939: Flags [F.], seq 3223250025, ack 2445636549, win 246, length 0
01:33:36.082691 IP 193.1.1.110.53939 > 193.1.1.231.ssh: Flags [F.], seq 1, ack 1, win 16412, length 0
网友评论