高效的DDoS攻击探测与分析工具——FastNetMon

一、简介

  FastNetMon这是一个基于多种抓包引擎(NetFlow, IPFIX, sFLOW, netmap, PF_RING, PCAP)的DoS/DDoS攻击高效分析工具,可以探测和分析网络中的异常流量情况,同时可以通过外部脚本通知或阻断攻击。

特性:

  1)可处理入/出口流量
  2)如果发现某个IP发出异常流量,可触发封禁脚本
  3)可通过ExaBGP将封禁IP通知BGP路由器
  4)可在1-2秒内发现DoS/DDoS
  5)支持插件
  6)测试最高支持10GE、5-6 Mpps(Intel i7 2600 & Intel Nic 82599)

二、安装FastNetMon

wget https://raw.githubusercontent.com/FastVPSEestiOu/fastnetmon/master/src/fastnetmon_install.pl -Ofastnetmon_install.pl 
perl fastnetmon_install.pl

It's REQUIRED to add all of your networks in CIDR notation (11.22.33.0/24) to the file /etc/networks_list in the form of one prefix per line.

Start main process:

/opt/fastnetmon/fastnetmon 

Start the client process in another console:

/opt/fastnetmon/fastnetmon_client

To enable fastnetmon to start on server startup, please add the following line to /etc/rc.local:

/opt/fastnetmon/fastnetmon --daemonize

If something goes wrong, please check logs:

tail -f /var/log/fastnetmon.log

The first time when threshold exceed (at this step we know IP, direction and power of attack). Second when we collect 100 packets for detailed audit of what happened. A sample script is provided and can be installed as follows:

cp /usr/src/fastnetmon/src/notify_about_attack.sh /usr/local/bin/notify_about_attack.sh
chmod 755 /usr/local/bin/notify_about_attack.sh

三、使用 pf_ring 作为 FastNetMon 的抓包引擎

首先编辑文件 /etc/fastnetmon.conf,将 mirror 的值改为 on ,这将使用 pf_ring 作为抓包引擎。

# PF_RING traffic capture, enough fast but wire speed version need paid license
mirror = on

同时,可以顺便把报警阈值调小一点,方便后面测试攻击。

# Limits for Dos/DDoS attacks 
threshold_pps = 200 threshold_mbps = 10 threshold_flows = 350

Start main process:

/opt/fastnetmon/fastnetmon 

Start the client process in another console:

/opt/fastnetmon/fastnetmon_client

四、模拟 DDoS 攻击测试 FastNetMon

编辑 /usr/local/bin/notify_about_attack.sh这个脚本,找到 ban 的条件语句,由于只是进行测试,我仅仅输出一条消息到 /tmp/ban.log 日志中。

if [ "$4" = "ban" ]; then
    echo "FastNetMon Guard: IP $1 blocked because $2 attack with power $3 pps" >> /tmp/ban.log
    exit 0
fi

我使用一款叫做 iperf 的工具来模拟 DDoS 攻击,这个工具一般用于测试网络带宽,当然也可以通过大量发包模拟一次 DDoS 攻击。

在 CentOS 上可以通过 yum 直接安装 iperf:yum install iperf

然后通过iperf -su命令启动 iperf 的服务器端。

这里 -u 参数指明侦听 udp 端口。

我将我的 mbp 作为攻击的发器端,同样安装 iperf : brew install iperf

在客户端上向服务器发起探测:iperf -u -c 10.1.2.137 -b 100M -P 5

这时,在服务器上执行 FastNetMon 的客户端命令 /opt/fastnetmon/fastnetmon_clinet进行查看,

可以看到出现如下信息。

FastNetMon v1.0 FastVPS Eesti OU (c) VPS and dedicated: http://FastVPS.host
IPs ordered by: packets
Incoming traffic         42594 pps    491 mbps      0 flows
10.1.2.137               35552 pps    410 mbps      0 flows  *banned*

Outgoing traffic             1 pps	0 mbps      0 flows
10.1.2.137                   1 pps	0 mbps      0 flows  *banned*

Internal traffic             0 pps	0 mbps

Other traffic                0 pps	0 mbps

Screen updated in:              0 sec 191 microseconds
Traffic calculated in:          0 sec 7 microseconds
Total amount of not processed packets: 0
Packets received:	404792
Packets dropped:        0
Packets dropped:        0.0 %

Ban list:
10.1.2.137/35552 pps incoming at 04_06_16_00:40:13

因为之前我设置了攻击阈值为 200 pps,10 mb,目前的这个负载量已经远远超过我设定的阈值,被认为遭到了攻击。可以看到,目前 10.1.2.137 这个 IP 已经被拉进 Ban list 之中了。

现在我们查看 FastNetMon 是否触发了通知,查看 /tmp/ban.log 这个日志,可以看到通知的消息。

FastNetMon Guard: IP 10.1.2.137 blocked because incoming attack with power 293 pps

FastNetMon 确实触发了通知的操作。 

五、FastNetMon 集成 InfluxDB

  InfluxDB 是一款开源的分布式时钟、事件和指标数据库。使用 Go 语言编写,它易于分布式和水平伸缩扩展。 InfluxDB 本身提供了非常简单易用的 HTTP API,因此它经常用于监控程序的后端数据存储,Grafana 对它就有非常好的支持。

它有三大特性:

  1. Time Series(时间序列):你可以使用与时间有关的相关函数,如最大,最小,求和等。
  2. Metrics(度量):你可以实时对大量数据进行计算。
  3. Eevents(事件):它支持任意的事件数据。

先来安装 InfluxDB

wget https://dl.influxdata.com/influxdb/releases/influxdb-0.13.0.x86_64.rpm
yum localinstall influxdb

编辑 InfluxDB 的配置文件 /etc/influxdb/influxdb.conf 中的 graphite 选项,按照如下配置:

[[graphite]]
  enabled = true
  bind-address = ":2003"
  protocol = "tcp"
  consistency-level = "one"


  batch-size = 5000
  batch-timeout = "1s" 
  separator = "."

  templates = [
    "fastnetmon.hosts.* app.measurement.cidr.direction.function.resource",
    "fastnetmon.networks.* app.measurement.cidr.direction.resource",
    "fastnetmon.total.* app.measurement.direction.resource"
  ]

现在就可以启动 InfluxDB 了。

# /etc/init.d/influxdb start
Starting the process influxdb [ OK ]
influxdb process was started [ OK ]

同样,需要在 FastNetMon 的配置文件 /etc/fastnetmon.conf 里做一些配置:

graphite = on
graphite_host = 127.0.0.1
graphite_port = 2003
graphite_prefix = fastnetmon

然后重启 FastNetMon

等待几秒,接下来登录 Influxdb shell,查看数据库里是否有数据了。

# influx
Visit https://enterprise.influxdata.com to register for updates, InfluxDB server management, and monitoring.
Connected to http://localhost:8086 version 0.13.0
InfluxDB shell version: 0.13.0
> show databases
name: databases
---------------
name
graphite
_internal

> use graphite
Using database graphite
> show measurements
name: measurements
------------------
name
fastnetmon.10_1_2_137.incoming.flows
fastnetmon.10_1_2_137.incoming.mbps
fastnetmon.10_1_2_137.incoming.pps
fastnetmon.10_1_2_137.outgoing.flows
fastnetmon.10_1_2_137.outgoing.mbps
fastnetmon.10_1_2_137.outgoing.pps
fastnetmon.172_26_1_1.incoming.flows
fastnetmon.172_26_1_1.incoming.mbps
fastnetmon.172_26_1_1.incoming.pps
fastnetmon.172_26_1_1.outgoing.flows
fastnetmon.172_26_1_1.outgoing.mbps
fastnetmon.172_26_1_1.outgoing.pps
fastnetmon.incoming.mbps
fastnetmon.incoming.pps
fastnetmon.incomingflows
fastnetmon.outgoing.mbps
fastnetmon.outgoing.pps
fastnetmon.outgoingflows

> select * from "fastnetmon.incoming.pps" order by time desc limit 10
name: fastnetmon.incoming.pps
-----------------------------
time            value
1465079546000000000    0
1465079545000000000    0
1465079544000000000    3
1465079543000000000    0
1465079542000000000    2
1465079541000000000    0
1465079540000000000    0
1465079539000000000    0
1465079538000000000    0
1465079537000000000    0
Influxdb shell

 

posted @ 2016-09-08 11:00  叶珍力  阅读(7147)  评论(0编辑  收藏  举报