一、簡介
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 對它就有非常好的支持。
它有三大特性:
- Time Series(時間序列):你可以使用與時間有關的相關函數,如最大,最小,求和等。
- Metrics(度量):你可以實時對大量數據進行計算。
- 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