rebootnow
Goto Top

NextcloudPi fail2ban password-protection für public shares

Hallo zusammen,

ich habe auf einem Raspberry Pi 4 4Gb NextcloudPi als heimische Cloud installiert.
Versionen:
- NextcloudPi V 1.26.2
- Nextcloud 18.0.5.1

NextcloudPi kommt u.a. mit aktivierbarem und vorkonfiguriertem fail2ban zum Schutz vor brute-force Attacken für ssh und und den https-User-Login, was auch wunderbar funktioniert.

Mir ist jedoch aufgefallen, dass der fail2ban-Schutz nicht die Passwortabfrage bei öffentlich geteilten Shares umfasst.

Im Nextcloudforum gibt es zu dieser Frage einen Thread:
(How to ban IP via shared links protected form https://help.nextcloud.com/t/how-to-ban-ip-via-shared-links-protected-fo ..)

Fail2ban is correctly banning IPs that try to force the login form. That’s really fine, and I would like to extend this feature to the form on shared links protected by password. Is there a way to do that?

mit einer leider nur kurzen und zumindest für mich (und einen weiteren User dort) nicht klaren Antwort:

Yeah, you’re right about bruteforce. And concerning Fail2ban, there’s a way to catch people trying to log on the shared link password page.
I’ve created a filter with this regex:
^<HOST> - - .*"POST /s/******ENTER*HASH*******/authenticate/showShare HTTP/2.0" 200  
And it works ! It’s important to keep the 200 response code, cause in case of success, it’s a redirection 303.


Inhalt der nextcloud.conf von fail2ban (/etc/fail2ban/filter.d/nextcloud.conf)
[INCLUDES]
before = common.conf

[Definition]
_groupsre = (?:(?:,?\s*"\w+":(?:"[^"]+"|\w+))*)  
failregex = ^\{%(_groupsre)s,?\s*"remoteAddr":"<HOST>"%(_groupsre)s,?\s*"message":"Login failed:  
datepattern = ,?\s*"time"\s*:\s*"%%Y-%%m-%%d[T ]%%H:%%M:%%S(%%z)?"  
ignoreregex =

Hat vielleicht jemand eine Idee, wie man das umzusetzen könnte?

Vorweg schon einmal vielen Dank.

Content-Key: 583635

Url: https://administrator.de/contentid/583635

Ausgedruckt am: 28.03.2024 um 20:03 Uhr

Mitglied: rebootnow
rebootnow 02.07.2020 aktualisiert um 21:28:19 Uhr
Goto Top
Für Interessierte hier eine Lösung, um die passwortgeschützten public shares bei NextcloudPi mit fail2ban abzusichern:

nehmen wir an, der Link zum passwortgeschützen public share ist:
https://mynextcloud.dyndns.org/index.php/s/oNrtAVXLQKeqC4M/authenticate/showShare

dann steht oNrtAVXLQKeqC4M in der URL für den share-spezifischen Hash.

um diesen passwortgeschützten Share mit Fail2Ban abzusichern braucht es folgende Schritte (natürlich vorausgesetzt, dass fail2ban bereits aktiviert ist und läuft):

1. Eine neue fail2ban-Filterdatei erstellen:

$ sudo nano /etc/fail2ban/filter.d/ncshareprotection.conf

und folgendes einfügen:

[Definition]
failregex = ^<HOST> - - \[.*\] "POST .*/s/oNrtAVXLQKeqC4M/authenticate/showShare HTTP/2.0" 200 .*  
datepattern = ^[^\[]*\[(%%d/%%b/%%Y:%%H:%%M:%%S %%z)\]
ignoreregex =

2. Den neuen Filter in der jail.local bekannt machen:

$ sudo nano /etc/fail2ban/jail.local

hier am Ende einfügen:

[ncshareprotection]
enabled  = true
port     = http,https
filter   = ncshareprotection
logpath  = /var/log/apache2/nc-access.log
maxretry = 3

$ sudo service fail2ban restart

Überprüfen ob es funktioniert:

$ fail2ban-regex /var/log/apache2/nc-access.log /etc/fail2ban/filter.d/ncshareprotection.conf


möchte man nicht nur einen spezifischen share, sondern alle shares absichern, dann sollte folgender Eintrag in der oben erstellten ncshareprotection.conf funktionieren:

[Definition]
failregex = ^<HOST> - - \[.*\] "POST .*/s/.*/authenticate/showShare HTTP/2.0" 200 .*  
datepattern = ^[^\[]*\[(%%d/%%b/%%Y:%%H:%%M:%%S %%z)\]
ignoreregex =

Falls man die e-Mail-Benachrichtigung für Fail2Ban konfiguriert hat, wird man nun auch per e-mail über etwaige bans bei den passwortgeschützten public shares informiert.