比思論壇

標題: LNMP下安裝CSF防火墙、CC攻击解决方法 [打印本頁]

作者: wabb44400    時間: 2012-9-18 18:30
標題: LNMP下安裝CSF防火墙、CC攻击解决方法
被DDOS攻击了以后,就一直找解决的方法。询问了很多人,最后让Kiloserve的技术人员帮我弄些方法,其中有提到过CFS

这个LINUX上的防火墙,记得上次KVM.LA的K总也提过,最终我还是选择了使用CSF的方法。

安装ConfigServer Security &  Firewall安全防护软件,它可以在极大程度上保护LINUX服务器安全。这是很重要的

一步,请不要忽略。不同的母机配置不同,可能封了部分功能,安装这个可以保证开啟必要功能,关闭不必要的功能。

cd /tmp
wget http://www.configserver.com/free/csf.tgz
tar zxvf csf.tgz
cd csf
./install.generic.sh
现在我们装好了CSF,然后就要修正配置档开啟/关闭一些功能。

cd /etc/csf
sed -i 's/^TESTING =.*/TESTING = "0"/' csf.conf
sed -i 's/^TCP_IN =.*/TCP_IN = "21,22,9091,51413,30000:35000"/' csf.conf
sed -i 's/^TCP_OUT =.*/TCP_OUT = "1:65535"/' csf.conf
sed -i 's/^UDP_IN =.*/UDP_IN = "20,21,51413"/' csf.conf
service csf restart
####### 遭遇CC攻击解决方法 #######

安装 CSF,然后用这个脚本(前提你是LNMP)

#!/bin/bash
#Collecting list of ip addresses connected to port 80
netstat -plan|grep :80|awk {‘print $5′}|cut -d: -f 1|sort|uniq -c|sort -nk 1 >
/root/iplist
#Limit the no of connections
LIMIT=15;

for ip in `cat /root/iplist |awk ‘{print $2}’`;do

if [ `grep $ip /root/iplist | awk '{print $1}'` -gt $LIMIT ]
then
echo “15 connection from $ip… `grep $ip /root/iplist | awk ‘{print $1}’` number of connections… Blocking $ip”;

#Blocking the ip …

CHECK_IF_LOCALIP=0;
/sbin/ifconfig | grep $ip > /dev/null;
if [ $? -ne $CHECK_IF_LOCALIP ]
then {
FLAG=0;
grep $ip /etc/csf/csf.deny > /dev/null;
if [ $? -ne $FLAG ]
then
iptables -I INPUT -s $ip -j DROP;
echo “deny $ip;” >> /usr/local/nginx/conf/vhost/block.conf;
/usr/sbin/csf -d $ip;
~/lnmp reload;
else
echo ” Ipaddress $ip is already blocked “;
fi
}
else
echo ” Sorry, the ip $ip cannot be blocked since this is a local ip of the server “;
fi
fi
done




歡迎光臨 比思論壇 (http://108.170.10.234/) Powered by Discuz! X2.5