我的Apache安全模块mod_evasive配置

本文介绍了在Apache 2.4版本上安装和配置mod_evasive模块的过程,包括解决`conn_rec`远程IP错误,以及处理iptables权限问题。通过修改httpd.conf,设置DOS防御参数,并创建执行脚本来绕过sudo限制。最终,通过测试验证配置成功。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先Apache的版本是:2.4
mod_evasive的主页是:(现在的版本是: mod_evasive_1.10.1.tar.gz
根据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之中。
配置成功!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值