Apache模块mod_evasive利用Hash表储存相应的HTTP请求,利用设定规则判断是否拒绝对方的请求。
安装:
1 2 3 4 5 6 | wget http: //www .zdziarski.com /blog/wp-content/uploads/2010/02/mod_evasive_1 .10.1. tar .gz tar zxvf mod_evasive_1.10.1. tar .gz cd mod_evasive/ apxs -i -a -c mod_evasive20.c #编译、安装、并加载模块 |
配置mod_evasive:
1 2 3 4 5 6 7 8 9 10 11 12 13 | <IfModule mod_evasive20.c> DOSHashTableSize 3097 #表大小 DOSPageCount 2 #限制单位时间内同一IP请求同一网页次数 DOSSiteCount 10 #限制单位时间内同一IP请求网站次数 DOSPageInterval 1 #网页存取间隔 DOSSiteInterval 1 #网站存取间隔 DOSBlockingPeriod 10 #限制访问时间 DOSEmailNotify #疑似攻击时邮件通知 DOSSystemCommand "su - onovps -c iptables -I INPUT -s %s --dport 80 -j DROP" #疑似攻击时用防火墙限制IP访问80端口 DOSLogDir "/var/log/ #日志目录 DOSWhiteList 127.0.0.1 #添加白名单 </IfModule> |
重启Apache生效:
1 | /etc/init .d /httpd restart |
同时作者还提供了一个测试程序用以测试mod_evasive是否生效:
1 2 3 | perl test.pl HTTP/1.1 200 OK HTTP/1.1 403 Forbidden |