Apache防御DDOS攻击,apache防御ddos


mod_evasive_1.10.1分布式拒绝服务(DDoS:Distributed Denial of Service)攻击指借助于客户/服务器技术,将多个计算机联合起来作为攻击平台,对一个或多个目标发动DDoS攻击,从而成倍地提高拒绝服务攻击的威力。因被DDOS攻击和恶意刷新导致Apache运行异常,占用资源过大,现在新发现一个很好的解决方法.基本上都通过安装mod_evasive模块得到了较好的解决。

下面我就来以我在CentOS 6.6上安装基于Apache2.4.6的mod_evasive经过给大家分享一下经验,顺便进一步讲述一下mod_evasive的特性。
mod_evasive通过对来访IP地址和访问URI建立内部动态哈希表来检测是否有攻击,如果有如下的行为将拒绝该IP的访问:
1. 每秒对同一页面的请求数超过平时(原文:Requesting the same page more than a few times per second)。
2. 每秒同一个子进程有超过50次的并发请求。
3. 临时被拒绝(在blacklist中)的时候还不断进行请求。
mod_evasive可以非常方便的和防火墙、路由器等进行整合,进一步提高抗拒绝服务的能力。
和别的防攻击工具一样,mod_evasive同样收到带宽、系统处理能力等因素的影响,所以要想应对大规模的攻击,最好的方式就是把mod_evasive和您的防火墙和路由器进行整合,而不是简单的安装成为独立的Apache模块。

mod_evasive在Apache2.4.6上的两种安装方式:
一、使用源码安装:
[cc lang="bash" escaped="true"][root@apache ~]# cd /usr/local/src
[root@src ~]# wget http://www.leixuesong.cn/wp-content/uploads/2015/03/mod_evasive_1.10.1.tar.gz
[root@src ~]# tar -zxvf mod_evasive_1.10.1.tar.gz
[root@mod_evasive ~]# cd mod_evasive
[root@mod_evasive ~]# /usr/local/apache/bin/apxs -i -a -c mod_evasive20.c[/cc]
说明:动态编译apache, 这里编译mod_evasive20.c是应对2.X版本的apache,如果是1.x版本的apache则编译mod_evasive.c就行了
二、yum安装
[cc lang="bash" escaped="true"][root@apache ~]yum install mod_evasive

#############################################################
Libraries have been installed in:
/usr/local/apache/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,-rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
chmod 755 /usr/local/apache/modules/mod_evasive20.so
[activating module `evasive20' in /usr/local/apache/conf/httpd.conf]

##############################################################
表示已经编译写入了apache模块
查看httpd.conf文件中已经自动添加了
LoadModule evasive20_module modules/mod_evasive20.so[/cc]

至此,重启Apache服务后,可以使用默认配置为您提供良好的防攻击能力,当然,您也可以自己进行一些参数的定制配置,添加如下参数:
[cc lang="vim" escaped="true"]<IfModule mod_evasive20.c>
DOSHashTableSize 3097
DOSPageCount 5
DOSSiteCount 50
DOSPageInterval 2
DOSSiteInterval 2
DOSBlockingPeriod 10
</IfModule>[/cc]

参数简单说明:
DOSHashTableSize 3097 记录和存放黑名单的哈西表大小,如果服务器访问量很大,可以加大该值
DOSPageCount 5 同一个页面在同一时间内可以被统一个用户访问的次数,超过该数字就会被列为攻击,同一时间的数值可以在DosPageInterval参数中设置。
DOSSiteCount 50 同一个用户在同一个网站内可以同时打开的访问数,同一个时间的数值在DOSSiteInterval中设置。
DOSPageInterval 2 设置DOSPageCount中时间长度标准,默认值为1。
DOSSiteInterval 2 设置DOSSiteCount中时间长度标准。
DOSBlockingPeriod 10 被封时间间隔秒,这中间会收到 403 (Forbidden) 的返回。

其他可选参数:
DOSEmailNotify 475216037@qq.com 设置受到攻击时接收攻击信息提示的邮箱地址。
DOSSystemCommand “su – someuser -c ‘/sbin/… %s …’” 受到攻击时Apache运行用户执行的系统命令
DOSLogDir “/var/lock/mod_dosevasive” 攻击日志存放目录/var/lock/mod_dosevasive 一般就可以存放到/tmp目录

相关内容

    暂无相关文章