Fail2Ban Script für die VCP API

  • Hallo,


    vielen Dank für das Script. Bei mir funktioniert es jetzt auch.
    Ich hab jedoch festgestellt, dass es zu einem Fehler kommt, wenn in der Firewall bisher keine Regeln angelegt sind.
    Es kann dann eine Regeln eingetragen werden, sobald man versucht diese mit dem Script zu löschen kommt folgender Fehler:

    Code
    PHP Notice:  Trying to get property of non-object in /etc/fail2ban/nc_firewallapi_beta.php on line 113
    PHP Notice:  Trying to get property of non-object in /etc/fail2ban/nc_firewallapi_beta.php on line 113
    PHP Notice:  Trying to get property of non-object in /etc/fail2ban/nc_firewallapi_beta.php on line 113
    PHP Notice:  Trying to get property of non-object in /etc/fail2ban/nc_firewallapi_beta.php on line 113
    PHP Notice:  Trying to get property of non-object in /etc/fail2ban/nc_firewallapi_beta.php on line 113
    PHP Notice:  Trying to get property of non-object in /etc/fail2ban/nc_firewallapi_beta.php on line 113
    PHP Notice:  Trying to get property of non-object in /etc/fail2ban/nc_firewallapi_beta.php on line 113
    PHP Notice:  Trying to get property of non-object in /etc/fail2ban/nc_firewallapi_beta.php on line 113
    Rule not found in firewall.


    Ich fänd es auch praktisch wenn das Sript einen Kommentar mit Uhrzeit zu den Regeln schreibt. Wie etwa "Added by fail2ban at 11:26:19 20120412" oder ähnliches.


    Nochmal Danke für das Script :thumbup:

  • Hey,
    vielen Dank für den Hinweis. :)


    Das man den Kommentar via Webservice hinzufügen kann, stand leider nicht in der Doku im Wiki. Ich habe jetzt einfach mal als Schnellschuss das Feld "comment" in das Script aufgenommen und es funktioniert. :D


    Auch habe ich noch die Möglichkeit eingebaut, die Konfiguration in eine separate Datei auszulagern. Ich vergesse beim Commit jedes mal meine Zugangsdaten wieder zu entfernen. *grml* Nun stehen die bei mir in einer eigenen Datei und die steht beim Commit auf ignore. *G*


    Alle Änderungen kann man im Log nachlesen: scripts.git/log
    Das Script: scripts.git/blob - linux/nc_firewallapi_beta.php
    Beispiel für externe Konfiguration: scripts.git/blob - linux/nc_vcp_settings_example.php


    Bitte testen. :)

  • Hallo,


    das ging ja schnell. Danke für die comments-Funktion. :)
    Bei mir funktioniert es sowei. Der Fehler beim löschen der ersten Regel, wenn sonst keine vorhanden sind, besteht jedoch immer noch. Die PHP Fehlermeldung ist zwar weg, aber das löschen geht noch nicht:


    Code
    # php -f /etc/fail2ban/nc_firewallapi_beta.php add INPUT "10.0.0.1" DROP      
    Firewall rule added.
    # php -f /etc/fail2ban/nc_firewallapi_beta.php delete INPUT "10.0.0.1" DROP   
    Rule not found in firewall.
    # php -f /etc/fail2ban/nc_firewallapi_beta.php add INPUT "10.0.0.2" DROP       
    Firewall rule added.
    # php -f /etc/fail2ban/nc_firewallapi_beta.php delete INPUT "10.0.0.1" DROP
    1 Firewall rule(s) deleted.
    # php -f /etc/fail2ban/nc_firewallapi_beta.php delete INPUT "10.0.0.2" DROP 
    Rule not found in firewall.


    Die Auslagerung der Konfiguration find ich sehr praktisch. So muss man nichts mehr bearbeiten, wenn es mal eine neue Version gibt.


    Vielen Dank :)

  • Genau das gleiche Problem habe ich auch.
    Die Regeln können nicht gelöscht werden


    Code
    IPTables wrapper script for netcup VCP firewall
    Version: 0.0.2
    (c) 2012 by Christian Blechert (http://fiae.ws)
    -------------------------------------------------------------
    
    
    
    
    Rule not found in firewall.

    V-Server Gold
    Debian Bullseye 64 Bit - ISPConfig 3.2.9

  • So... Ich habe jetzt mal meine ganzen Regeln alle gelöscht und den Fehler gefunden.
    Nun sollte es gehen.


    netcup
    Der Webservice liefert kein Array zurück, wenn nur eine Regel angelegt ist.
    Das ist ein wenig verwirrend...

    Habe ich letztes Jahr schon im Test Thread drauf hingewiesen und folgende Antwort bekommen:


    Neun von zehn stimmen in meinem Kopf sagen ich bin nicht verrückt, die zehnte summt die Melodie von Tetris.

  • Mhh... leider zu früh gefreut...
    Es kommt nun folgender Fehler:

    Code
    2012-04-24 17:50:20,517 fail2ban.actions: WARNING [ssh] Ban 218.108.224.84
    2012-04-24 18:00:21,340 fail2ban.actions: WARNING [ssh] Unban 218.108.224.84
    2012-04-24 18:00:21,616 fail2ban.actions.action: ERROR php -f /etc/fail2ban/firewallapi.php delete INPUT "218.108.224.84" DROP returned 100


    Wenn ich eine IP manuell banne und entbanne, dann funktioniert es, aber anscheinend nicht automatisch...

    V-Server Gold
    Debian Bullseye 64 Bit - ISPConfig 3.2.9

  • Bei mir funktioniert es Fehlerfrei.


    Hier eine mögliche Ursache: Problem fail2ban

  • hallo,


    ersteinmal danke für das script, läuft mit ipv4 einwandfrei.
    mit ipv6 klappt es bei mir nicht:


    Zitat

    sepp@www:~$ ssh -6 2a01:4f8:100:30a4:0:bc28:ec2b:1
    sepp@2a01:4f8:100:30a4:0:bc28:ec2b:1's password:
    Permission denied, please try again.

    usw...


    aus dem auth.log

    Zitat

    May 5 16:51:02 desete sshd[12032]: Failed password for sepp from 2a01:488:66:1000:b24d:4a24:0:1 port 39015 ssh2
    May 5 16:51:06 desete sshd[12032]: last message repeated 2 times
    May 5 16:51:06 desete sshd[12033]: Connection closed by 2a01:488:66:1000:b24d:4a24:0:1
    May 5 16:51:06 desete sshd[12032]: PAM 2 more authentication failures; logname= uid=0 euid=0 tty=ssh ruser= rhost=2a01:488:66:1000:b24d:4a24:0:1 user=sepp

    ein manueller test funktioniert, die regel erscheint auch im vcp

    Zitat

    root@desete:~# php -f /etc/fail2ban/firewallapi.php add INPUT 2a01:488:66:1000:b24d:4a24:0:1 DROP
    IPTables wrapper script for netcup VCP firewall
    Version: 0.0.2
    (c) 2012 by Christian Blechert (http://fiae.ws)
    -------------------------------------------------------------


    Firewall rule added.

    klappt bei euch wirklich v6 "von außen" ??


    danke+gruß

  • guter hinweis, danke.


    der failregex erfasst tatsächlich nur v4 adressen, habe dies nach dieser anleitung behoben: Fail2ban - wiki.debian-fr

    Zitat

    2012-05-05 17:38:59,490 fail2ban.actions: WARNING [ssh] Ban 2a01:488:66:1000:b24d:4a24:0:1
    2012-05-05 17:38:59,501 fail2ban.actions: WARNING [ssh-ip6tables] Ban 2a01:488:66:1000:b24d:4a24:0:1

    Ich musste das shell-script das im patch enthalten ist etwas anpassen, dann ging es. bekomme noch einen fehler wenn fail2ban das script aufruft, funktioniert aber trotzdem.
    hier muss noch etwas feintuning gemacht werden, dann ist es perfekt.


    [edit] hm... obwohl is quatsch. oben steht ja auch, dass sowohl ssh als auch mein neuer ssh-ip6tables das erkannt haben. der failregex erfasst auch v6 adressen

    Zitat

    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\-.^_]+)

    also kann man sich das gefrikkel sparen. keine ahnung, warum es in meinen ersten tests nicht ging....