【问题标题】:Use bash script in Fail2Ban Configuration在 Fail2Ban 配置中使用 bash 脚本
【发布时间】:2018-03-14 13:36:48
【问题描述】:

我想在Fail2Ban 的邮件中调用一个bash 脚本。 bash脚本调用rest api获取fail2ban被屏蔽ip地址的用户名。

# Fail2Ban configuration file
#
# Author: *
#
#

[INCLUDES]

before = sendmail-common.conf

[Definition]

# Option:  actionban
# Notes.:  command executed when banning an IP. Take care that the
#          command is executed with Fail2Ban user rights.
# Tags:    See jail.conf(5) man page
# Values:  CMD
#
actionban = printf %%b "Subject: [Fail2Ban] <name>: banned <ip> from `uname -n`
            Date: `LC_ALL=C date +"%%a, %%d %%h %%Y %%T %%z"`
            From: <sendername> <<sender>>
            To: <dest>\n
            The following IP <ip> has just been banned by Fail2Ban after <failures> attempts against the acceptance environment of <name> on server.\n
            One or the following users could be the victim: \n 
            `/etc/fail2ban/restapi/getHttpSessions.sh | grep <ip>` \n | /usr/sbin/sendmail -f <sender> <dest>

[Init]

但是我在 fail2ban 日志中发现没有发送电子邮件的错误

`/bin/sh /etc/fail2ban/scripts/getHttpSessions.sh | grep` 10.100.00.00 \n |/usr/sbin/sendmail -f fail2ban test@test.com -- returned 1

有没有办法在 fail2ban 配置文件中使用 bash 脚本来查找 bash 创建的概述中的 IP 地址?

谢谢!

【问题讨论】:

    标签: bash sendmail fail2ban


    【解决方案1】:

    我让它工作了。可能是语法中的一些问题。工作代码:

    # Fail2Ban configuration file
    #
    # Author: Danny van den Berg
    #
    #
    
    [INCLUDES]
    
    before = sendmail-common.conf
    
    [Definition]
    
    # Option:  actionban
    # Notes.:  command executed when banning an IP. Take care that the
    #          command is executed with Fail2Ban user rights.
    # Tags:    See jail.conf(5) man page
    # Values:  CMD
    #
    actionban = printf %%b "Subject: [Fail2Ban] <name>: banned <ip> from `uname -n`
                Date: `LC_ALL=C date +"%%a, %%d %%h %%Y %%T %%z"`
                From: <sendername> <<sender>>
                To: <dest>\n
                The following IP <ip> has just been banned by Fail2Ban after <failures> attempts against the production environment of <name> on server.\n
                More information about the user:\n 
                [IP            | KEY] \n
                `/usr/bin/gethttpsessions | grep <ip> `\n\n" | /usr/sbin/sendmail -f <sender> <dest>
    
    [Init]
    
    # Default name of the chain
    #
    name = default
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-15
      • 2015-10-20
      • 1970-01-01
      相关资源
      最近更新 更多