altis 2016-12-5 15:44
DDoS Deflate - Linux下防DDoS攻擊的基礎防護
DDoS deflate是一款Linux/centos減輕/防止ddos攻擊的一個小程序,相當於軟件防火牆。<br>注意,此程序僅僅能抵禦較低流量的攻擊,大流量攻擊連用了上百台高檔服務器做了負載均衡的新浪都扛不住,何況一個小小的普通服務器或vps。<br>對此程序不要期望過高。這裡僅僅介紹一下,對於一些簡單的軟件攻擊可能還有點作用。<br><br>DDoS deflate介紹<br><br>DDoS deflate是一款免費的用來防禦和減輕DDoS攻擊的腳本。它通過netstat監測跟踪創建大量網絡連接的IP地址,在檢測到某個結點超過預設的限制時,該程序會通過 iptables 禁止或阻擋這些IP.<br><br>DDoS deflate官方網站:http://deflate.medialayer.com/<br><br>如何確認是否受到DDOS攻擊?<br><br>執行:<br><br># <font color="Blue">netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n</font><br>執行後,將會顯示服務器上所有的每個IP多少個連接數。<br><br>以下是用VPS測試的結果:<br><br>www:~# netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n <br>1 58.60.118.142 <br>1 Address <br>1 servers ) <br>4 117.36.231.253 <br>4 119.162.46.124 <br>6 219.140.232.128 <br>8 220.181.61.31<br><font color="Red">2311 57.15.42.197 (這個看起來像攻擊)</font><br>每個IP幾個、十幾個或幾十個連接數都還算比較正常,如果像上面成百上千肯定就不正常了。<br><br>1、安裝DDoS deflate<br><br># wget http://www.inetbase.com/scripts/ddos/install.sh <br># chmod 0700 install.sh<br># ./install.sh<br><br>2、配置DDoS deflate<br><br>下面是DDoS deflate的默認配置位於/usr/local/ddos/ddos.conf ,內容如下:<br>[quote]<br>##### Paths of the script and other files <br>PROGDIR="/usr/local/ddos" <br>PROG="/usr/local/ddos/ddos.sh" <br>IGNORE_IP_LIST="/usr/local/ddos/ignore.ip. list" //IP地址白名單<br>CRON="/etc/cron.d/ddos.cron" //定時執行程序<br>APF="/etc/apf/apf" <br>IPT="/sbin/iptables" <br><br>##### frequency in minutes for running the script <br>##### Caution: Every time this setting is changed, run the script with --cron <br>##### option so that the new frequency takes effect <br>FREQ=1 //檢查時間間隔,默認1分鐘<br><br>##### How many connections define a bad IP? Indicate that below. <br>NO_OF_CONNECTIONS=150 //最大連接數,超過這個數IP就會被屏蔽,一般默認即可<br><br>##### APF_BAN=1 (Make sure your APF version is atleast 0.96) <br>##### APF_BAN=0 (Uses iptables for banning ips instead of APF) <br>APF_BAN=0 //使用APF還是iptables。推薦使用iptables,將APF_BAN的值改為0即可。<br><br>##### KILL=0 (Bad IPs are'nt banned, good for interactive execution of script) <br>##### KILL=1 (Recommended setting) <br>KILL=1 //是否屏蔽IP,默認即可<br><br>### ## An email is sent to the following address when an IP is banned. <br>##### Blank would suppress sending of mails <br>EMAIL_TO="root" //當IP被屏蔽時給指定郵箱發送郵件,推薦使用,換成自己的郵箱即可<br><br>##### Number of seconds the banned ip should remain in blacklist. <br>BAN_PERIOD=600 //禁用IP時間,默認600秒,可根據情況調整<br>用戶可根據給默認配置文件加上的註釋提示內容,修改配置文件。<br>[/quote]<br><br>3.白名單設置:<br><br>有時候默認的白名單經常有失誤,為了避免這個情況,我們可以手工設置白名單的ip,然後強制不允許修改<br><br>手工設置白名單IP<br># vi /usr/local/ddos/ignore.ip.list<br><br>強制不允許修改<br># chattr +i /usr/local/ddos/ignore.ip.list<br><br>解除不允許修改<br># chattr -i /usr/local/ddos/ignore.ip.list<br><br>4. ubuntu 障礙排除:<br>當在 ubuntu 16.04 下安裝後,執行 <br># /usr/local/ddos/ddos.sh<br>會出現錯誤<br>[quote]<br>/usr/local/ddos/ddos.sh: 13: [: /usr/local/ddos/ddos.conf: unexpected operator<br>DDoS-Deflate version 0.6<br>Copyright (C) 2005, Zaf <zaf@vsnl.com><br><br>$CONF not found.<br>[/quote]<br><br>這時你只要編輯 ddos.sh 檔<br>[quote]<br># <font color="DarkGreen">vi /usr/local/ddos/ddos.sh</font><br>將第一行的<br>#!/bin/sh<br>改成<br><font color="Red">#!/bin/bash</font><br>[/quote]<br><br>還有預設的排程不會運作...必須自己手動加上<br>[quote]<br>############ DDoS Protection ####################<br>0-59/1 * * * * root /usr/local/ddos/ddos.sh >/dev/null 2>&1<br>[/quote]<br><br>這樣就可以正常囉~<br><br>參考資料: <a href="http://blog.xuite.net/lichangying/wretch/176501051-DDoS+Deflate%E9%98%B2Linux%E4%B8%8BDDOS%E6%94%BB%E6%93%8A" target="_blank">http://blog.xuite.net/lichangyin ... S%E6%94%BB%E6%93%8A</a>