我的Apache安全模块mod_evasive配置

来源:互联网 发布:查尔斯软件使用教程 编辑:程序博客网 时间:2024/05/16 11:02
首先Apache的版本是:2.4
mod_evasive的主页是:(现在的版本是:mod_evasive_1.10.1.tar.gz)
http://www.zdziarski.com/blog/?page_id=442
根据READEME中的步骤:
APACHE v2.0
-----------
1. Extract this archive
2. Run $APACHE_ROOT/bin/apxs -i -a -c mod_evasive20.c
3. The module will be built and installed into $APACHE_ROOT/modules, and loaded into your httpd.conf
4. Restart Apache
安装后出现以下错误:
error: 'conn_rec' has no member named 'remote_ip'
解决方法是:将remote_ip替换成client_ip.

开始的httpd.conf的配置是:
<IfModule mod_evasive20.c>
    DOSHashTableSize    5097
    DOSPageCount       9
    DOSSiteCount        150
    DOSPageInterval     2
    DOSSiteInterval     2
    DOSBlockingPeriod   110
    #DOSSystemCommand  "sudo /sbin/iptables -I INPUT -s %s -p tcp --dport 80 -j DROP"
    #DOSSystemCommand "su - root c '/sbin/iptables -I INPUT -s %s -p tcp --dport 80 -j DROP'"
</IfModule>
两种命令都有试过,但是都没有效果(每次修改配置文件都重启了Apache)。报如下错误:
can't initialize iptables table `filter': Permission denied (you must be root)
sudo: sorry, you must have a tty to run sudo
standard in must be a tty
sudo: no tty present and no askpass program specified

1.使用:ssh -t remotehost "sudo ./binary" 方式,最后失败
2.将Apache的用户apache设为root权限,不安全放弃。
3.用visudo编辑添加:
User_Alias  APACHE = apache
Cmnd_Alias  FIREWALL = /sbin/iptables,/sbin/ifconfig,/sbin/route
APACHE ALL =(ALL) NOPASSWD: FIREWALL
发现无效,然后又将Defaults    requiretty注释,仍然无效。。。。。

尝试失败后,将mod_evasive文件夹删除,重新tar解压一份,覆盖安装。更改remote_ip。
建立sh文件,apache.sh,写入:
##!/bin/bash
sudo /sbin/iptables -I INPUT -s $1 -p tcp --dport 80 -j DROP
保存退出,chmod +x apache.sh
然后配置Apache的http.conf文件:
<IfModule mod_evasive20.c>
    DOSHashTableSize    5097
    DOSPageCount      5
    DOSSiteCount        50
    DOSPageInterval     1
    DOSSiteInterval     1
    DOSBlockingPeriod   10
    DOSSystemCommand "sh /usr/local/apache.sh %s"
</IfModule>
sudoers文件保持上面visudo的配置不变,重新启动Apache。进行测试,发现页面卡住,
使用iptables-save发现测试ip已经添加到iptables之中。
配置成功!

0 0
原创粉丝点击