带有 IPtables 的 Fail2ban 块在 Debian Lenny 上不起作用。[移动ssh端口]

ant*_*tel 12 security firewall debian iptables

我最近决定做一些安全维护。我看到了我的日志,并且有一些针对我的 SSH 服务器的尝试。起初,我从默认的 22 端口移开了 SSH 端口。之后,我读了一些关于Fail2banBlockHostsDenyHosts 的内容

我先看了看:配置简单,一切都好理解;但是当我试图“探索它的保护”时,测试失败了。一切似乎都很好,但我仍然可以访问服务器。

我还测试了 IPtables:# iptables -I INPUT -j DROP- 之后我的 SSH 连接丢失了(所以,我想要什么)。然后# iptables -I INPUT -s 84.x.y.z -j DROP,这也奏效了。

但是,Fail2ban 做了什么规则,这不起作用:($ sudo iptables -L

Chain INPUT (policy ACCEPT)
target     prot opt source               destination        
fail2ban-apache  tcp  --  anywhere             anywhere            multiport dports www,https
fail2ban-ssh  tcp  --  anywhere             anywhere            multiport dports ssh
fail2ban-ssh-ddos  tcp  --  anywhere             anywhere            multiport dports ssh

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination        

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination        

Chain fail2ban-apache (1 references)
target     prot opt source               destination        
RETURN     all  --  anywhere             anywhere            

Chain fail2ban-ssh (1 references)
target     prot opt source               destination        
DROP       all  --  84.x.y.z           anywhere            
RETURN     all  --  anywhere             anywhere            

Chain fail2ban-ssh-ddos (1 references)
target     prot opt source               destination        
RETURN     all  --  anywhere             anywhere
Run Code Online (Sandbox Code Playgroud)

加载的内核模块:( $ lsmod | grep ip)

iptable_nat             4680  0
nf_nat                 15576  1 iptable_nat
nf_conntrack_ipv4      12268  3 iptable_nat,nf_nat
nf_conntrack           55540  4 xt_state,iptable_nat,nf_nat,nf_conntrack_ipv4
xt_multiport            2816  2
iptable_filter          2624  1
ip_tables              10160  2 iptable_nat,iptable_filter
x_tables               13284  5 xt_state,xt_tcpudp,iptable_nat,xt_multiport,ip_tables
ipv6                  235396  24
Run Code Online (Sandbox Code Playgroud)

版本:

  • Debian Lenny 5.06,内核 2.6.26-2-686
  • IPtables 1.4.2-6
  • Fail2ban 0.8.3-2sid1
  • openssh-server 1:5.1p1-5

测试#1 一步一步:

  1. 将 Fail2ban 配置为低禁止时间。60 秒。然后重新加载。
  2. 尝试登录(使用 SSH),直接使用错误的密码。
  3. 第 6 次输入正确的密码(此处最多尝试 4 次)。我登录了。我还可以访问该服务器托管的网页。
  4. iptables -L向我展示了上面提到的内容。所以禁令是有效的,当我连接时,命令我的服务器。

逐步测试#2:

  1. 停止 Fail2ban。创建一个at脚本,以在将来删除下面写的禁止规则。( iptables -D INPUT 1)
  2. 创建禁止规则: iptables -I INPUT 1 -s 84.x.y.z -j DROP
  3. 我无法输入任何其他内容,SSH 连接无法使用。我无法访问网页。所以,我想从 iptables 得到什么。
  4. at脚本之后,我可以访问我的服务器。

我没有看到解决方案,我应该怎么做才能使我的 IPtables 禁令(由 Fail2ban 制造)起作用?

ant*_*tel 9

在安装fail2ban之前,我发现了问题,我做了什么。对不起,你的时间。

出于安全原因,我将 sshd 从端口 22 移到另一个端口。中的引用iptables仅指端口 22。我想,它是一个变量,总是指当前的 sshd 端口。但不是

确切的解决方案(如果您将守护进程从其原始端口移开):

  1. 打开 jail.local(或 .conf)。
  2. 找到您的服务(在大括号中)。
  3. 将该port部分修复为所有. 例子:port = all
  4. banaction在端口行之后添加或编辑现有行,值为iptables-allports。例子:banaction = iptables-allports
  5. 重新启动守护程序。例子:# service fail2ban restart

我找不到更改port ssh指令的解决方案,或者在那里写一个数字。如果您有非全端口解决方案,我会听的!