服务器被攻击怎么办

服务器被攻击怎么办,第1张

1、换高防IP或切换高防服务器流量攻击进入高防IP将异常流量清洗后,保留正常流量转到我们正常服务器IP。

2、网站业务添加CDN,预算充足的情况下可以考虑添加CDN,但是大流量的攻击可能产生高额CDN费用,需要酌情考虑。

3、定期排查服务器安全漏洞,及时修补服务器漏洞,防止被黑客利用漏洞进行服务器攻击。

4、设置防火墙,防火墙是可以在部分攻击上打到抵御的效果的,禁用一些不用的端口防止非法分子利用其端口进行攻击,同时可以通过防火墙设置把攻击重定向。

5、提升服务器配置,一般的攻击如果不是非常猛烈,可以适当提升服务器带宽,CPU和内存,保证资源不被攻击消耗殆尽。

6、通过反向路由进行ip真实性检测,禁用非真实IP也可以防御攻击。

7、限制SYN/ICMP流量,在路由器上配置SYN/ICMP的最大流量限制SYN/ICMP封包所能占有的最高频宽,大量的异常流量那基本上就是攻击了。

8、过滤所有RFC1918,IP地址RFC1918是内部网的IP地址,过滤攻击时伪造的大量虚假内部IP,也是能减轻攻击DDOS攻击。

由于工作需要我就自己写了一个简单的防止IP攻击的脚本,可以防止linux虚拟主机一些小方面的IP攻击系统是基于RHEL的centos,包括3,4,5三个版本,当然自己也初学shell,中间肯定用了很多笨的办法,效果也不一定怎么样,请大家给点意见注意:这个脚本是根据apache服务器的server-status和系统的dmesg分析结果进行防范的,所以非apache用户和没有开启server-status的朋友没法使用可以在服务器的crontab里设定每一分钟运行一次脚本, 复制下面的脚本到autoblock.sh,root用户下# chmod u+x autoblock.shQUOTE:#!/bin/bash# author hao32# basic settingecho 1 >/proc/sys/net/ipv4/tcp_syncookies# find server-status namess_name="/usr/local/autoblock"if [ -e $ss_name/ss_name ]thenss_n=`cat $ss_name/ss_name`elsemkdir /usr/local/autoblock >/dev/null 2>&1cat `locate httpd.conf|grep -E "httpd/conf/httpd.conf$|apache_ssl/conf/httpd.conf$"`\|grep "n /server-status"|cut -d/ -f2|cut -d\>-f1 >$ss_name/ss_namess_n=`cat $ss_name/ss_name`fi# block setting# 设定排除的IP地址ip_exclude="192.168.1.*|60.195.249.*|222.76.212.*|218.241.156.*|58.215.87.*|218.107.216.110"ip_amou=25ss_url=" http://127.0.0.1/$ss_n?notable "ss_tmp="/tmp/server-status"poss_ip="/tmp/poss_ip"real_ip="/tmp/real_ip"# block start...if [ -e "$poss_ip" ]thenecho "" >$poss_ipfiif [ -e "$real_ip" ]thenecho "" >$real_ipfi# analyse demsgdmesg |grep "short"|awk '{if($4!="From"){print $4} else {print $5}}'|awk -F: '{print $1}'|sort|uniq>>$poss_ipwget -q -O "$ss_tmp" "$ss_url"grep " " $ss_tmp|grep -vE $ip_exclude|awk '{print $1}'|sed 's/ //g'|sort|uniq -c\|awk '{if($1>'$ip_amou') print $2}'>>$poss_ip#iptables -nvL|grep "DROP "|awk '{print $8}'|sort|uniq|sed 's/0\/24/*/g'>$rule_iprule_ip=`iptables -nvL|grep "DROP "|awk '{print $8}'|sort|uniq|sed 's/0\/24/*/g'|xargs|sed 's/\ /|/g'`if [ -z $rule_ip ]thenfor i in `cat $poss_ip`do/sbin/iptables -I INPUT -p all -s $i -j DROPdoneelsecat $poss_ip|grep -vE "$rule_ip" >$real_ipfor i in `cat $real_ip`do/sbin/iptables -I INPUT -p all -s $i -j DROPdonefi


欢迎分享,转载请注明来源:夏雨云

原文地址:https://www.xiayuyun.com/zonghe/202809.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-02
下一篇2023-04-02

发表评论

登录后才能评论

评论列表(0条)

    保存