Fail2ban-Filter für MongoDB

Fail2ban-Filter für MongoDB

Fail2Ban-Version: 0.10.2

Ich habe viele Filterkonfigurationsdateien für die fehlgeschlagene MongoDB-Remote-Authentifizierung ausprobiert, keine davon hat funktioniert. Ich bin zu dem Schluss gekommen, dass das Problem bei „failregex“ liegt und ich nicht in der Lage bin, einen richtigen regulären Ausdruck zu finden.

{"$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"}}

Dies ist das Mongo-Protokoll, das ich bei dem fehlgeschlagenen Versuch erhalte. Ich habe versucht, <HOST>, <ADDR> im regulären Ausdruck zu verwenden, aber <HOST> ergibt 0.0.0.0 und <ADDR> ergibt 3:6005 (letzte Ziffer der IP und 4 Ziffern des Ports).

Was wäre der richtige reguläre Ausdruck zum Filtern dieses Protokolls?

Regex, ich habe es versucht

^(.*Authentication failed.*)|(.*<ADDR>.*)|$
^(.*Authentication failed.*)|(.*<HOST>.*)|$

Antwort1

  1. https://github.com/fail2ban/fail2ban/issues/2932
  2. https://github.com/fail2ban/fail2ban/issues/3046

in Kürze:

[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+"

verwandte Informationen