AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题

问题[fail2ban](server)

Martin Hope
Kevin Renskers
Asked: 2024-06-02 21:31:52 +0800 CST

Nginx 的 limit_req + failure2ban:IP 地址被禁止,但仍然可以访问该网站

  • 5

我已经成功设置了 Nginx 的 limit_req 模块,这样当任何人尝试访问我们的服务器(我们根本不托管)上的 PHP 文件时,他们都会得到 503。请参阅有关我的设置的问题,包括配置。

现在我想在此基础上添加一个fail2ban 监狱,这样尝试访问PHP 文件的人就会被禁止一段时间。我似乎已经成功了:当我连续多次访问 PHP 地址时,我确实看到了有关将我的地址添加到监狱的fail2ban 日志条目。但是,我仍然可以正常访问该网站,我根本没有被真正禁止。

/etc/fail2ban/filter.d/nginx-limit-req.conf:

[Definition]
ngx_limit_req_zones = deny_rules
failregex = ^\s*\[[a-z]+\] \d+#\d+: \*\d+ limiting requests, excess: [\d\.]+ by zone "(?:%(ngx_limit_req_zones)s)", client: <HOST>,
ignoreregex =
datepattern = {^LN-BEG}

/etc/fail2ban/jail.local:

[nginx-limit-req]
port    = http,https
logpath = %(nginx_error_log)s
enabled = true
bantime  = 2h
maxretry = 1

当我重复访问我们服务器上的 .php 地址时,会发生以下情况。我确实认为禁令的实施效果很好:

tail -f /var/log/fail2ban.log

2024-06-03 10:38:33,921 fail2ban.filter         [3816728]: INFO    [nginx-limit-req] Found 81.204.117.221 - 2024-06-03 10:38:33
2024-06-03 10:38:34,242 fail2ban.actions        [3816728]: NOTICE  [nginx-limit-req] 81.204.117.221 already banned

是的,该地址已添加到防火墙中:

iptables -S | grep f2b:

iptables -S | grep f2b
-N f2b-nginx-limit-req
-N f2b-sshd
-A INPUT -p tcp -m multiport --dports 80,443 -j f2b-nginx-limit-req
-A INPUT -p tcp -m multiport --dports 22 -j f2b-sshd
-A f2b-nginx-limit-req -s 81.204.117.221/32 -j REJECT --reject-with icmp-port-unreachable

我在这里缺少哪一块拼图?为什么我仍然可以访问该网站?我们在 Debian 11 上使用fail2ban v0.11.2,UFW 在幕后支持。

fail2ban
  • 1 个回答
  • 60 Views
Martin Hope
xstack
Asked: 2024-01-28 07:01:08 +0800 CST

尝试了解fail2ban是否可以在Debian 10 VPS上运行

  • 5

我有一台在 VPS 上运行的 Debian 10 服务器。我安装的唯一软件是:tinyproxy(http代理)和fail2ban

我已经包含了使用 nmap 进行端口扫描的结果

我已将我的具体设置包含在fail2ban jam.local 文件中。

我已将我的具体设置包含在fail2ban failure2ban.local 文件中。

我在下面提供了来自身份验证日志的条目示例。

我在下面包含了fail2ban 日志中的条目示例。

我已经包含了 IpTables 样本扫描的结果。

我不明白fail2ban 是否起作用,即根据fail2ban 所做的IP 表中的条目导致IP 被阻止。

例如:

== auth.log 几乎每分钟都会显示 192.241.141.43 尝试输入的信息

==fail2ban.log显示192.241.141.43被禁止

== iptables显示192.241.141.43被禁止

我认为基于 IP 被阻止,恶意用户将无法尝试登录。然而,这些用户似乎确实能够尝试登录。

我的问题,请:

  1. 看来fail2ban 正在工作吗?
  2. 为什么恶意用户在被禁止的情况下仍可以尝试登录?

非常感谢 !

=== === nmap 扫描结果

# Nmap 7.80 扫描于 2024 年 1 月 27 日星期六 15:25:04 启动为:nmap -sS -oG out.txt

107.174.156.124

主机:107.174.156.124 (107-174-156-124-host.colocrossing.com)   
地位:
向上
主机:107.174.156.124 (107-174-156-124-host.colocrossing.com)   
端口:
139/过滤/tcp//netbios-ssn///,
445/过滤/tcp//微软-ds///,
8888/open/tcp//sun-answerbook///    
忽略状态:关闭(997)

# Nmap 于 2024 年 1 月 27 日星期六 15:25:06 完成
-- 2.20 秒内扫描 1 个 IP 地址(1 个主机)

=== === 这是我在jail.local中的条目

#
# 监狱
#

#
# SSH 服务器
#

[sshd]

# 要使用更激进的 sshd 模式,请在 Jail.local 中设置过滤器参数“mode”:
# 正常(默认)、ddos、额外或攻击性(全部组合)。
# 有关使用示例和详细信息,请参阅“tests/files/logs/sshd”或“filter.d/sshd.conf”。
#模式=正常
启用=真
模式=激进
端口 = 63xxx
过滤器=sshd
日志路径 = /var/log/auth.log
班时间 = 2000000
查找时间 = 7200
最大重试次数 = 2
后端 = %(sshd_backend)s
操作= iptables-multiport [名称= sshd,端口=“ssh”,协议= tcp]

=== === 这是我在fail2ban.local中的条目

# 选项:dbpurgeage
# 注意:设置应从数据库中清除禁令的年龄
# 值:[ SECONDS ] 默认值:86400(24 小时)
数据库清除 = 2100000

=== === 这是示例身份验证日志

例如,192.241.141.43 进行了多次尝试,并且几乎每分钟都会重复一次!

1 月 27 日 15:54:55racknerd-64d010 sshd[2232]: pam_unix(sshd:auth): 身份验证失败;logname= uid=0 euid=0 tty=ssh ruser= rhost=192.241.141.43 user=root
Jan 27 15:54:57racknerd-64d010 sshd[2232]:来自 192.241.141.43 端口 54798 ssh2 的 root 密码失败
1 月 27 日 15:54:57racknerd-64d010 sshd[2232]:从 192.241.141.43 端口 54798:11 收到断开连接:再见 [preauth]
1 月 27 日 15:54:57racknerd-64d010 sshd[2232]:与验证用户 root 192.241.141.43 端口 54798 [preauth] 断开连接

=== === 这是fail2ban的示例

例如,fail2ban 表示 192.241.141.43 已被禁止

2024-01-27 15:55:50,928 failed2ban.actions [29992]:警告 [sshd] 82.102.12.130 已被禁止
2024-01-27 15:55:50,929 failed2ban.actions [29992]:警告 [sshd] 192.241.141.43 已被禁止
2024-01-27 15:55:50,929 failed2ban.actions [29992]:警告 [sshd] 159.75.161.40 已被禁止

=== === Iptables 扫描结果

IP 192.241.141.43 被禁止

    0 0 拒绝全部 -- * * 61.231.64.170 0.0.0.0/0 拒绝 icmp 端口不可达
    0 0 拒绝全部 -- * * 192.241.141.43 0.0.0.0/0 拒绝 icmp 端口不可达
    0 0 拒绝全部 -- * * 104.250.34.177 0.0.0.0/0 拒绝 icmp 端口不可达
fail2ban
  • 1 个回答
  • 96 Views
Martin Hope
Nick Coons
Asked: 2023-06-03 06:08:48 +0800 CST

Fail2Ban - 匹配 Asterisk PJSIP 认证成功

  • 6

我正在尝试创建一个 fail2ban 过滤器来匹配成功的身份验证。示例日志条目如下所示:

[2023-05-25 18:41:00] VERBOSE[26149] res_pjsip/pjsip_options.c: Contact user/sip:[email protected]:47682;transport=ws;x-ast-orig-host=b0cnalpndgjm.invalid:0 is now Reachable.  RTT: 27.843 msec

我不精通创建 fail2ban 过滤器,但这是我的尝试(我首先将 filter.d 中的 asterisk.conf 复制到 asterisk-whitelist.conf 以用作模板,然后更改 failregex 以尝试匹配类似的行以上):

[INCLUDES]

# Read common prefixes. If any customizations available -- read them from
# common.local
before = common.conf

[Definition]

_daemon = asterisk

__pid_re = (?:\s*\[\d+\])

iso8601 = \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+[+-]\d{4}

# All Asterisk log messages begin like this:
log_prefix= (?:NOTICE|SECURITY|WARNING)%(__pid_re)s:?(?:\[C-[\da-f]*\])? [^:]+:\d*(?:(?: in)? \w+:)?

prefregex = ^%(__prefix_line)s%(log_prefix)s <F-CONTENT>.+</F-CONTENT>$

failregex = ^Contact [A-Za-z0-9]+/sip:[A-Za-z0-9]+@<HOST>:[0-9]+;transport=[A-Za-z]+;[A-Za-z]+=[A-Za-z0-9\.]+:0 is now Reachable\.  RTT: [0-9]*\.[0-9]+ msec$
ignoreregex =

以上不起作用。我不是特别确定如何解决此问题,或者需要进行哪些更改才能匹配。结果fail2ban-regex /var/log/asterisk/full asterisk-whitelist.conf显示 0 个匹配项。

已更新以在已接受答案的帮助下添加最终解决方案。这是最终对我有用的配置:

[INCLUDES]
# Read common prefixes. If any customizations available -- read them from
# common.local
before = common.conf

[Definition]
_daemon = asterisk

__pid_re = (?:\s*\[\d+\])

iso8601 = \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+[+-]\d{4}

# All Asterisk log messages begin like this:
log_prefix= (?:NOTICE|SECURITY|WARNING|VERBOSE)%(__pid_re)s:?(?:\[C-[\da-f]*\])? [^:]+:\d*(?:(?: in)? \w+:)?

prefregex = ^%(__prefix_line)s%(log_prefix)s <F-CONTENT>.+</F-CONTENT>$

failregex = ^.*Contact .*\/sip[s]?:.*@<HOST>.* is now Reachable.*

ignoreregex =
fail2ban
  • 1 个回答
  • 50 Views
Martin Hope
WSpivak
Asked: 2023-04-10 06:23:36 +0800 CST

fail2ban ipset 正确设置 jail.conf

  • 5

我的理解是使用 ipset 运行 Fail2ban 更快。为此:

我按照说明(针对 Fedora 37 进行了修改)从 Git 下载并安装了 ritsu/ipset-fail2ban。

我的banaction仍然设置为: banaction_allports = firewallcmd-rich-rules[actiontype=]

当我尝试添加或替换上面的内容时: banaction = firewallcmd-ipset

我收到如下错误:

2023-04-09 15:51:46,130 fail2ban.actions        [986]: NOTICE  [postfix-auth] Restore Ban 117.69.159.181
2023-04-09 15:51:46,526 fail2ban.utils          [986]: ERROR   7f29c6bd0ea0 -- exec: ipset -exist create f2b-postfix-unv hash:ip timeout 0
firewall-cmd --direct --add-rule ipv4 filter INPUT_direct 0 -p tcp -m multiport --dports smtp,imap2,imap3,imaps,pop3,pop3s,465,587, submission -m set --match-set f2b-postfix-unv src -j REJECT --reject-with icmp-port-unreachable
2023-04-09 15:51:46,527 fail2ban.utils          [986]: ERROR   7f29c6bd0ea0 -- stderr: "Error: COMMAND_FAILED: '/usr/sbin/iptables-restore -w -n' failed: iptables-restore v1.8.8 (legacy): invalid port/service `' specified"
2023-04-09 15:51:46,527 fail2ban.utils          [986]: ERROR   7f29c6bd0ea0 -- stderr: 'Error occurred at line: 2'
2023-04-09 15:51:46,527 fail2ban.utils          [986]: ERROR   7f29c6bd0ea0 -- stderr: "Try `iptables-restore -h' or 'iptables-restore --help' for more information."
2023-04-09 15:51:46,527 fail2ban.utils          [986]: ERROR   7f29c6bd0ea0 -- stderr: ''
2023-04-09 15:51:46,527 fail2ban.utils          [986]: ERROR   7f29c6bd0ea0 -- returned 13

如果我运行,firewall-cmd --list-all-zones我会得到一个当前被禁止的 IP 地址列表。

但是它们不在任何区域文件中/etc/firewalld/zones

$ iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
DROP       all  --  anywhere             anywhere             match-set blacklist-fail2ban src

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
DROP       tcp  --  anywhere             185.191.32.198       tcp dpt:http

如果我错了,我哪里错了?

谢谢

[附录 1]

根据 Ginnungagap 关于框架问题的建议,我对他关于尾随逗号的询问的回答是:

我的错误示​​例的 jail.local 是:

[postfix-unv] 
enabled = true 
filter = postfix-unv 
port = smtp,imap2,imap3,imaps,pop3,pop3s,465,587, submission 
logpath = /var/log/maillog 
maxretry = 1 
bantime = 604800

我没有看到额外的逗号。我也没有在实际过滤器中看到额外的逗号。我会研究nftables。

[附录 2]

按照你的建议改变banaction。当我发布 cmd nft list 规则集时,它似乎起作用了。

我重启了firewalld,它没有额外的规则(即rich sets)

我重新启动了 fail2ban,它在大约一分钟内加载了所有被禁止的规则。

我还需要 Git 中的文件吗(如上所述)?

谢谢 Ginnungagap,非常感谢您的帮助。

fail2ban
  • 1 个回答
  • 63 Views
Martin Hope
Gregory Schultz
Asked: 2023-03-02 19:10:21 +0800 CST

fail2ban:如何组合多个 failregex?

  • 5

failregex我在文件中添加多行时遇到问题jail.local。如果我有一根线,它会起作用,但如果我有两根线,它就不起作用。

这是我的 jail.local 配置:

[sshd]
enabled = true
logpath = %(sshd_log)s
port = 22
banaction = iptables-multiport
mode = aggressive
failregex = %(known/failregex)s
            ^Bad protocol version identification '.*' from <HOST>
failregex = %(known/failregex)s 
            ^runcloud\[\d+\]: echo: http: TLS handshake error from <ADDR>:\d+
fail2ban
  • 1 个回答
  • 11 Views
Martin Hope
Moso
Asked: 2022-04-18 06:28:47 +0800 CST

fail2ban 似乎正在工作,但服务器仍会收到连接尝试

  • 0

fail2ban 之谜!

一切似乎都运行良好且配置良好,但服务器仍会收到连接尝试。

[moso@matrix ~]$ sudo systemctl status fail2ban
● fail2ban.service - Fail2Ban Service
     Loaded: loaded (/usr/lib/systemd/system/fail2ban.service; enabled; vendor preset: disabled)
     Active: active (running) since Sat 2022-04-16 22:10:45 -03; 13h ago
       Docs: man:fail2ban(1)
    Process: 332 ExecStartPre=/bin/mkdir -p /run/fail2ban (code=exited, status=0/SUCCESS)
   Main PID: 335 (fail2ban-server)
      Tasks: 5 (limit: 19183)
     Memory: 17.9M
        CPU: 1min 945ms
     CGroup: /system.slice/fail2ban.service
             └─335 /usr/bin/python /usr/bin/fail2ban-server -xf start

Apr 16 22:10:45 matrix systemd[1]: Starting Fail2Ban Service...
Apr 16 22:10:45 matrix systemd[1]: Started Fail2Ban Service.
Apr 16 22:10:45 matrix fail2ban-server[335]: Server ready



[moso@matrix ~]$ sudo cat /etc/fail2ban/jail.d/sshd.local
[sshd]
  enabled   = true
  filter    = sshd
  banaction = iptables
  backend   = systemd
  maxretry  = 3
  findtime  = 1d
  bantime   = 2w
  ignoreip  = 127.0.0.1/8 x1.y1.z1.w1/32 x2.y2.z2.w2/32



[moso@matrix ~]$ sudo fail2ban-client status sshd
Status for the jail: sshd
|- Filter
| |- Currently failed: 1
| |- Total failed: 10
| `- Journal matches: _SYSTEMD_UNIT=sshd.service + _COMM=sshd
`- Actions
|- Currently banned: 1
|- Total banned: 1
`- Banned IP list: 179.43.156.154



[moso@matrix ~]$ sudo iptables -L -n | grep 179.43.156.154
REJECT all -- 179.43.156.154 0.0.0.0/0 reject-with icmp-port-unreachable



[moso@matrix ~]$ sudo cat /var/log/fail2ban.log
2022-04-16 22:10:45,655 fail2ban.server [335]: INFO Starting Fail2ban v0.11.2
2022-04-16 22:10:45,657 fail2ban.observer [335]: INFO Observer start...
2022-04-16 22:10:45,667 fail2ban.database [335]: INFO Connected to fail2ban persistent database '/var/lib/fail2ban/fail2ban.sqlite3'
2022-04-16 22:10:45,670 fail2ban.database [335]: WARNING New database created. Version '4'
2022-04-16 22:10:45,670 fail2ban.jail [335]: INFO Creating new jail 'sshd'
2022-04-16 22:10:45,706 fail2ban.jail [335]: INFO Jail 'sshd' uses systemd {}
2022-04-16 22:10:45,706 fail2ban.jail [335]: INFO Initiated 'systemd' backend
2022-04-16 22:10:45,707 fail2ban.filter [335]: INFO maxLines: 1
2022-04-16 22:10:45,723 fail2ban.filtersystemd [335]: INFO [sshd] Added journal match for: '_SYSTEMD_UNIT=sshd.service + _COMM=sshd'
2022-04-16 22:10:45,723 fail2ban.filter [335]: INFO maxRetry: 3
2022-04-16 22:10:45,723 fail2ban.filter [335]: INFO findtime: 86400
2022-04-16 22:10:45,724 fail2ban.actions [335]: INFO banTime: 1209600
2022-04-16 22:10:45,724 fail2ban.filter [335]: INFO encoding: UTF-8
2022-04-16 22:10:45,725 fail2ban.jail [335]: INFO Jail 'sshd' started
2022-04-16 22:53:09,239 fail2ban.filter [335]: INFO [sshd] Found 179.43.156.154 - 2022-04-16 22:53:08
2022-04-17 00:33:22,995 fail2ban.filter [335]: INFO [sshd] Found 179.43.156.154 - 2022-04-17 00:33:22
2022-04-17 01:31:38,980 fail2ban.filter [335]: INFO [sshd] Found 179.43.156.154 - 2022-04-17 01:31:38
2022-04-17 01:31:39,266 fail2ban.actions [335]: NOTICE [sshd] Ban 179.43.156.154
2022-04-17 02:58:45,765 fail2ban.filter [335]: INFO [sshd] Found 179.43.156.154 - 2022-04-17 02:58:45
2022-04-17 05:40:59,243 fail2ban.filter [335]: INFO [sshd] Found 179.43.156.154 - 2022-04-17 05:40:58
2022-04-17 07:13:51,766 fail2ban.filter [335]: INFO [sshd] Found 179.43.156.154 - 2022-04-17 07:13:51
2022-04-17 07:13:52,130 fail2ban.actions [335]: WARNING [sshd] 179.43.156.154 already banned
2022-04-17 07:49:33,667 fail2ban.filter [335]: INFO [sshd] Found 179.43.156.154 - 2022-04-17 07:49:33
2022-04-17 08:20:44,205 fail2ban.filter [335]: INFO [sshd] Found 179.43.156.154 - 2022-04-17 08:20:44
2022-04-17 08:44:07,980 fail2ban.filter [335]: INFO [sshd] Found 179.43.156.154 - 2022-04-17 08:44:07
2022-04-17 08:44:08,129 fail2ban.actions [335]: WARNING [sshd] 179.43.156.154 already banned
2022-04-17 09:44:54,464 fail2ban.filter [335]: INFO [sshd] Found 179.43.156.154 - 2022-04-17 09:44:54
...



[moso@matrix ~]$ journalctl _SYSTEMD_UNIT=sshd.service
Apr 16 22:10:15 matrix sshd[151093]: Received signal 15; terminating.
-- Boot aa222dfff23f467ab30cd5125c7c3a55 --
Apr 16 22:10:45 matrix sshd[333]: Server listening on 0.0.0.0 port 2206.
Apr 16 22:53:08 matrix sshd[656]: Connection from 179.43.156.154 port 40138 on 38.105.209.109 port 2206 rdomain ""
Apr 16 22:53:08 matrix sshd[656]: Invalid user root root from 179.43.156.154 port 40138
Apr 16 22:53:08 matrix sshd[656]: Connection closed by invalid user root root 179.43.156.154 port 40138 [preauth]
Apr 17 00:33:22 matrix sshd[685]: Connection from 179.43.156.154 port 34498 on 38.105.209.109 port 2206 rdomain ""
Apr 17 00:33:22 matrix sshd[685]: Invalid user root root from 179.43.156.154 port 34498
Apr 17 00:33:22 matrix sshd[685]: Connection closed by invalid user root root 179.43.156.154 port 34498 [preauth]
Apr 17 01:31:38 matrix sshd[699]: Connection from 179.43.156.154 port 59372 on 38.105.209.109 port 2206 rdomain ""
Apr 17 01:31:38 matrix sshd[699]: Invalid user root root from 179.43.156.154 port 59372
Apr 17 01:31:38 matrix sshd[699]: Connection closed by invalid user root root 179.43.156.154 port 59372 [preauth]
Apr 17 02:58:44 matrix sshd[722]: Connection from 179.43.156.154 port 57448 on 38.105.209.109 port 2206 rdomain ""
Apr 17 02:58:45 matrix sshd[722]: Invalid user root root from 179.43.156.154 port 57448
Apr 17 02:58:45 matrix sshd[722]: Connection closed by invalid user root root 179.43.156.154 port 57448 [preauth]
Apr 17 05:40:58 matrix sshd[760]: Connection from 179.43.156.154 port 54992 on 38.105.209.109 port 2206 rdomain ""
Apr 17 05:40:58 matrix sshd[760]: Invalid user root root from 179.43.156.154 port 54992
Apr 17 05:40:58 matrix sshd[760]: Connection closed by invalid user root root 179.43.156.154 port 54992 [preauth]
Apr 17 07:13:51 matrix sshd[777]: Connection from 179.43.156.154 port 59646 on 38.105.209.109 port 2206 rdomain ""
Apr 17 07:13:51 matrix sshd[777]: Invalid user root root from 179.43.156.154 port 59646
Apr 17 07:13:51 matrix sshd[777]: Connection closed by invalid user root root 179.43.156.154 port 59646 [preauth]
Apr 17 07:49:33 matrix sshd[789]: Connection from 179.43.156.154 port 33684 on 38.105.209.109 port 2206 rdomain ""
Apr 17 07:49:33 matrix sshd[789]: Invalid user root root from 179.43.156.154 port 33684
Apr 17 07:49:33 matrix sshd[789]: Connection closed by invalid user root root 179.43.156.154 port 33684 [preauth]
Apr 17 08:20:43 matrix sshd[801]: Connection from 179.43.156.154 port 55522 on 38.105.209.109 port 2206 rdomain ""
Apr 17 08:20:44 matrix sshd[801]: Invalid user root root from 179.43.156.154 port 55522
Apr 17 08:20:44 matrix sshd[801]: Connection closed by invalid user root root 179.43.156.154 port 55522 [preauth]
Apr 17 08:44:07 matrix sshd[805]: Connection from 179.43.156.154 port 39862 on 38.105.209.109 port 2206 rdomain ""
Apr 17 08:44:07 matrix sshd[805]: Invalid user root root from 179.43.156.154 port 39862
Apr 17 08:44:07 matrix sshd[805]: Connection closed by invalid user root root 179.43.156.154 port 39862 [preauth]
Apr 17 09:44:54 matrix sshd[822]: Connection from 179.43.156.154 port 42592 on 38.105.209.109 port 2206 rdomain ""
Apr 17 09:44:54 matrix sshd[822]: Invalid user root root from 179.43.156.154 port 42592
Apr 17 09:44:54 matrix sshd[822]: Connection closed by invalid user root root 179.43.156.154 port 42592 [preauth]
...

为什么 IP 179.43.156.154 继续尝试连接,如果 fail2ban 似乎工作并且来自 179.43.156.154 的任何连接都应该被拒绝?(参见上面 iptables 的输出)

linux ssh iptables fail2ban
  • 1 个回答
  • 215 Views
Martin Hope
Whip
Asked: 2022-02-13 00:08:31 +0800 CST

Fail2ban bantime.increment 不起作用

  • 0

我想增加屡犯者被 fail2ban 抓住的时间。我在 /etc/fail2ban/jail.local 和 fail2ban.local 的顶部添加了以下几行

[DEFAULTS]
bantime.increment = true
bantime.factor = 1
bantime.formula = ban.Time * (1<<(ban.Count if ban.Count<20 else 20)) * banFactor

但这似乎不起作用。这是日志的一部分

2022-02-12 12:18:11,869 fail2ban.filter         [744]: INFO    [postfix-sasl] Found 193.56.29.112 - 2022-02-12 12:18:11
2022-02-12 12:18:11,888 fail2ban.actions        [744]: NOTICE  [postfix-sasl] Ban 193.56.29.112
2022-02-12 12:28:11,985 fail2ban.actions        [744]: NOTICE  [postfix-sasl] Unban 193.56.29.112
2022-02-12 12:28:29,103 fail2ban.filter         [744]: INFO    [postfix-sasl] Found 193.56.29.112 - 2022-02-12 12:28:29
2022-02-12 12:36:15,501 fail2ban.filter         [744]: INFO    [postfix-sasl] Found 193.56.29.112 - 2022-02-12 12:36:15
2022-02-12 12:36:15,928 fail2ban.actions        [744]: NOTICE  [postfix-sasl] Ban 193.56.29.112
2022-02-12 12:46:16,257 fail2ban.actions        [744]: NOTICE  [postfix-sasl] Unban 193.56.29.112
2022-02-12 12:46:42,148 fail2ban.filter         [744]: INFO    [postfix-sasl] Found 193.56.29.112 - 2022-02-12 12:46:42

有什么东西可以压倒这个吗?我怎样才能知道?

我的服务器是 Ubuntu 20.04

ubuntu fail2ban
  • 1 个回答
  • 671 Views
Martin Hope
Patrick32123
Asked: 2022-02-05 12:02:15 +0800 CST

在 fail2ban 中回测历史日志

  • 0

设置 我在 ubuntu 服务器上运行 apache。我创建了一个 fail2ban 规则,当他们请求太多页面太快时禁止 ip。

# Fail2ban Rule
failregex = ^.*?(:80|:443) <HOST> - .* "(GET|POST|HEAD).*$
ignoreregex =.*(.ico|.jpg|.png|.gif|.js|.css|.woff|.mp4)

findtime = 30
maxretry = 10

目标:
我想针对这个新的 fail2ban 规则运行一个旧的 apache 日志,以便我可以查看它是否会禁止任何合法请求。

尝试#1 我认为我可以使用fail2ban-regex 来获取可能被禁止的用户列表,但它没有该功能。

尝试#2 我认为将历史日志回显到fail2ban 当前正在观看的日志中会使它们被解析。在修复了一个小挂断后,忽略了具有旧日期的日志行(通过向它们添加一年来修复)fail2ban 开始解析它们并禁止其中的 IP。但是,我只需要查看第一个被禁止的 IP 就知道它是错误的。有问题的 IP 总共只发出了 10 个请求,而且它们在时间上并不接近。我只能假设 fail2ban 没有使用日志行的时间戳来确定有效性,这使得这种测试方法失败了。

# echo example
zcat other_vhosts_access.log.8.gz | sed -n 's/\/2022:/\/2032:/p' >> /var/log/apache2/fail2ban_test.log

结论 由于我之前的两次尝试都失败了,我想不出一种理智的方法来解决这个问题。有人可以推荐一种方法来实现我所追求的吗?或者深入了解为什么我的第二个解决方案不起作用。

ubuntu security fail2ban
  • 1 个回答
  • 114 Views
Martin Hope
Adam Larsson
Asked: 2022-01-30 06:43:48 +0800 CST

fail2ban 无法将 iptables 添加到规则中

  • 0

我遇到的问题是 fail2ban 没有将被禁止的 IP 添加到 iptables。

这是错误;

2022-01-29 15:13:48,499 fail2ban.actions        [2608]: NOTICE  [man] Restore Ban 212.192.246.26
2022-01-29 15:13:48,513 fail2ban.utils          [2608]: ERROR   7f9281692660 -- exec: iptables -w -N f2b-man
iptables -w -A f2b-man -j RETURN
iptables -w -I INPUT -p tcp -m multiport --dports all -j f2b-man
2022-01-29 15:13:48,514 fail2ban.utils          [2608]: ERROR   7f9281692660 -- stderr: 'iptables: Chain already exists.'
2022-01-29 15:13:48,514 fail2ban.utils          [2608]: ERROR   7f9281692660 -- stderr: "iptables v1.8.4 (legacy): invalid port/service `all' specified"
2022-01-29 15:13:48,514 fail2ban.utils          [2608]: ERROR   7f9281692660 -- stderr: "Try `iptables -h' or 'iptables --help' for more information."
2022-01-29 15:13:48,514 fail2ban.utils          [2608]: ERROR   7f9281692660 -- returned 2
2022-01-29 15:13:48,514 fail2ban.actions        [2608]: ERROR   Failed to execute ban jail 'man' action 'iptables-multiport' info 'ActionInfo({'ip': '212.192.246.26', 'family': 'inet4', 'fid': <function Actions.ActionInfo.<lambda> at 0x7f9280d62e50>, 'raw-ticket': <function Actions.ActionInfo.<lambda> at 0x7f9280d63550>})': Error starting action Jail('man')/iptables-multiport: 'Script error'

所以 iptables 不喜欢;

iptables -w -I INPUT -p tcp -m multiport --dports all -j f2b-man

--dport all 显然是问题所在,所以我的问题是为什么?为什么fail2ban会给出错误的命令,以及如何纠正它?

编辑:在没有网络计划的情况下运行 Ubuntu 服务器 20.04.3。

ubuntu iptables fail2ban ufw
  • 1 个回答
  • 532 Views
Martin Hope
Hynek Bernard
Asked: 2022-01-07 07:04:49 +0800 CST

使用来自 fail2ban 正则表达式的 <F-USER> 值

  • 0

我正在尝试向我和用户发送电子邮件,有人试图登录他们的 ssh 并失败 - IP 被禁止。但我不明白如何在我尝试发送的电子邮件中使用该变量。

Sendmail 设置正确,因为电子邮件发送没有问题。

这是我的 jail.local 配置

[sshd]
port    = ssh
logpath = %(sshd_log)s
backend = %(sshd_backend)s
action  = %(banaction)s[name=%(__name__)s, bantime="%(bantime)s", port="%(port)s", protocol="%(protocol)s", chain="%(chain)s"]
             %(mta)s-whois-lines-ssh[name=%(__name__)s, sender="%(sender)s", dest="%(destemail)s", logpath=%(logpath)s, chain="%(chain)s"]

这是我的 action.d/sendmail-whois-lines-ssh.conf

[INCLUDES]

before = sendmail-common.conf
         helpers-common.conf

[Definition]

norestored = 1
actionban = ( printf %%b "Subject: [Fail2Ban] <name>: banned <ip> from <fq-hostname>
            Date: `LC_ALL=C date +"%%a, %%d %%h %%Y %%T %%z"`
            From: <sendername> <<sender>>
            To: <dest>, <F-USER>@mydomain.cz\n
            Hi,\n
            The IP <ip> has just been banned by Fail2Ban after
            <failures> attempts against <name>.\n\n
            Here is more information about <ip> :\n
            `/usr/bin/whois <ip> || echo missing whois program`\n\n
            Lines containing failures of <ip>\n";
            %(_grep_logs)s;
            printf %%b "\n
            Regards,\n
            Fail2Ban" ) | /usr/sbin/sendmail -f <sender>.mydomain.cz <dest> <F-USER>@mydomain.cz

[Init]
name = default
logpath = /dev/null

发送给我的电子邮件很好,因为从配置中正确获取,但 <F-USER> 没有价值,因此它被发送到@mydomain.cz

我怎样才能获得价值,以便能够将电子邮件发送给用户?

编辑 在 SSH 上受到打击的正则表达式是这个:

^pam_unix\(sshd:auth\):\s+authentication failure;\s*logname=\S*\s*uid=\d*\s*euid=\d*\s*tty=\S*\s*ruser=<F-USER>\S*</F-USER>\s*rhost=<HOST>\s.*%(__suff)s$
debian ssh fail2ban
  • 1 个回答
  • 262 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve