歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux管理 >> Linux安全 >> DDoS Deflate防Linux下DDOS攻擊

DDoS Deflate防Linux下DDOS攻擊

日期:2017/2/27 17:10:36   编辑:Linux安全

服務器運營過程中可能會受到黑客攻擊,常見的攻擊方式有SYN,DDOS等。通過更換IP,查找被攻擊的站點可能避開攻擊,但是中斷服務的時間比較 長。比較徹底的解決方法是添置硬件防火牆。不過,硬件防火牆價格比較昂貴。在沒有硬防的情況下,尋找軟件代替是最直接的方法,比如用iptables,但 是iptables不能自動屏蔽,只能手動屏蔽。這裡要介紹的就是一款能夠自動屏蔽DDOS攻擊者IP的軟件:DDoS Deflate。

DDOS deflate是一個輕量級的腳本,以協助阻止拒絕服務攻擊的過程中的bash shell腳本。它使用下面的命令來創建一個連接到服務器的IP地址列表,以及與它們的連接總數。這是最簡單的安裝軟件的解決方案之一。

# netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n

超過了預先配置的連接數的IP地址自動被服務器防火牆阻止

腳本特點:

1.可以配置白名單的IP地址,通過配置:/usr/local/ddos/ignore.ip.list

2.簡單的配置文件:/usr/local/ddos/ddos.conf

3.IP地址被封時間是預先設定的(默認:600秒後自動解除封鎖)

4.通過配置文件,腳本可以定時周期性運行(默認是:1分鐘)

5.有IP地址被封鎖時,可以為指定的郵箱接收電子郵件警報。

安裝:

# wget http://www.inetbase.com/scripts/ddos/install.sh  
# chmod 0700 install.sh
# cat install.sh
#!/bin/sh
if [ -d '/usr/local/ddos' ]; then
         echo; echo; echo "Please un-install the previous version first"
         exit 0
else
         mkdir /usr/local/ddos
fi
clear
echo; echo 'Installing DOS-Deflate 0.6'; echo
echo; echo -n 'Downloading source files...'
wget -q -O /usr/local/ddos/ddos.conf http://www.inetbase.com/scripts/ddos/ddos.conf
echo -n '.'
wget -q -O /usr/local/ddos/LICENSE http://www.inetbase.com/scripts/ddos/LICENSE
echo -n '.'
wget -q -O /usr/local/ddos/ignore.ip.list http://www.inetbase.com/scripts/ddos/ignore.ip.list
echo -n '.'
wget -q -O /usr/local/ddos/ddos.sh http://www.inetbase.com/scripts/ddos/ddos.sh
chmod 0755 /usr/local/ddos/ddos.sh
cp -s /usr/local/ddos/ddos.sh /usr/local/sbin/ddos
echo '...done'
echo; echo -n 'Creating cron to run script every minute.....(Default setting)'
/usr/local/ddos/ddos.sh --cron > /dev/null 2>&1
echo '.....done'
echo; echo 'Installation has completed.'
echo 'Config file is at /usr/local/ddos/ddos.conf'
echo 'Please send in your comments and/or suggestions to [email protected]'
echo
cat /usr/local/ddos/LICENSE | less

# ./install.sh

配置文件:

# ll /usr/local/ddos/
總用量 24
-rw-r--r--. 1 root root   971  1月 10 2006 ddos.conf
-rwxr-xr-x. 1 root root  3945  1月 10 2006 ddos.sh
-rw-r--r--. 1 root root    10  1月 10 2006 ignore.ip.list
-rw-r--r--. 1 root root 10113  1月 10 2006 LICENSE

# cat /usr/local/ddos/ddos.conf
##### Paths of the script and other files
PROGDIR="/usr/local/ddos"  #文件存放目錄
PROG="/usr/local/ddos/ddos.sh" #主要功能腳本
IGNORE_IP_LIST="/usr/local/ddos/ignore.ip.list" #白名單地址列表
CRON="/etc/cron.d/ddos.cron" #crond定時任務腳本
APF="/etc/apf/apf"
IPT="/sbin/iptables"

##### frequency in minutes for running the script
##### Caution: Every time this setting is changed, run the script with --cron
#####          option so that the new frequency takes effect
FREQ=1 #ddos.sh執行的頻率,單位是分鐘,搭配crontab來執行.
##### How many connections define a bad IP? Indicate that below.
NO_OF_CONNECTIONS=150 #最大連接數設置,超過這個數字的IP就會屏蔽

##### APF_BAN=1 (Make sure your APF version is atleast 0.96)
##### APF_BAN=0 (Uses iptables for banning ips instead of APF)
APF_BAN=1 #1:使用APF 0:使用iptables,一般情況下你是使用iptables來做防火牆,所以這裡你需要將APF_BAN的值改為0

##### KILL=0 (Bad IPs are'nt banned, good for interactive execution of script)
##### KILL=1 (Recommended setting)
KILL=1 #將非法的的IP加入iptables的INPUT鏈中,DROP之.

##### An email is sent to the following address when an IP is banned.
##### Blank would suppress sending of mails
EMAIL_TO="root"   #發送電子郵件報警的郵箱地址

##### Number of seconds the banned ip should remain in blacklist.
BAN_PERIOD=600  #屏蔽IP的時間,根據情況調整

卸載DDOSdeflate

# wget http://www.inetbase.com/scripts/ddos/uninstall.ddos
# chmod 0700 uninstall.ddos
# ./uninstall.ddos
Copyright © Linux教程網 All Rights Reserved