我正在使用Ubuntu 12.04而且我已经看到一堆失败的SSH尝试进入我的服务器而我正在尝试添加一个规则来fail2Ban阻止它们,但我的正则表达式似乎不正确。
fail2ban是否连续查找N次重试,或者是日志中出现的次数?如果它是前者(来自IP的连续重试),那么我认为我的正则表达式是正确的,并且它们在最大尝试次数下切换IP。
所以这是我所见过的一个例子
Feb 13 18:41:37 sshd[22426]: Received disconnect from 186.42.181.66: 11: Bye Bye [preauth]
Feb 13 18:41:38 sshd[22428]: Received disconnect from 186.42.181.66: 11: Bye Bye [preauth]
Feb 13 18:41:39 sshd[22430]: reverse mapping checking getaddrinfo for host-190-95-232-234.uio.telconet.net [190.95.232.234] failed - POSSIBLE BREAK-IN ATTEMPT!
Feb 13 18:41:39 sshd[22430]: Received disconnect from 190.95.232.234: 11: Bye Bye [preauth]
Feb 13 18:41:40 sshd[22432]: Received disconnect from 186.42.181.66: 11: Bye Bye [preauth]
Feb 13 18:41:41 sshd[22434]: reverse mapping checking getaddrinfo for host-190-95-232-234.uio.telconet.net [190.95.232.234] failed - POSSIBLE BREAK-IN ATTEMPT!
Feb 13 18:41:42 sshd[22434]: Received disconnect from 190.95.232.234: 11: Bye Bye [preauth]
Feb 13 18:41:43 sshd[22436]: Received disconnect from 186.42.181.66: 11: Bye Bye [preauth]
Feb 13 18:41:44 sshd[22438]: Received disconnect from 186.42.181.66: 11: Bye Bye [preauth]
Feb 13 18:41:45 sshd[22440]: reverse mapping checking getaddrinfo for host-190-95-232-234.uio.telconet.net [190.95.232.234] failed - POSSIBLE BREAK-IN ATTEMPT!
Feb 13 18:41:45 sshd[22440]: Received disconnect from 190.95.232.234: 11: Bye Bye [preauth]
Feb 13 18:41:46 sshd[22442]: Received disconnect from 186.42.181.66: 11: Bye Bye [preauth]
这是jail.conf中的SSH部分
[ssh]
enabled = true
port = ssh
filter = sshd
logpath = /var/log/auth.log #this is the correct file
maxretry = 5
bantime = 86400
以下是sshd.conf中与上面示例相关的两行正则表达式
^%(__prefix_line)sReceived disconnect from <HOST>: 11: Bye Bye \[preauth\]\s*$
^%(__prefix_line)sAddress <HOST> .* POSSIBLE BREAK-IN ATTEMPT!*\s*$
添加这些规则后,我重新启动了fail2ban。我检查了IP表,fail2ban为我的其他规则添加了几个IP,但这个似乎没有工作,所以我猜它是我的正则表达式。
答案 0 :(得分:1)
我没有fail2ban,所以我无法真正测试它,但在正则表达式中有一些东西对我很突出......
%(__prefix_line)
是<HOST>
是另一种替换或占位符,fail2ban可以理解 我注意到的第一件事是 见下面的评论。 s
之后的'%(__prefix_line)
'。看起来它应该是一个空白速记字符类而不是文字s
。在它前面放一个反斜杠(\s
)。
我注意到的第二件事是第二行爆炸(感叹号)后的星号。那说“零个或多个!字符”。也许这就是预期的。也许不吧。如果你删除那个星号,那么它更有意义。如果你在前面添加一个点,它也是有道理的。
<德尔>尝试:德尔>
^%(__prefix_line)\sReceived disconnect from <HOST>: 11: Bye Bye \[preauth\]\s*$
^%(__prefix_line)\sAddress <HOST> .* POSSIBLE BREAK-IN ATTEMPT!*\s*$
请参阅以下评论
如果这不起作用,那么在爆炸后用星号做一些事情。
如果这不起作用,请使用fail2ban确认“ 我找到了 <HOST>
”是正确的替换。<HOST>
< em>在fail2ban文档中。它看起来是正确的。
另请参阅:Testing
中的Fail2ban 0.8 Manual