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
    • 最新
    • 标签
主页 / unix / 问题

问题[fail2ban](unix)

Martin Hope
xstack
Asked: 2024-01-28 23:45:21 +0800 CST

试图理解为什么内核尝试验证被禁止的 IP (Debian 10 VPS)

  • 5

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

我已经包括:

  • 使用nmap进行端口扫描的结果
  • 我在fail2ban jam.local 文件中的具体设置。
  • 我在fail2ban failure2ban.local 文件中的具体设置。
  • 验证日志中的完整样本。
  • fail2ban 日志的完整样本。
  • 我的 IpTables 样本扫描结果。

问题总结:

  • auth.log 显示 192.241.141.43 几乎每分钟都尝试进入
  • fail2ban.log 显示 192.241.141.43 已被禁止
  • iptables显示192.241.141.43被禁止

我认为基于 IP 被阻止,恶意用户将无法尝试登录。然而,内核似乎确实(pam_unix(sshd:auth))允许尝试登录。

我的两个问题:

  1. 为什么内核在禁止恶意用户的情况下仍允许他们尝试登录?
  2. 为什么 Iptables 条目显示“icmp”而不是“tcp”?是的,我知道“ping”是一个 icmp 数据包,但我想阻止 tcp 登录尝试。

非常感谢 !

nmap 扫描结果

# Nmap 7.80 scan initiated Sat Jan 27 15:25:04 2024 as: nmap -sS -oG out.txt 

107.174.156.124

Host: 107.174.156.124 (107-174-156-124-host.colocrossing.com)   
Status: 
Up
Host: 107.174.156.124 (107-174-156-124-host.colocrossing.com)   
Ports: 
139/filtered/tcp//netbios-ssn///, 
445/filtered/tcp//microsoft-ds///, 
8888/open/tcp//sun-answerbook///    
Ignored State: closed (997)

# Nmap done at Sat Jan 27 15:25:06 2024 
-- 1 IP address (1 host up) scanned in 2.20 seconds

这是我在 jam.local 中的条目

请注意,我已将 SSHD 端口移至 63xxx 范围。我用 xxx 遮盖了最后 3 位数字

#
# JAILS
#

#
# SSH servers
#

[sshd]

# To use more aggressive sshd modes set filter parameter "mode" in jail.local:
# normal (default), ddos, extra or aggressive (combines all).
# See "tests/files/logs/sshd" or "filter.d/sshd.conf" for usage example and details.
#mode   = normal
enabled = true
mode = aggressive
port = 63xxx
filter = sshd
logpath = /var/log/auth.log
bantime = 2000000
findtime = 7200
maxretry = 2
backend = %(sshd_backend)s
action = iptables-multiport[name=sshd, port="ssh", protocol=tcp]

fail2ban.local

# Options: dbpurgeage
# Notes.: Sets age at which bans should be purged from the database
# Values: [ SECONDS ] Default: 86400 (24hours)
dbpurgeage = 2100000

身份验证日志示例

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

Jan 27 15:54:55 racknerd-64d010 sshd[2232]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.241.141.43  user=root
Jan 27 15:54:57 racknerd-64d010 sshd[2232]: Failed password for root from 192.241.141.43 port 54798 ssh2
Jan 27 15:54:57 racknerd-64d010 sshd[2232]: Received disconnect from 192.241.141.43 port 54798:11: Bye Bye [preauth]
Jan 27 15:54:57 racknerd-64d010 sshd[2232]: Disconnected from authenticating user root 192.241.141.43 port 54798 [preauth]

fail2ban 示例

例如,fail2ban 表示 192.241.141.43 已被禁止

2024-01-27 15:55:50,928 fail2ban.actions        [29992]: WARNING [sshd] 82.102.12.130 already banned
2024-01-27 15:55:50,929 fail2ban.actions        [29992]: WARNING [sshd] 192.241.141.43 already banned
2024-01-27 15:55:50,929 fail2ban.actions        [29992]: WARNING [sshd] 159.75.161.40 already banned

Iptables 扫描的结果

IP 192.241.141.43 被禁止

    0     0 REJECT     all  --  *      *       61.231.64.170        0.0.0.0/0            reject-with icmp-port-unreachable
    0     0 REJECT     all  --  *      *       192.241.141.43       0.0.0.0/0            reject-with icmp-port-unreachable
    0     0 REJECT     all  --  *      *       104.250.34.177       0.0.0.0/0            reject-with icmp-port-unreachable

附加信息1+2,完整规则集

这是完整规则集文件的链接。

  • iptables_o2.txt
  • auth_2024-01-27m_sample.txt

=== 附加信息摘要

我在这里总结了克里斯·戴维斯的重要意见。我这样做是为了让将来阅读本文的人们能够清楚地知道要在监狱.local 文件的 SSHD Jail 部分中添加哪些内容。

我还包括了fail2ban.local 文件中的单行更改文本 - 再次感谢 Chris。

=== 这是jail.local

#
# 监狱
#

#
# SSH 服务器
#

[sshd]

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

=== 这是fail2ban.local

# 选项:dbpurgeage
# 注意:设置应从数据库中清除禁令的年龄
# 值:[ SECONDS ] 默认值:86400(24 小时)
数据库清除 = 2100000
fail2ban
  • 1 个回答
  • 124 Views
Martin Hope
symcbean
Asked: 2019-12-04 03:36:21 +0800 CST

如何在没有日志文件的情况下配置 fail2ban?

  • 0

我正在尝试在 fail2ban 中配置一个策略——在我的情况下,不良行为的检测和识别相当复杂,所以我打算在一个专门的程序中处理这个问题。与其让该程序写入日志,并通过 fail2ban 轮询日志以查看它是否应该采取行动,我认为fail2ban-client banip直接从检测器调用会更简单。但是fail2ban 拒绝识别我的监狱配置,因为它没有定义过滤器。

我必须提供日志文件和过滤器吗?有没有办法说服fail2ban在没有这个的情况下工作?如果我需要告诉 fail2ban 一个日志文件,它是否必须存在于文件系统中?

fail2ban logs
  • 1 个回答
  • 116 Views
Martin Hope
xenoid
Asked: 2019-11-06 09:37:54 +0800 CST

大型fail2ban数据库,正常吗?

  • 9

我服务器上的 fail2ban 数据库非常大(420MB)。

fail2ban 日志非常繁忙(每两秒就有一个“过滤器”条目),但iptables只显示了几个被禁止的地址。

dbpurage 为 86400 秒(24 小时)

这个尺寸与活动一致还是发生了什么?

我假设如果我停止/擦除数据库/启动,我会恢复到合理的大小,但这不会使活动禁令永久化吗?

fail2ban
  • 1 个回答
  • 1531 Views
Martin Hope
giuseppe
Asked: 2019-09-09 02:52:51 +0800 CST

Fail2ban 添加新链

  • -2

如果 recidive 具有该块的 N 个 IP,如何创建一个出现在第一个位置(在 recidive 之前)创建 iptables 规则以阻止整个 IP 类的新链?

提前谢谢

fail2ban
  • 1 个回答
  • 49 Views
Martin Hope
realtebo
Asked: 2019-03-15 03:35:15 +0800 CST

Fail2ban 正则表达式:如何不获取主机名但获取 IP?

  • 0

在我access.log的某个地方,我得到了一个

ip - - [date] method link ... etc..

和其他一些人

www.domain.com:ip - - [date] method link ... etc..

我实际上正在使用这个正则表达式

 ^<HOST>.*/phpmyadmin

问题是它导致fail2ban在解析第二种行时使用www.domain.com的反向查找作为ip。

是否有更精确的 ip 正则表达式而不是主机名?

fail2ban
  • 1 个回答
  • 300 Views
Martin Hope
realtebo
Asked: 2019-03-14 08:10:37 +0800 CST

fail2ban 禁止了我的 IP 但我仍然可以使用 SSH 登录

  • 2

fail2ban我在 Debian 9.8 上进行了全新安装

我复制/etc/fail2ban/jail.conf为jail.local.

并在我jail.local的in添加enabled=true下[ssh]

跟踪 fail2ban 的日志我可以看到当我尝试使用错误的用户名/密码对登录 SSH 时会发生什么

2019-03-13 17:03:55,751 fail2ban.filter         [3328]: INFO    [sshd] Found 192.168.229.1
2019-03-13 17:03:55,753 fail2ban.filter         [3328]: INFO    [sshd] Found 192.168.229.1
2019-03-13 17:03:57,534 fail2ban.filter         [3328]: INFO    [sshd] Found 192.168.229.1
2019-03-13 17:04:00,630 fail2ban.filter         [3328]: INFO    [sshd] Found 192.168.229.1
2019-03-13 17:04:00,633 fail2ban.filter         [3328]: INFO    [sshd] Found 192.168.229.1
2019-03-13 17:04:00,635 fail2ban.actions        [3328]: NOTICE  [sshd] Ban 192.168.229.1

我以为没问题,但我仍然可以尝试登录。我有

2019-03-13 17:07:59,245 fail2ban.actions        [3328]: NOTICE  [sshd] 192.168.229.1 already banned

我看到我的 IP 进入 iptables

 sudo iptables-save | grep 192.
-A f2b-sshd -s 192.168.229.1/32 -j REJECT --reject-with icmp-port-unreachable

那么,为什么我仍然可以尝试登录?当然,我也可以使用正确的名称/密码对成功登录。

我使用端口 26522 而不是标准的 22 端口进行 ssh。我必须以某种方式精确吗?

fail2ban
  • 1 个回答
  • 1442 Views
Martin Hope
porton
Asked: 2018-05-25 06:54:16 +0800 CST

fail2ban 如何防御 DDoS?

  • 5

如何fail2ban防御 SSH DDoS 攻击?在 DDoS 攻击的情况下它会做什么?它如何确定它是否是 DDoS?

我只询问D DoS 攻击。

(我认为它确实可以防止 DDoS,因为诸如How to Secure SSH server from Brute-Force 和 DDOS with Fail2ban (Ubuntu) 之类的文章。)

fail2ban iptables
  • 1 个回答
  • 3175 Views
Martin Hope
Attila Kis
Asked: 2018-01-11 03:15:40 +0800 CST

Fail2ban 记录到 systemd

  • 0

我正在尝试将fail2ban 的后端设置为systemd。文件:

/etc/fail2ban/jail.local

选项:

backend = systemd

它不会启动,日志:

2018-06-27 12:09:53,387 fail2ban.jail           [10240]: ERROR   Backend 'systemd' failed to initialize due to No module named 'systemd'

有什么解决办法?

我试过这些:

python3 -c 'from systemd import journal; print("OK")'
python2 -c 'from systemd import journal; print "OK"'


ImportError: No module named systemd
fail2ban systemd
  • 1 个回答
  • 1107 Views
Martin Hope
ensabahn
Asked: 2017-12-30 09:12:25 +0800 CST

dpkg:错误处理包fail2ban(--configure):

  • 1

我正在尝试在我的 ubuntu 服务器 16.04 上安装 fail2ban 服务,但是我有这个错误并且 fail2ban 服务无法启动,这是什么问题?

root@clm:~# apt install fail2ban
Reading package lists... Done
Building dependency tree       
Reading state information... Done
fail2ban is already the newest version (0.9.3-1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
Setting up fail2ban (0.9.3-1) ...
Job for fail2ban.service failed because the control process exited with error code. See "systemctl status fail2ban.service" and "journalctl -xe" for details.
invoke-rc.d: initscript fail2ban, action "start" failed.
● fail2ban.service - Fail2Ban Service
   Loaded: loaded (/lib/systemd/system/fail2ban.service; enabled; vendor preset: enabled)
   Active: activating (auto-restart) (Result: exit-code) since Fri 2017-12-29 18:08:01 CET; 8ms ago
     Docs: man:fail2ban(1)
  Process: 4888 ExecStart=/usr/bin/fail2ban-client -x start (code=exited, status=255)

Dec 29 18:08:01 domain systemd[1]: Failed to start Fail2Ban Service.
Dec 29 18:08:01 domain systemd[1]: fail2ban.service: Unit entered failed state.
Dec 29 18:08:01 domain systemd[1]: fail2ban.service: Failed with result 'exit-code'.
dpkg: error processing package fail2ban (--configure):
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 fail2ban
E: Sub-process /usr/bin/dpkg returned an error code (1)

日志说是这样的,

root@clm:~# systemctl status fail2ban.service
● fail2ban.service - Fail2Ban Service
   Loaded: loaded (/lib/systemd/system/fail2ban.service; enabled; vendor preset: enabled)
   Active: inactive (dead) (Result: exit-code) since Fri 2017-12-29 18:27:09 CET; 9min ago
     Docs: man:fail2ban(1)
  Process: 7277 ExecStop=/usr/bin/fail2ban-client stop (code=exited, status=0/SUCCESS)
  Process: 7301 ExecStart=/usr/bin/fail2ban-client -x start (code=exited, status=255)
 Main PID: 7026 (code=killed, signal=TERM)

Dec 29 18:27:09 domain systemd[1]: fail2ban.service: Control process exited, code=exited status=255
Dec 29 18:27:09 domain systemd[1]: Failed to start Fail2Ban Service.
Dec 29 18:27:09 domain systemd[1]: fail2ban.service: Unit entered failed state.
Dec 29 18:27:09 domain systemd[1]: fail2ban.service: Failed with result 'exit-code'.
Dec 29 18:27:09 domain systemd[1]: fail2ban.service: Service hold-off time over, scheduling restart.
Dec 29 18:27:09 domain systemd[1]: Stopped Fail2Ban Service.
Dec 29 18:27:09 domain systemd[1]: fail2ban.service: Start request repeated too quickly.
Dec 29 18:27:09 domain systemd[1]: Failed to start Fail2Ban Service.
root@clm:~# tail -f /var/log/fail2ban.log 
2017-12-29 18:26:08,198 fail2ban.actions        [7026]: INFO    Set banTime = 600
2017-12-29 18:26:08,262 fail2ban.filter         [7026]: INFO    Added logfile = /var/log/auth.log
2017-12-29 18:26:08,330 fail2ban.filter         [7026]: INFO    Set jail log file encoding to UTF-8
2017-12-29 18:26:08,331 fail2ban.filter         [7026]: INFO    Set maxRetry = 5
2017-12-29 18:26:08,331 fail2ban.filter         [7026]: INFO    Set maxlines = 10
2017-12-29 18:26:08,448 fail2ban.server         [7026]: INFO    Jail sshd is not a JournalFilter instance
2017-12-29 18:26:08,465 fail2ban.jail           [7026]: INFO    Jail 'sshd' started
2017-12-29 18:27:05,924 fail2ban.server         [7026]: INFO    Stopping all jails
2017-12-29 18:27:06,756 fail2ban.jail           [7026]: INFO    Jail 'sshd' stopped
2017-12-29 18:27:06,831 fail2ban.server         [7026]: INFO    Exiting Fail2ban
ubuntu fail2ban
  • 2 个回答
  • 2323 Views

Sidebar

Stats

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

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

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

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve