• This forum has a zero tolerance policy regarding spam. If you register here to publish advertising, your user account will be deleted without further questions.

Fail2Ban auf CentOS7 Filter klappt, aber die Zeit wird nicht erfasst

defiance

New Member
Hallo zusammen,

aktuell möchte ich meinen Server weiter absichern nachdem die letzten Tage einige Mail Accounts geknackt wurden und begonnen wurde Spam zu versenden. (Es ist zum Glück nicht viel passiert, ich habe es schnell gemerkt und die Anzahl des versendeten Spams war noch recht gering).
Nun kommen natürlich wieder etliche Anfragen zum Einloggen auf den geknackten Accounts. Um die Chance Accounts zukünftig zu knacken, trotz vielleicht schlechter Passwörter, versuche ich das Ganze mit fail2ban abzusichern. Allerdings klappt es nicht, da kein Ban ausgesprochen wird. Ich schätze es liegt daran, dass das Programm die Zeit nicht richtig erfasst.

Wie bekomme ihc fail2ban dazu, die Zeit richtig zu erfassen und somit zu funktionieren?:confused:

Hier Beispielauszüge aus dem Log, um einen Eindruck der Problematik zu geben:

Code:
Mar  4 15:53:05 localhost postfix/submission/smtpd[24494]: disconnect from host6.cookingate.com[194.63.142.103]
Mar  4 15:53:05 localhost postfix/submission/smtpd[24494]: connect from host6.cookingate.com[194.63.142.103]
Mar  4 15:53:11 localhost postfix/submission/smtpd[24494]: warning: host6.cookingate.com[194.63.142.103]: SASL PLAIN authentication failed:
Mar  4 15:53:11 localhost postfix/submission/smtpd[24494]: disconnect from host6.cookingate.com[194.63.142.103]
Mar  4 15:53:11 localhost postfix/submission/smtpd[24494]: connect from host6.cookingate.com[194.63.142.103]
Mar  4 15:53:18 localhost postfix/submission/smtpd[24494]: warning: host6.cookingate.com[194.63.142.103]: SASL PLAIN authentication failed:
Mar  4 15:53:18 localhost postfix/submission/smtpd[24494]: disconnect from host6.cookingate.com[194.63.142.103]
Mar  4 15:53:18 localhost postfix/submission/smtpd[24494]: connect from host6.cookingate.com[194.63.142.103]
Mar  4 15:53:20 localhost postfix/submission/smtpd[24494]: warning: host6.cookingate.com[194.63.142.103]: SASL PLAIN authentication failed:
Mar  4 15:53:20 localhost postfix/submission/smtpd[24494]: disconnect from host6.cookingate.com[194.63.142.103]
Mar  4 15:53:20 localhost postfix/submission/smtpd[24494]: connect from host6.cookingate.com[194.63.142.103]
Mar  4 15:53:22 localhost postfix/submission/smtpd[24494]: warning: host6.cookingate.com[194.63.142.103]: SASL PLAIN authentication failed:
Mar  4 15:53:22 localhost postfix/submission/smtpd[24494]: disconnect from host6.cookingate.com[194.63.142.103]
Mar  4 15:53:22 localhost postfix/submission/smtpd[24494]: connect from host6.cookingate.com[194.63.142.103]
Mar  4 15:53:24 localhost postfix/submission/smtpd[24494]: warning: host6.cookingate.com[194.63.142.103]: SASL PLAIN authentication failed:


Mar  4 19:44:15 localhost postfix/smtpd[27204]: warning: unknown[195.22.126.189]: SASL LOGIN authentication failed: Invalid authentication mechanism
Mar  4 19:44:15 localhost postfix/smtpd[27204]: disconnect from unknown[195.22.126.189]

In Fail2Ban habe ich verschiedenen Konfigurationen ausprobiert, leider scheitern sie alle am Format der Logs, welches ich jedoch als normal abgestempelt.

Hier die Aufrufe der entsprechenden Filter:
Code:
fail2ban-regex /var/log/maillog /etc/fail2ban/filter.d/postfix-sasl.bkp

Running tests
=============

Use   failregex filter file : postfix-sasl, basedir: /etc/fail2ban
Use         log file : /var/log/maillog
Use         encoding : UTF-8

Results
=======

Failregex: 62 total
|-  #) [# of hits] regular expression
|   1) [62] (?i): warning: [-._\w]+\[<HOST>\]:(\d*?:)? SASL (?:LOGIN|PLAIN|(?:CRAM|DIGEST)-MD5) authentication failed: \w
`-

Ignoreregex: 0 total

Date template hits:
|- [# of hits] date format
|  [26244] (?:DAY )?MON Day 24hour:Minute:Second(?:\.Microseconds)?(?: Year)?
`-

Lines: 26244 lines, 0 ignored, 62 matched, 26182 missed
[processed in 4.11 sec]

Missed line(s): too many to print.  Use --print-all-missed to print all 26182 lines

Zu erkennen, der Filter findet die entsprechenden Ausdrücke, jedoch kann er das Datum und die Zeit nicht extrahieren und damit wird kein Ban ausgesprochen.

Natürlich habe ich schon viel gegoogelt, finde jedoch keine Antwort, die auf mein Problem passt. Bei manchen scheint es einfach zu funktionieren, ich weiß nicht, wie ich das Datum erkennen lassen kann.

Hat jemand eine Idee?

Hier meine zwei Variationen von Regulären ausdrücke, die ich ausprobiert habe:

postfix-sasl.conf
Code:
# Option: failregex
# Notes.: regex to match the password failures messages in the logfile. The
#          host must be matched by a group named "host". The tag "<HOST>" can
#          be used for standard IP/hostname matching and is only an alias for
#          (?:::f{4,6}:)?(?P<host>[\w\-.^_]+)
# Values: TEXT
#
failregex = (?i): warning: [-._\w]+\[<HOST>\]:(\d*?:)? SASL (?:LOGIN|PLAIN|(?:CRAM|DIGEST)-MD5) authentication failed: \w


# Option:  ignoreregex
# Notes.:  regex to ignore. If this regex matches, the line is ignored.
# Values:  TEXT
#
ignoreregex =

bzw. die Original postfix-sals.conf welche ich in ein zwei Variationen ausprobiert habe. Alle liefern nur das oben beschrieben Ergebnis.
Code:
[INCLUDES]

before = common.conf

[Definition]

_daemon = postfix(-\w+)?/(?:submission/|smtps/)?smtp[ds]

#failregex = ^%(__prefix_line)swarning: [-._\w]+\[<HOST>\]: SASL ((?i)LOGIN|PLAIN|(?:CRAM|DIGEST)-MD5) authentication failed(:[ A-Za-z0-9+/:]*={0,2})?\s*$
failregex = (?i): warning: [-._\w]+\[<HOST>\]: SASL (?:LOGIN|PLAIN|(?:CRAM|DIGEST)-MD5) authentication failed(:[A-Za-z0-9+/ ]*)?$

ignoreregex = authentication failed: Connection lost to authentication server$

[Init]

journalmatch = _SYSTEMD_UNIT=postfix.service


# Author: Yaroslav Halchenko

Noch als zusätzliche Info zu meinem System:
CentOS Linux release 7.3.1611 (Core)
fail2ban Version 0.9.6
 
Back
Top