抓包软件学习
[root@vultr ~]# tcpdump -i eth0 -c 2
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
01:25:44.952654 IP 45.63.62.88.vultrusercontent.com.ssh > 27.38.238.130.cxws: Flags [P.], seq 2453249983:2453250179, ack 227453586, win 37, length 196
01:25:44.953148 IP 45.63.62.88.vultrusercontent.com.53759 > 108.61.10.10.choopa.net.domain: 63726+ PTR? 130.238.38.27.in-addr.arpa. (44)
2 packets captured
8 packets received by filter
0 packets dropped by kernel
[root@vultr ~]# tcpdump -i eth0 -c 2 -nn
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
01:29:06.950182 IP 45.63.62.88.22 > 27.38.238.130.4673: Flags [P.], seq 2453251891:2453252087, ack 227454630, win 37, length 196
01:29:06.950649 IP 45.63.62.88.22 > 27.38.238.130.4673: Flags [P.], seq 196:376, ack 1, win 37, length 180
2 packets captured
2 packets received by filter
0 packets dropped by kernel
-n Don't convert host addresses to names. This can be used to avoid DNS lookups.
-nn Don't convert protocol and port numbers etc. to names either.
-nn :IP和port以数字形式展示,默认以主机名和服务名称展示
-i:监听的网络接口
-c:抓取的数据包数量
-r:从文件读取数据包
-w:将数据包存储下来
Next, we look at the two commands used to generate our captures:
Write to PCAP file - tcpdump -i enp0s8 -c100 -nn -w output_file
Write to TXT file - tcpdump -i enp0s8 -c100 -nn > output.txt
保存到PCAP文件可以使用WireShark打开
//抓取的时候进行过滤
[root@vultr ~]# tcpdump -i eth0 -nn port 9094
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
01:58:32.925799 IP 45.63.62.88.9094 > 27.38.238.130.65110: Flags [P.], seq 1945586592:1945586665, ack 3204078956, win 33, length 73
01:58:33.086865 IP 27.38.238.130.65110 > 45.63.62.88.9094: Flags [F.], seq 1, ack 73, win 1027, length 0
01:58:33.087135 IP 45.63.62.88.9094 > 27.38.238.130.65110: Flags [F.], seq 73, ack 2, win 33, length 0
01:58:33.246390 IP 27.38.238.130.65110 > 45.63.62.88.9094: Flags [.], ack 74, win 1027, length 0
^C
4 packets captured
4 packets received by filter
0 packets dropped by kernel
//抓取数据包保存为文件
[root@vultr ~]# tcpdump -i eth0 -c 4 -nn -w test.dump
tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
4 packets captured
5 packets received by filter
0 packets dropped by kernel
[root@vultr ~]# file test.dump
test.dump: tcpdump capture file (little-endian) - version 2.4 (Ethernet, capture length 262144)
//读取数据包文件
[root@vultr ~]# tcpdump -r test.dump
reading from file test.dump, link-type EN10MB (Ethernet)
01:47:09.099760 IP 45.63.62.88.vultrusercontent.com.ssh > 27.38.238.130.cxws: Flags [P.], seq 2453254991:2453255123, ack 227456682, win 37, length 132
01:47:09.258998 IP 27.38.238.130.cxws > 45.63.62.88.vultrusercontent.com.ssh: Flags [.], ack 132, win 1025, length 0
01:47:17.421624 IP 27.38.238.130.cxws > 45.63.62.88.vultrusercontent.com.ssh: Flags [P.], seq 1:53, ack 132, win 1025, length 52
01:47:17.421799 IP 45.63.62.88.vultrusercontent.com.ssh > 27.38.238.130.cxws: Flags [P.], seq 132:184, ack 53, win 37, length 52
//从已保存数据包文件过滤
[root@vultr ~]# tcpdump -r test.dump port 21
reading from file test.dump, link-type EN10MB (Ethernet)
[root@vultr ~]# tcpdump -r test.dump 'port 22'
reading from file test.dump, link-type EN10MB (Ethernet)
01:47:09.099760 IP 45.63.62.88.vultrusercontent.com.ssh > 27.38.238.130.cxws: Flags [P.], seq 2453254991:2453255123, ack 227456682, win 37, length 132
01:47:09.258998 IP 27.38.238.130.cxws > 45.63.62.88.vultrusercontent.com.ssh: Flags [.], ack 132, win 1025, length 0
01:47:17.421624 IP 27.38.238.130.cxws > 45.63.62.88.vultrusercontent.com.ssh: Flags [P.], seq 1:53, ack 132, win 1025, length 52
01:47:17.421799 IP 45.63.62.88.vultrusercontent.com.ssh > 27.38.238.130.cxws: Flags [P.], seq 132:184, ack 53, win 37, length 52
过滤条件举例:
'tcp port 21':针对协议和端口过滤;
'host 127.0.0.1':针对主机进行过滤
误区:
wireshark底层不是tcpdump,过滤条件语法不同。
[root@vultr ~]# tcpdump -i eth0 -nn 'tcp.port==22' -c 5
tcpdump: syntax error
评论
发表评论