【问题标题】:Secure server with Fail2ban and Docker使用 Fail2ban 和 Docker 保护服务器
【发布时间】:2016-06-23 15:37:11
【问题描述】:

我在 docker 容器中使用 nginx,我可以轻松地与主机共享我的 nginx docker 容器上的日志文件。日志就在上面并在/var/log/nginx 文件夹上工作。

我已经在主机上安装了 fail2ban 来检查日志文件,特别是 access.log

我测试了一个简单的过滤器

# Fail2Ban configuration file
# Author: Miniwark

[Definition]
failregex = ^<HOST> .*"GET .*w00tw00t
# try to access to admin directory
            ^<HOST> .*"GET .*admin.* 403
            ^<HOST> .*"GET .*admin.* 404
# try to access to install directory
            ^<HOST> .*"GET .*install.* 404
# try to access to phpmyadmin
            ^<HOST> .*"GET .*dbadmin.* 404
            ^<HOST> .*"GET .*myadmin.* 404
            ^<HOST> .*"GET .*MyAdmin.* 404
            ^<HOST> .*"GET .*mysql.* 404
            ^<HOST> .*"GET .*websql.* 404
            ^<HOST> .*"GET \/pma\/.* 404
# try to access to wordpress (we use another CMS)
            ^<HOST> .*"GET .*wp-content.* 404
            ^<HOST> .*"GET .*wp-login.* 404
# try to access to typo3 (we use another CMS)
            ^<HOST> .*"GET .*typo3.* 404
# try to access to tomcat (we do not use it)      
            ^<HOST> .*"HEAD .*manager.* 404
# try to access various strange scripts and malwares
            ^<HOST> .*"HEAD .*blackcat.* 404
            ^<HOST> .*"HEAD .*sprawdza.php.* 404

ignoreregex = 

我很容易在/etc/fail2ban/jail.local激活它

[nginx-nokiddies]
# ban script kiddies
enabled  = true
port     = http,https
filter   = nginx-nokiddies
logpath  = /var/log/nginx*/*access.log
maxretry = 1

我重新启动/停止/启动/重新加载 fail2ban 服务。然后我用

测试这个正则表达式
fail2ban-regex /var/log/nginx/access.log /etc/fail2ban/filter.d/nginx-nokiddies.conf

它匹配数千行,尤其是任何 admin 请求。

主要问题是fail2ban 不能自动工作,所以不能像以前那样发送邮件。事实上,当我直接在主机上使用 nginx 安装时,它可以完美运行。

日志是基本格式,像这样调用“组合”格式:

log_format combined '$remote_addr - $remote_user [$time_local]  '
            '"$request" $status $body_bytes_sent '
            '"$http_referer" "$http_user_agent"';

没有权限问题,因为我的 nginx 容器及其子容器是完全权限 (777) 可以肯定的是,我当然会更改它!

为什么fail2ban进程不禁止ip并且不匹配docker?

【问题讨论】:

    标签: logging docker fail2ban


    【解决方案1】:

    您可以在主机上安装 fail2ban,然后将访问日志文件从 nginx 容器映射到您的主机。像docker run -v /path/in/host:/var/log/nginx/access.log nginx 这样的东西。然后在 fail2ban 中只引用该文件。

    【讨论】:

    • 你可能想要-v /var/log/nginx/access.log:/var/log/nginx/access.log
    猜你喜欢
    • 2019-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-14
    • 2011-03-08
    • 2014-05-28
    相关资源
    最近更新 更多