Fail2Ban

Diskutiere Fail2Ban im Sicherheit Forum im Bereich Plesk-Forum; Fail2Ban Was macht Fail2Ban überhaupt? Fail2Ban bannt eine IP, wenn diese z.B. zu oft das falsche Passwort per SSH eingegeben hat oder blockt die IP ...

Ergebnis 1 bis 7 von 7
  1. #1

    Fail2Ban

    Fail2Ban

    Was macht Fail2Ban überhaupt?
    Fail2Ban bannt eine IP, wenn diese z.B. zu oft das falsche Passwort per SSH eingegeben hat oder blockt die IP wenn eine nicht bestehende Datei des Öfteren über den Apache aufgerufen wurde.
    Der Bann kann Dauerhaft oder für z.B. 600 Sekunden sein.

    Installation
    Installation unter Debian Etch

    /etc/apt/sources.list
    Zeile hinzufügen:
    Code:
    deb http://ftp.de.debian.org/debian sid main
    Code:
    #apt-get update
    Code:
    #apt-get install fail2ban
    IPTables nur installieren falls noch nicht installiert
    #apt-get install iptables
    /etc/apt/sources.list
    Zeile entfernen
    Code:
    deb http://ftp.de.debian.org/debian sid main
    Code:
    #apt-get update
    Installation unter Debian 3.1
    /etc/apt/source.list
    Code:
    deb http://ftp.de.debian.org/backports.org/ sarge-backports main contrib non-free
    Weitere Mirrors hier

    Code:
    #apt-get update
    Code:
    #apt-get -t sarge-backports install fail2ban
    Installation unter Suse
    Code:
    Packman Paketdatenbank aktivieren
    #yast2
    Gehe im YaST auf Software > Community Repositories
    Aktiviere dann den Packman Repository und drücke [Finish]
    Verlasse danach YaST
    #yast2 -i fail2ban
    chkconfig –add fail2ban
    /etc/init.d/fail2ban start
    Konfiguration
    Konfigurationsdatei unter /etc/fail2ban/jail.conf

    Standardmäßig ist SSH gegen eine Brute Force Attacke geschützt

    fail2ban Konfiguration (kann je nach Version etwas unterschiedlich sein)
    (Beispielkonfiguration)

    Default Werte:
    Code:
    Maxretry = Anzahl der Fehlversuche bevor eine IP gesperrt wird
    bantime = Zeit (Sekunden) die eine IP gesperrt wird
    ignoreip = IPs die ausgeschlossen werden
    logtargets = Pfad zur Logdatei
    Zur Info:
    bantime = 600 (Auf einem Produktivsystem sollte man diese höher setzen -> In Sekunden)
    Code:
    # Fail2Ban configuration file.
    #
    # This file was composed for Debian systems from the original one
    #  provided now under /usr/share/doc/fail2ban/examples/jail.conf
    #  for additional examples.
    #
    # To avoid merges during upgrades DO NOT MODIFY THIS FILE
    # and rather provide your changes in /etc/fail2ban/jail.local
    #
    # Author: Yaroslav O. Halchenko <debian@onerussian.com>
    #
    # $Revision: 281 $
    #
    
    # The DEFAULT allows a global definition of the options. They can be override
    # in each jail afterwards.
    
    [DEFAULT]
    
    # "ignoreip" can be an IP address, a CIDR mask or a DNS host
    ignoreip = 127.0.0.1
    bantime  = 600 
    maxretry = 3
    
    # "backend" specifies the backend used to get files modification. Available
    # options are "gamin", "polling" and "auto".
    # yoh: For some reason Debian shipped python-gamin didn't work as expected
    #      This issue left ToDo, so polling is default backend for now
    backend = polling
    
    #
    # Destination email address used solely for the interpolations in
    # jail.{conf,local} configuration files.
    destemail = root@localhost
    
    #
    # ACTIONS
    #
    
    # Default banning action (e.g. iptables, iptables-new,
    # iptables-multiport, shorewall, etc) It is used to define 
    # action_* variables. Can be overriden globally or per 
    # section within jail.local file
    banaction = iptables-multiport
    
    # email action. Since 0.8.1 upstream fail2ban uses sendmail
    # MTA for the mailing. Change mta configuration parameter to mail
    # if you want to revert to conventional 'mail'.
    mta = sendmail
    
    # Default protocol
    protocol = tcp
    
    #
    # Action shortcuts. To be used to define action parameter
    
    # The simplest action to take: ban only
    action_ = %(banaction)s[name=%(__name__)s, port="%(port)s", protocol="%(protocol)s]
    
    # ban & send an e-mail with whois report to the destemail.
    action_mw = %(banaction)s[name=%(__name__)s, port="%(port)s", protocol="%(protocol)s]
                  %(mta)s-whois[name=%(__name__)s, dest="%(destemail)s", protocol="%(protocol)s]
    
    # ban & send an e-mail with whois report and relevant log lines
    # to the destemail.
    action_mwl = %(banaction)s[name=%(__name__)s, port="%(port)s", protocol="%(protocol)s]
                   %(mta)s-whois-lines[name=%(__name__)s, dest="%(destemail)s", logpath=%(logpath)s]
     
    # Choose default action.  To change, just override value of 'action' with the
    # interpolation to the chosen action shortcut (e.g.  action_mw, action_mwl, etc) in jail.local
    # globally (section [DEFAULT]) or per specific section 
    action = %(action_)s
    
    #
    # JAILS
    #
    
    # Next jails corresponds to the standard configuration in Fail2ban 0.6 which
    # was shipped in Debian. Enable any defined here jail by including
    #
    # [SECTION_NAME] 
    # enabled = true
    
    #
    # in /etc/fail2ban/jail.local.
    #
    # Optionally you may override any other parameter (e.g. banaction,
    # action, port, logpath, etc) in that section within jail.local
    
    [ssh]
    
    enabled = true
    port	= ssh,sftp
    filter	= sshd
    logpath  = /var/log/auth.log
    maxretry = 2
    
    # Generic filter for pam. Has to be used with action which bans all ports
    # such as iptables-allports, shorewall
    [pam-generic]
    
    enabled = false
    # pam-generic filter can be customized to monitor specific subset of 'tty's
    filter	= pam-generic
    # port actually must be irrelevant but lets leave it all for some possible uses
    port = all
    banaction = iptables-allports
    port     = anyport
    logpath  = /var/log/auth.log
    maxretry = 6
    
    
    [ssh-ddos]
    
    enabled = true
    port    = ssh,sftp
    filter  = sshd-ddos
    logpath  = /var/log/auth.log
    maxretry = 3
    
    #
    # HTTP servers
    #
    
    [apache]
    
    enabled = false
    port	= http,https
    filter	= apache-auth
    logpath = /var/log/apache*/*access.log
    maxretry = 3
    
    # default action is now multiport, so apache-multiport jail was left
    # for compatibility with previous (<0.7.6-2) releases
    [apache-multiport]
    
    enabled   = true
    port	  = http,https
    filter	  = apache-auth
    logpath   = /var/log/apache*/*access.log
    maxretry  = 3
    
    [apache-noscript]
    
    enabled = true
    port    = http,https
    filter  = apache-noscript
    logpath = /var/log/apache*/*error.log
    maxretry = 3
    
    #
    # FTP servers
    #
    
    [vsftpd]
    
    enabled  = false
    port	 = ftp,ftp-data,ftps,ftps-data
    filter   = vsftpd
    logpath  = /var/log/vsftpd.log
    # or overwrite it in jails.local to be
    # logpath = /var/log/auth.log
    # if you want to rely on PAM failed login attempts
    # vsftpd's failregex should match both of those formats
    maxretry = 6
    
    
    [proftpd]
    
    enabled  = false
    port	 = ftp,ftp-data,ftps,ftps-data
    filter   = proftpd
    logpath  = /var/log/proftpd/proftpd.log
    maxretry = 6
    
    
    [wuftpd]
    
    enabled  = false
    port	 = ftp,ftp-data,ftps,ftps-data
    filter   = wuftpd
    logpath  = /var/log/auth.log
    maxretry = 6
    
    
    #
    # Mail servers
    #
    
    [postfix]
    
    enabled  = false
    port	 = smtp,ssmtp
    filter   = postfix
    logpath  = /var/log/mail.log
    
    
    [couriersmtp]
    
    enabled  = false
    port	 = smtp,ssmtp
    filter   = couriersmtp
    logpath  = /var/log/mail.log
    
    
    #
    # Mail servers authenticators: might be used for smtp,ftp,imap servers, so
    # all relevant ports get banned
    #
    
    [courierauth]
    
    enabled  = false
    port	 = smtp,ssmtp,imap2,imap3,imaps,pop3,pop3s
    filter   = courierlogin
    logpath  = /var/log/mail.log
    
    
    [sasl]
    
    enabled  = false
    port	 = smtp,ssmtp,imap2,imap3,imaps,pop3,pop3s
    filter   = sasl
    logpath  = /var/log/mail.log
    
    
    # DNS Servers
    
    # Mention: by default logging is off with bind installation.
    # Need smth like
    # logging {
    #       channel security_file { file "/var/log/named/security.log" versions 3 size 30m; severity dynamic; print-time yes; };
    # 		category security { security_file; };
    # }
    # in your named.conf to provide proper logging
    
    # Word of Caution:
    # Given filter can lead to DoS attack against your DNS server
    # since there is no way to assure that UDP packets come from the
    # real source IP
    [named-refused-udp]
    
    enabled  = false
    port     = domain,953
    protocol = udp
    filter   = named-refused
    logpath  = /var/log/named/security.log
    
    [named-refused-tcp]
    
    enabled  = false
    port     = domain,953
    protocol = tcp
    filter   = named-refused
    logpath  = /var/log/named/security.log
    Natürlich kann man die anderen Filter auch einschalten!!!!

    Herstellerseite:
    http://www.fail2ban.org

    •    

      MisterAd


        
       

  2. #2
    Kurzer Nachtrag. Sie könnte eine erfolgreiche Apache2 Konfig aussehen.

    Geblockt werden damit die Einträge:

    File does not exist ....
    ... not found or unable to stat

    Dabei werden Einträge mit favicon.ico ignoriert

    apache-noscript.conf
    Code:
    # Fail2Ban configuration file
    #
    # Author: Cyril Jaquier
    #
    # $Revision: 510 $
    #
    
    [Definition]
    
    # Option:  failregex
    # Notes.:  regex to match the password failure 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>\S+)
    # Values:  TEXT
    #
    failregex = ([[]client <HOST>[]] File does not exist: .*)|(.* not found or unable to stat)
    
    # Option:  ignoreregex
    # Notes.:  regex to ignore. If this regex matches, the line is ignored.
    # Values:  TEXT
    #
    ignoreregex = favicon.ico

  3. #3
    Möchte man nur die ganzen default Einträge weg bekommen, dann könnte man die apache-noscript auch so aufbauen:

    Code:
    # Fail2Ban configuration file
    #
    # Author: Cyril Jaquier
    #
    # $Revision: 510 $
    #
    
    [Definition]
    
    # Option:  failregex
    # Notes.:  regex to match the password failure 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>\S+)
    # Values:  TEXT
    #
    failregex = [[]client <HOST>[]] .* /var/www/vhosts/default/ 
    
    # Option:  ignoreregex
    # Notes.:  regex to ignore. If this regex matches, the line is ignored.
    # Values:  TEXT
    #
    ignoreregex = favicon.ico

  4. #4

    w00tw00t Scans stoppen mit Fail2Ban

    Hallo,

    Ja Fail2Ban kann eine Menge:weisswas:

    Hier mal ein Link zu einem HowTo, um w00tw00t Scans in den Griff zu bekommen: HowTo Fail2Ban -w00tw00t Scans

    Noch etwas ganz Wichtiges:

    Einige Serveradmins neigen dazu den SSH-Port zu verlegen, in solch einem Fall muss dieses auch Fail2Ban mitgeteilt werden, da Fail2Ban standartmäßig auf Port 22 lauscht.

    Gruß, Ready

  5. #5

    Cool AW: Fail2Ban

    viel gemeiner ist auf port 22 portsentry laufen zu lassen und den ssh port auf >1024 zu verlegen kurz vor und kurz nach dem neuen ssh port dann nochmals portsentry ansetzen. Und jeder verbindungsaufbau zu den Ports sorgt für einen schicken eintrag in der Firewall (sollte natürlich durch ein weiteres script auf ~20 ips und einen gewissen Zeitraum beschränkt werden) Die Firewall noch so konfigueren das Portscans erkannt werden und ignoriert werden....

  6. #6

    AW: Fail2Ban

    :thup: stimmt

    da hab ich doch auch noch ein HowTo zu: Portsentry

  7. #7

    AW: Fail2Ban

    Bei mir läuft fail2ban so, dass Loginversuche mit nicht existierenden usern bereits nach dem ersten Versuch für mehrere Tage komplett geblockt werden. Ausserdem habe ich die Aktion so erweitert, dass per whois versucht wird, eine abuse - Mailadresse oder zumindest eine gültige Mailadresse des besitzers zu ermitteln. Falls ja, wird automatisch eine Mail abgesetzt, die den Inhaber der IP informiert und den betreffenden Tail des Logs mit anhängt.
    Interessanterweise ist die Reaktion aus Fernost gleich Null, wogegen aus Südamerika in der Regel relativ schnell und in den seltensten Fällen mit einer automatisch generierten Mail geantwortet wird. Ob und in welcher Form man dort dann wirklich aktiv wird, bleibt nach wie vor fraglich. In europäischen Ländern (Frankreich ausgenommen) ist die Reaktion in der Regel prompt und automatisch generiert.
    Bleibt natürlcih fraglich, wieviel Erfolg das Ganze hat, aber ich bin der Meinung, wenn man keinen Druck macht, passiert überhaupt nichts. Für mich ist der Erfolg von fail2ban deutlich spürbar, alleine die Login - Versuche per SSH sind seither deutlich zurück gegangen von mehreren tausend auf < 50 pro Tag.

Fail2Ban

Besucher kamen mit folgenden Begriffen auf die Seite:

fail2ban vhost

fail2ban apache ddos

apache-noscript
plesk portsentry
fail2ban ddos
fail2ban
pam-generic
plesk fail2ban
w00tw00t fail2ban
fail2ban file does not exist
fail2ban error file not exist
fail2ban ssh-ddos
fail2ban pam-generic
postfix smtp falsche login versuche beschränken
fail2ban plesk
fail2ban ports
fail2ban mta
fail2ban apache-noscript
fail2ban mta postfix
fail2ban und plesk
fail2ban.actions.action: ERROR iptables -N fail2ban-ssh
fail2ban ssh ddos
fail2ban ignoreip
ignoreip = 127.0.0.1
fail2ban ssh port