2019独角兽企业重金招聘Python工程师标准>>>
监控系统状态
- 抓包工具 tcpdump
- 用法:tcpdump -nn
- tcpdump -nn -i ens33
- tcpdump -nn port 80
- tcpdump -nn not port 22 and host 192.168.0.100
- tcpdump -nn -c 100 -w 1.cap
- tshark -n -t a -R http.request -T fields -e "frame.time" -e "ip.src" -e "http.host" -e "http.request.method" -e "http.request.uri"
- yum install -y wireshark
tcpdump命令
- tcpdump命令,是用来抓包的
- 安装tcpdump包——>yum install -y tcpdump
- tcp -nn -i eno16777736
- 第一个n,表示你的ip用数字的形式显示出来(若是不加,则会显示出主机名)
[root@hf-01 ~]# tcpdump -nn
tcpdump: packet printing is not supported for link type NFLOG: use -w
[root@hf-01 ~]# ifconfig
eno16777736: flags=4163 mtu 1500
inet 192.168.74.129 netmask 255.255.255.0 broadcast 192.168.74.255
inet6 fe80::20c:29ff:feff:fe93 prefixlen 64 scopeid 0x20
ether 00:0c:29:ff:fe:93 txqueuelen 1000 (Ethernet)
RX packets 11067 bytes 12250186 (11.6 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2631 bytes 312427 (305.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73 mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10
loop txqueuelen 0 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@hf-01 ~]# tcpdump -nn -i eno16777736
5204, ack 6605, win 159, length 180
06:27:41.186368 IP 192.168.74.129.22 > 192.168.74.1.49322: Flags [P.], seq 45955204:45955384, ack 6605, win 159, length 180
06:27:41.186422 IP 192.168.74.129.22 > 192.168.74.1.49322: Flags [P.], seq 45955384:45955564, ack 6605, win 159, length 180
等等等,运行后,会显示出很多的信息
按ctrl+c退出
- DDos攻击
- udp flood叫udp的洪水攻击
- 在遇到这种攻击的时候,只能接入防攻击的设备(比如:创宇--300G是可以顶住的)
- udp flood叫udp的洪水攻击
tcpdump命令指定端口
- tcpdump -nn -i eno16777736 port 22
[root@hf-01 ~]# tcpdump -nn -i eno16777736 port 22
4, length 0
06:52:04.034073 IP 192.168.74.129.22 > 192.168.74.1.49322: Flags [P.], seq 228004:228376, ack 1, win 159, length 372
06:52:04.034155 IP 192.168.74.129.22 > 192.168.74.1.49322: Flags [P.], seq 228376:228556, ack 1, win 159, length 180
06:52:04.034302 IP 192.168.74.1.49322 > 192.168.74.129.22: Flags [.], ack 228556, win 252, length 0
06:52:04.034387 IP 192.168.74.129.22 > 192.168.74.1.49322: Flags [P.], seq 228556:228832, ack 1, win 159, length 276
等等等,只截取了一部分
tcpdump命令使用排除法
- tcpdump -nn not port 22 and host 192.168.0.100 除去22端口和只要ip为192.168.0.100的包
tcpdump命令指定长度和个数
- tcpdump -nn -i eno16777736 -c 100 -w 1.cap 指定数据包只要10个,并存入到1.cap文件中去
- 在终端查看的时候,不产生一些数据量的话,就不会产生那么多数据包
- file 1.cap 查看该文件——>文件名称可以随意更改
- 能查看文件的大概信息
- 该文件不能直接 cat命令 查看的,会出现乱码
- 因为1.cap这个文件就是从你网卡里捕捉到的数据包,就是你通信的那个数据
在这里复制另一个终端,并打开,跑vmstat 1命令
在当前终端查看,输入以下命令
[root@hf-01 ~]# tcpdump -nn -i eno16777736 -c 10 -w 1.cap
tcpdump: listening on eno16777736, link-type EN10MB (Ethernet), capture size 262144 bytes
10 packets captured
10 packets received by filter
0 packets dropped by kernel
[root@hf-01 ~]# file 1.cap
1.cap: tcpdump capture file (little-endian) - version 2.4 (Ethernet, capture length 262144)
[root@hf-01 ~]#
- 若要查看这个文件,则可以tcpdump -r 1.cap
- -r 表示读
[root@hf-01 ~]# tcpdump -r 1.cap //查看1.cap文件
reading from file 1.cap, link-type EN10MB (Ethernet)
07:02:05.134302 IP 192.168.74.129.ssh > 192.168.74.1.49322: Flags [P.], seq 4218852344:4218852492, ack 3076966380, win 159, length 148
07:02:05.134859 IP 192.168.74.1.49322 > 192.168.74.129.ssh: Flags [.], ack 148, win 255, length 0
07:02:05.257655 IP 192.168.74.129.ssh > 192.168.74.1.49322: Flags [P.], seq 148:280, ack 1, win 159, length 132
07:02:05.462113 IP 192.168.74.1.49322 > 192.168.74.129.ssh: Flags [.], ack 280, win 255, length 0
07:02:06.258704 IP 192.168.74.129.ssh > 192.168.74.1.49322: Flags [P.], seq 280:428, ack 1, win 159, length 148
07:02:06.462164 IP 192.168.74.1.49322 > 192.168.74.129.ssh: Flags [.], ack 428, win 254, length 0
07:02:07.259714 IP 192.168.74.129.ssh > 192.168.74.1.49322: Flags [P.], seq 428:560, ack 1, win 159, length 132
07:02:07.460218 IP 192.168.74.1.49322 > 192.168.74.129.ssh: Flags [.], ack 560, win 254, length 0
07:02:08.260717 IP 192.168.74.129.ssh > 192.168.74.1.49322: Flags [P.], seq 560:708, ack 1, win 159, length 148
07:02:08.460263 IP 192.168.74.1.49322 > 192.168.74.129.ssh: Flags [.], ack 708, win 253, length 0
[root@hf-01 ~]#
- 在read的返回的时候,是数据流,从哪到哪(包括tcpdump -nn屏幕上显示的也是数据流)
- 而tcpdump -r的时候,写入的是真正的数据包
tshark命令
- tshark命令
- 安装tshark包——>yum install -y wireshark
- tshark和tcpdump类似的工具,也是用来抓包的
- tshark -n -t a -R http.request -T fields -e "frame.time" -e "ip.src" -e "http.host" -e "http.request.method" -e "http.request.uri" 查看指定网卡,80端口的一个web访问情况
- 类似于web的访问日志