Fail2ban blockt nicht [gelöst ]

Alles rund um sicherheitsrelevante Fragen und Probleme.
Antworten
Benutzeravatar
Faber38
Beiträge: 380
Registriert: 21.03.2009 23:28:20
Wohnort: Elsdorf

Fail2ban blockt nicht [gelöst ]

Beitrag von Faber38 » 09.02.2024 18:41:09

Hallo,
Auf einem Debian12 Container
habe ich die Fail2ban Konfiguration um eine Log Datei erweitert.
In der Datei werden alle Fehlversuche der Joomla-Webseite gespeichert.
nun wollte ich Fail2ban darauf hin erweitern.
Vorab... beim sshd zugriff funktioniert das ip blocken.

hier mal die Veränderungen in der /etc/fail2ban/jail.local
[sshd]

# To use more aggressive sshd modes set filter parameter "mode" in jail.local:
# normal (default), ddos, extra or aggressive (combines all).
# See "tests/files/logs/sshd" or "filter.d/sshd.conf" for usage example and details.
#mode = normal
port = ssh
logpath = %(sshd_log)s
backend = %(sshd_backend)s

[joomla]
# Joomla Webseite HTTP/HTTPS web interface auth
# Logs auth failures to joomla error log
bantime = 15d
maxretry = 3
findtime = 15d
filter = joomla
port = http,https
logpath = /var/www/html/joomla/administrator/logs/error.php
nun der passende Filter in /etc/fail2ban/filter.d/joomla.conf

[Definition]
failregex = ^<HOST>.*tokenfailure.*Authentication failed
^<HOST>.*joomlafailure.*Benutzername und Passwort falsch oder das Benutzerkonto existiert noch nicht.

ignoreregex =

# DEV Notes:
# INFO 216.218.206.67 tokenfailure Authentication failed
# INFO 87.79.239.103 joomlafailure Benutzername und Passwort falsch oder das Benutzerkonto existiert noch nicht\.
#
frage ich den Status ab
Status for the jail: joomla
|- Filter
| |- Currently failed: 0
| |- Total failed: 0
| `- File list: /var/www/html/joomla/administrator/logs/error.php
`- Actions
|- Currently banned: 0
|- Total banned: 0
`- Banned IP list:
obwohl es mehrere Einträge gibt die gebannt werden sollten !?
Zuletzt geändert von Faber38 am 10.02.2024 11:45:29, insgesamt 1-mal geändert.

Benutzeravatar
Faber38
Beiträge: 380
Registriert: 21.03.2009 23:28:20
Wohnort: Elsdorf

Re: Fail2ban blockt nicht

Beitrag von Faber38 » 09.02.2024 18:49:07

noch zusätzlich aus der /var/log/fail2ban.log
2024-02-09 18:44:44,803 fail2ban.jail [3547]: INFO Jail 'joomla' uses pyinotify {}
2024-02-09 18:44:44,806 fail2ban.jail [3547]: INFO Initiated 'pyinotify' backend
2024-02-09 18:44:44,808 fail2ban.filter [3547]: INFO maxRetry: 3
2024-02-09 18:44:44,808 fail2ban.filter [3547]: INFO findtime: 1296000
2024-02-09 18:44:44,808 fail2ban.actions [3547]: INFO banTime: 1296000
2024-02-09 18:44:44,808 fail2ban.filter [3547]: INFO encoding: UTF-8
2024-02-09 18:44:44,809 fail2ban.filter [3547]: INFO Added logfile: '/var/www/html/joomla/administrator/logs/error.php' (pos = 10338, hash = 9762053d4defb8be822cb0957983a6b8796976d6)
2024-02-09 18:44:44,820 fail2ban.jail [3547]: INFO Jail 'sshd' started
2024-02-09 18:44:44,821 fail2ban.jail [3547]: INFO Jail 'joomla' started
2024-02-09 18:44:45,010 fail2ban.actions [3547]: NOTICE [sshd] Restore Ban 192.168.38.100

Benutzeravatar
heisenberg
Beiträge: 3567
Registriert: 04.06.2015 01:17:27
Lizenz eigener Beiträge: MIT Lizenz

Re: Fail2ban blockt nicht

Beitrag von heisenberg » 09.02.2024 21:22:24

Hast Du Deinen Filter schon mal mit fail2ban-regex geprüft? Das Programm kann man auf verschiedene Arten aufrufen.

Z. B. so:

Code: Alles auswählen

# fail2ban-regex /var/log/mail.log postfix

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

Use   failregex filter file : postfix, basedir: /etc/fail2ban
Use      datepattern : {^LN-BEG} : Default Detectors
Use         log file : /var/log/mail.log
Use         encoding : UTF-8


Results
=======

Failregex: 46320 total
|-  #) [# of hits] regular expression
|   1) [46320] postfix/((smtps|submission)/)?smtpd\[[0-9]+\]: warning: [^[]+\[<HOST>\]: SASL( [^ ]+)? authentication failed:
`-

Ignoreregex: 0 total

Date template hits:
|- [# of hits] date format
|  [458344] {^LN-BEG}(?:DAY )?MON Day %k:Minute:Second(?:\.Microseconds)?(?: ExYear)?
`-

Lines: 458344 lines, 0 ignored, 46320 matched, 412024 missed
[processed in 34.65 sec]

Missed line(s): too many to print.  Use --print-all-missed to print all 412024 lines
P. S. : Ich hatte den Fail2ban hier mal 'ne Weile aus. Deswegen sind da so viele Matches.

P. P. S.: Systemausgaben, Protokollauszüge bitte in code-Tags (</> - Symbol) nicht in quote-Tags ( " - Symbol).
Jede Rohheit hat ihren Ursprung in einer Schwäche.

Benutzeravatar
Faber38
Beiträge: 380
Registriert: 21.03.2009 23:28:20
Wohnort: Elsdorf

Re: Fail2ban blockt nicht

Beitrag von Faber38 » 10.02.2024 06:47:41

erstmal Danke für den Hinweis !
das hat mir sehr weiter geholfen... hier mal das ergenbis
fail2ban-regex /var/www/html/joomla/administrator/logs/error.php joomla

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

Use failregex filter file : joomla, basedir: /etc/fail2ban
Use log file : /var/www/html/joomla/administrator/logs/error.php
Use encoding : UTF-8


Results
=======

Failregex: 0 total

Ignoreregex: 0 total

Date template hits:
|- [# of hits] date format
| [94] {^LN-BEG}ExYear(?P<_sep>[-/.])Month(?P=_sep)Day(?:T| ?)24hour:Minute:Second(?:[.,]Microseconds)?(?:\s*Zone offset)?
`-

Lines: 94 lines, 0 ignored, 0 matched, 94 missed
[processed in 0.01 sec]

Missed line(s): too many to print. Use --print-all-missed to print all 94 lines
da stimmt was mit mein failregex filter nicht

Benutzeravatar
Faber38
Beiträge: 380
Registriert: 21.03.2009 23:28:20
Wohnort: Elsdorf

Re: Fail2ban blockt nicht

Beitrag von Faber38 » 10.02.2024 07:37:04

ich dreh mich im Kreis !

aus folgenden Zeilen möchte ich das passende failregex erstellen...
2024-02-08T18:37:51+00:00 INFO 51.255.62.13 tokenfailure Authentication failed
2024-02-08T18:40:03+00:00 INFO 51.255.62.5 tokenfailure Authentication failed
2024-02-08T18:44:47+00:00 INFO 87.79.239.103 joomlafailure Benutzername und Passwort falsch oder das Benutzerkonto existiert noch nicht.
2024-02-08T18:44:51+00:00 INFO 87.79.239.103 joomlafailure Benutzername und Passwort falsch oder das Benutzerkonto existiert noch nicht.
mein Ergebniss ist mangelhaft ich hab folgendes probiert
failregex = ^<HOST>.*tokenfailure.*Authentication failed
oder
failregex = ^(?P<date>\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\+\d{2}:\d{2})\s+INFO\s+(?P<ip>\S+)\s+tokenfailure\s+Authentication failed\s*$
chatGPT hilft mir auch nicht weiter :-(

Benutzeravatar
Faber38
Beiträge: 380
Registriert: 21.03.2009 23:28:20
Wohnort: Elsdorf

Re: Fail2ban blockt nicht

Beitrag von Faber38 » 10.02.2024 10:20:38

ich komme nicht weiter...
fail2ban-regex -d "%Y-%b-%dT:%H:%M:%S+00:00" /var/www/html/joomla/administrator/logs/error.php /etc/fail2ban/filter.d/joomla -v

ergibt folgendes
Running tests
=============

Use datepattern : %Y-%b-%dT:%H:%M:%S+00:00 : Year-MON-DayT:24hour:Minute:Second+00:00
Use failregex filter file : joomla, basedir: /etc/fail2ban
Use log file : /var/www/html/joomla/administrator/logs/error.php
Use encoding : UTF-8


Results
=======

Failregex: 0 total
|- #) [# of hits] regular expression
| 1) [0] ^<HOST>.*tokenfailure.*Authentication failed
`-

Ignoreregex: 0 total

Date template hits:
|- [# of hits] date format
| [0] Year-MON-DayT:24hour:Minute:Second+00:00
`-
:cry: :?:

Benutzeravatar
Faber38
Beiträge: 380
Registriert: 21.03.2009 23:28:20
Wohnort: Elsdorf

Re: Fail2ban blockt nicht [gelöst ]

Beitrag von Faber38 » 10.02.2024 11:47:33

Lösung gefunden...
in jail.local
[joomla]
# Joomla Webseite HTTP/HTTPS web interface auth
# Logs auth failures to joomla error log
datepattern = %Y-%m-%dT%H:%M:%S%z
bantime = 15d
maxretry = 3
findtime = 15d
port = http,https
logpath = /var/www/html/joomla/administrator/logs/error.php
und als Filter in filter.d/joomla.conf
# Fail2Ban filter for Joomla User login
#

[Definition]
failregex = ^.*INFO <HOST>.*joomlafailure.*(Benutzername|Username).*
^.*INFO <HOST>.*tokenfailure.*(Authentication failed).*

# DEV Notes:
# INFO 216.218.206.67 tokenfailure Authentication failed
# INFO 87.79.239.103 joomlafailure Benutzername und Passwort falsch oder das Benutzerkonto existiert noch nicht.
jetzt gehts !

Antworten