当前位置 主页 > 服务器问题 > Linux/apache问题 >

    配置fail2ban对Apache服务器进行安全防护的方法(3)

    栏目:Linux/apache问题 时间:2019-02-21 14:08


        enabled  = true
        port     = http,https
        filter   = apache-noscript
        logpath  = /var/log/httpd/*error_log
        maxretry = 6
        # 检测 Apache 溢出攻击
        [apache-overflows]
        enabled  = true
        port     = http,https
        filter   = apache-overflows
        logpath  = /var/log/httpd/*error_log
        maxretry = 2
        # 检测在服务器寻找主目录的尝试
        [apache-nohome]
        enabled  = true
        port     = http,https
        filter   = apache-nohome
        logpath  = /var/log/httpd/*error_log
        maxretry = 2
        # 检测执行不存在的脚本的企图
        # 这些都是流行的网站服务程序
        # 如:webmail, phpMyAdmin,WordPress
        port     = http,https
        filter   = apache-botsearch
        logpath  = /var/log/httpd/*error_log
        maxretry = 2

    注意这些监狱文件默认的操作是iptables-multiport(定义在/etc/fail2ban/jail.conf中[DEFAULT]字段下的“banaction”中)。这个措施使用iptable的多端口模块禁止一个IP地址。

    启用监狱后,你必须重启fail2ban来加载监狱。

    在 Fedora 或者 CentOS/RHEL 7中:

      $ sudo systemctl restart fail2ban 

    在 CentOS/RHEL 6中:

      $ sudo service fail2ban restart 

    检查和管理fail2ban禁止状态

    监狱一旦激活后,你可以用fail2ban的客户端命令行工具来监测当前的禁止状态。

    查看激活的监狱列表:

      $ sudo fail2ban-client status 

    查看特定监狱的状态(包含禁止的IP列表):

      $ sudo fail2ban-client status [监狱名] 

    201561195749494.jpg (800×298)

        你也可以手动禁止或者解禁IP地址:

    要用制定监狱禁止IP:

      $ sudo fail2ban-client set [name-of-jail] banip [ip-address] 

    要解禁指定监狱屏蔽的IP:

      $ sudo fail2ban-client set [name-of-jail] unbanip [ip-address] 

    总结

    本篇教程解释了fail2ban监狱如何工作以及如何使用内置的监狱来保护Apache服务器。依赖于你的环境以及要保护的web服务器类型,你或许要调整已有的监狱或者编写自定义监狱和日志过滤器。查看outfail2ban的官方Github页面来获取最新的监狱和过滤器示例。