DDoS Deflate防Linux下DDOS攻擊

來源:互聯網
上載者:User

伺服器運營過程中可能會受到駭客攻擊,常見的攻擊方式有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 zaf@vsnl.com'

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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.