歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux管理 >> Linux安全 >> DDoS deflate–簡單解決VPS被DDOS/CC攻擊

DDoS deflate–簡單解決VPS被DDOS/CC攻擊

日期:2017/2/27 17:10:15   编辑:Linux安全
我想現在大家接觸VPS久了,也知道互聯網上被DDOS,CC是家常便飯,在沒有硬防的情況下,尋找軟件代替是最直接的方法,比如用iptables,但是iptables不能在自動屏蔽,只能手動屏蔽,今天我給大家介紹的就是一款可以自動屏蔽DDOS,CC,SYN攻擊的軟件:DDoS Deflate。

DDoS deflate官方地址:http://deflate.medialayer.com/

DOS DEFLATE是一個輕量級的bash shell腳本,以協助用戶阻止DDOS攻擊,它利用下面的命令創建一個連接到服務器的IP地址列表,以及與他們連接總數。它是在軟件層面上的簡單和最容易安裝的解決方案之一。

如何查看是否被攻擊

在VPS中輸入上面的命令查看
netstat -ntu |  awk '{print $5}' |  cut -d: -f1 |  sort |  uniq -c |  sort -n

下面是安裝教程
wget http://www.inetbase.com/scripts/ddos/install.sh
chmod +x  install .sh
. /install .sh

安裝完以後,你會看到一大篇協議,按q退出即可 :

安裝後文件說明 安裝目錄為:/usr/local/ddos/
  • ddos.conf ? DDoS-Deflate 的配置文件,其中配置防止ddos時的各種行為
  • ddos.sh ? DDoS-Deflate 的主程序,使用shell編寫的,整個程序的功能模塊
  • ignore.ip.list ? 白名單,該文件中的ip超過設定的連接數時,也不被 DDoS-Deflate 阻止
  • LICENSE ? DDoS-Deflate 程序的發布協議

下面是配置文件的中文說明 大家可以根據配置文件進行修改,默認也可以
##### 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"  # 白名單.如有反向代理,注意添加本機地址和本機外網IP地址,防止提供反向代理的主機被判定為攻擊.
CRON=” /etc/cron .d /ddos . cron ”
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 ##### How many connections define a bad IP? Indicate that below. # 單IP發起連接數閥值,不建議設置太低.
NO_OF_CONNECTIONS=150
##### APF_BAN=1 (Make sure your APF version is atleast 0.96)
##### APF_BAN=0 (Uses iptables for banning ips instead of APF) #一般情況下你是使用iptables來做防火牆,所以這裡你需要將 APF_BAN的值改為0.
APF_BAN=1
##### KILL=0 (Bad IPs are’nt banned, good for interactive execution of script)
##### KILL=1 (Recommended setting)
KILL=1  // 是否屏蔽IP,默認即可
##### An email is sent to the following address when an IP is banned. # 當單IP發起的連接數超過閥值後,將發郵件給指定的收件人.
##### Blank would suppress sending of mails
EMAIL_TO=”root”  // 這裡是郵箱,可以替換成你的郵箱
##### Number of seconds the banned ip should remain in blacklist. # 設置被擋IP多少秒後移出黑名單.
BAN_PERIOD=600

查看/usr/local/ddos/ddos.sh文件的第117行
netstat -ntu |  awk '{print $5}' |  cut -d: -f1 |  sort |  uniq -c |  sort -nr > $BAD_IP_LIST

修改為以下代碼即可!
netstat -ntu |  awk '{print $5}' |  cut -d: -f1 |  sed -n  '/[0-9]/p' |  sort |  uniq -c |  sort -nr > $BAD_IP_LIST

卸載
wget http: //www .inetbase.com /scripts/ddos/uninstall .ddos
chmod +x uninstall.ddos
. /uninstall .ddos

白名單設置

有時候默認的白名單經常有失誤,為了避免這個情況,我們可以手工設置白名單的ip,然後強制不允許修改
vi /usr/local/ddos/ignore .ip.list  // 手工設置白名單IP
chattr +i  /usr/local/ddos/ignore .ip.list   // 強制不允許修改
chattr -i  /usr/local/ddos/ignore .ip.list   // 解除不允許修改

常見問題
1.如何判斷是否生效
使用web壓力測試,自己攻擊自己,詳細文章,過幾天會介紹

2.重新啟動VPS腳本會自動運行嗎?
會自動運行

3.運行必要軟件是什麼

iptables和sendmail 安裝方法 yum install iptables或sendmail sendmail可以不裝。

4.怎麼查看被屏蔽IP
如果屏蔽後,請用iptables -L -n 命令查看被屏蔽的IP
Copyright © Linux教程網 All Rights Reserved