Centos SeLinux阻止mod evasive(Apache)作为sudo运行命令
我正在尝试在CENTOS7服务器(VPS)中配置mod_evasive以防止DDOS攻击 我遵循了以下教程中提到的步骤。()虽然我没有使用IPTABLES,但我使用的是firewalld 在mod_evasive中,当IP被列入黑名单时执行shell命令的指令是Centos SeLinux阻止mod evasive(Apache)作为sudo运行命令,centos,selinux,mod-evasive,Centos,Selinux,Mod Evasive,我正在尝试在CENTOS7服务器(VPS)中配置mod_evasive以防止DDOS攻击 我遵循了以下教程中提到的步骤。()虽然我没有使用IPTABLES,但我使用的是firewalld 在mod_evasive中,当IP被列入黑名单时执行shell命令的指令是DOSSystemCommand。但是当一个IP被阻止时,我想要运行的脚本会将IP地址提交给firewalld进行阻止,它会被SeLinux阻止。根据我在查看audit.log后了解到的情况,SeLinux不允许apache用户像sudo
DOSSystemCommand
。但是当一个IP被阻止时,我想要运行的脚本会将IP地址提交给firewalld进行阻止,它会被SeLinux阻止。根据我在查看audit.log后了解到的情况,SeLinux不允许apache用户像sudo一样运行命令。即使这是通过sudoers文件允许的
(mod_evasive工作正常,我通过运行mod_evasive提供的测试脚本验证了这一点。当IP被阻止时,我还会收到电子邮件)
具体内容如下:
mod_evasive.conf文件(仅DOSSystemCommand指令如下所示)
我也尝试过下面的变化(使用不同的用户,例如root用户)
Sudoers文件(只有我为此修改的部分[允许apache以sudo的身份运行])
我允许apache作为任何用户运行所有脚本,只是为了测试
apache ALL=NOPASSWD: /usr/local/bin/myscripts/ban_ip.sh
Defaults:apache !requiretty
我的ban_ip.sh文件
#!/bin/sh
# IP that will be blocked, as detected by mod_evasive
IP=$1
sudo firewall-cmd --add-rich-rule 'rule family="ipv4" source address="`$IP" service name="https" reject'
我已通过运行以下命令验证配置是否正常工作
sudo -u apache '/usr/local/bin/myscripts/ban_ip.sh 111.111.111.111'
上面的命令成功地将规则添加到firewalld
当我禁用SeLinux时,整个设置工作正常
启用SeLinux后,audit.log中会出现以下错误
type=AVC msg=audit(1593067671.808:1363): avc: denied { setuid } for pid=3332 comm="sudo" capability=7 scontext=system_u:system_r:httpd_sys_script_t:s0 tcontext=system_u:system_r:httpd_sys_script_t:s0 tclass=capability permissive=0
Was caused by:
Missing type enforcement (TE) allow rule.
You can use audit2allow to generate a loadable module to allow this access.
type=AVC msg=audit(1593067671.808:1364): avc: denied { setgid } for pid=3332 comm="sudo" capability=6 scontext=system_u:system_r:httpd_sys_script_t:s0 tcontext=system_u:system_r:httpd_sys_script_t:s0 tclass=capability permissive=0
Was caused by:
Missing type enforcement (TE) allow rule.
You can use audit2allow to generate a loadable module to allow this access.
以下标志在SeLinux中设置
httpd_mod_auth_pam
httpd_setrlimit
我不知道为什么SeLinux会阻止这种行为,因此我怀疑是否会像audit2allow建议的那样创建一个允许这种行为的自定义策略
审核2允许输出
#============= httpd_sys_script_t ==============
allow httpd_sys_script_t self:capability { setgid setuid };
#============= httpd_t ==============
allow httpd_t systemd_logind_t:dbus send_msg;
我觉得如果我们不能阻止IP,而不仅仅是向攻击者发送403禁止的
响应,mod_evasive将无助于阻止DDOS。这仍然会消耗服务器资源
我如何解决这个问题,以及我可以实施哪些其他替代方案来缓解DDOS并增强我的VPS保护
谢谢你的帮助
type=AVC msg=audit(1593067671.808:1363): avc: denied { setuid } for pid=3332 comm="sudo" capability=7 scontext=system_u:system_r:httpd_sys_script_t:s0 tcontext=system_u:system_r:httpd_sys_script_t:s0 tclass=capability permissive=0
Was caused by:
Missing type enforcement (TE) allow rule.
You can use audit2allow to generate a loadable module to allow this access.
type=AVC msg=audit(1593067671.808:1364): avc: denied { setgid } for pid=3332 comm="sudo" capability=6 scontext=system_u:system_r:httpd_sys_script_t:s0 tcontext=system_u:system_r:httpd_sys_script_t:s0 tclass=capability permissive=0
Was caused by:
Missing type enforcement (TE) allow rule.
You can use audit2allow to generate a loadable module to allow this access.
httpd_mod_auth_pam
httpd_setrlimit
#============= httpd_sys_script_t ==============
allow httpd_sys_script_t self:capability { setgid setuid };
#============= httpd_t ==============
allow httpd_t systemd_logind_t:dbus send_msg;