![mongodb 的 Fail2ban 過濾器](https://rvso.com/image/769269/mongodb%20%E7%9A%84%20Fail2ban%20%E9%81%8E%E6%BF%BE%E5%99%A8.png)
Fail2Ban版本:0.10.2
我已經嘗試了很多用於 MongoDB 遠端身份驗證失敗的過濾器配置文件,但它們都不起作用,我認為問題出在failregex上,並且我無法想出正確的正則表達式。
{"$date":"2021-08-10T17:27:13.498+05:30"},"s":"I", "c":"ACCESS", "id":20249, "ctx":"conn187","msg":"Authentication failed","attr":{"mechanism":"SCRAM-SHA-256","speculative":true,"principalName":"Admin","authenticationDatabase":"admin","remote":"123.456.789.123:60054","extraInfo":{},"error":"AuthenticationFailed: SCRAM authentication failed, storedKey mismatch"}}
這是我在失敗的嘗試中得到的 mongo 日誌。我嘗試在正規表示式中使用 <HOST>、<ADDR>,但 <HOST> 給出 0.0.0.0,<ADDR> 給出 3:6005(IP 的最後一位數字和連接埠的 4 位數)。
過濾此日誌的正確正規表示式是什麼?
正規表示式我已經嘗試過
^(.*Authentication failed.*)|(.*<ADDR>.*)|$
^(.*Authentication failed.*)|(.*<HOST>.*)|$
答案1
不久:
[Definition]
datepattern = ^\{"t":\{"\$date":"%%Y-%%m-%%dT%%H:%%M:%%S\.%%f%%z"}\s*,\s*
_groupre = (?:"(?!(?:msg|attr|client|remote)\b)\w+":(?:"[^"]+"|\w+)\s*[,\}]\s*)
failregex = ^%(_groupre)s*"msg":"Authentication failed"\s*,\s*%(_groupre)s*"attr"\s*:\s*\{%(_groupre)s*"(?:client|remote)":"<ADDR>:\d+"