Fail2Ban fails to ban :-)

Discussion in 'Installation/Configuration' started by Wandering-Aimlessly, Jul 23, 2009.

  1. Wandering-Aimlessly

    Wandering-Aimlessly New Member

    Hi people.

    I have spent 2 days trying to get Fail2Ban to work. I have read everything I can find without success, so it is time to ask.

    I have installed Fail2ban on a test server and after some messing with the configs got it working well. Then I tried to install on a production box but it just won't work. Both boxes are running Centos 5.3 and are reasonably identical (except the hardware of course). I have even copied the configs from the test to the production box.

    Fail2ban seems to be running and passes all the tests I can come up with but it just fails to ban any attempts at brute force SSH.

    Here are the configs/results of tests etc :-

    # fail2ban-client status
    # fail2ban-regex /var/log/secure /etc/fail2ban/filter.d/sshd.conf

    Here is the result of a deliberate wrong user login (from /var/log/secure):
    To ensure that there was not time issue,I immediately ran the date command
    There are no local config files so here are the regular files (snipped for brevity):



    I have not changed iptables.conf

    When I stop and start Fail2ban an email is sent confirming the stop and another for the start.

    The version I installed was fail2ban-0.8.2-3.el5.rf.noarch.rpm from
    DAG packages for Red Hat Linux el5 x86_64.

    Hoping that someone can help. Thanks for reading.

    Edited to add: var/log/fail2ban.log shows no entry for failed logins but does show entries for the start/stop.
    Last edited: Jul 23, 2009
  2. Flash

    Flash New Member

    You will need at least 3 failed logins from thesame IP in order for fail2ban to ban the IP.
  3. Wandering-Aimlessly

    Wandering-Aimlessly New Member

    Thanks Flash, I only included one failure for the sake of brevity, there have been dozens within the required 10 minute period.
  4. Wandering-Aimlessly

    Wandering-Aimlessly New Member

    Problem solved

    Got the problem nailed !

    In case anyone else suffers the same problem, here are the details.

    In Jail.conf there is a "backend" option, this can be set to "gamin", "polling" or "auto" which chooses whatever method is available.

    If I set this to "polling" Fail2Ban started working but "auto" or "gamin"! it didn't.

    I could not find why gamin was not working and could find little information on testing/debugging it.

    In the end, out of desperation I rebooted the server.

    And the problem went away. :D:D:D
  5. rlischer

    rlischer Member

    Thanks for this! Did you change something in "sshd.conf" ? I made the change to "pooling". It still does not ban me after 3, but drops me after 7 and lets me go right back and do it 7 more times. I must be missing something somewhere.
    I don't know why you looked at the date, mine says "Fri Aug 14 04:17:10 EDT 2009" which has the wrong time for me. Also, I did fix the path to var\log\secure.

  6. Wandering-Aimlessly

    Wandering-Aimlessly New Member


    No, I made no changes to sshd.conf.

    The only experience I have is on Cento5, is that what you are running ?

    I guess you could make sure that the log time is the same as the clock time. If the logs don't have the same time as the clock (I don't know how this happens), funny things can happen.

    I did that by logging on and then immediately running date" in an SSH session and confirm that the time shown is the same, or at least very near the time shown in the log file entry.

    If the time is correct, please post the content of your jail.conf
  7. rlischer

    rlischer Member

    I am in centos 5.3 and I did check the times and they match now server/log. Here is my jail.conf Thanks!

    # FailBan configuration file
    # Author: Cyril Jaquier
    # $Revision: 617 $
    # The DEFAULT allows a global definition of the options. They can be override
    # in each jail afterwards.
    # "ignoreip" can be an IP address, a CIDR mask or a DNS host. Fail2ban will not
    # ban a host which matches an address in this list. Several addresses can be
    # defined using space separator.
    ignoreip =
    # "bantime" is the number of seconds that a host is banned.
    bantime  = 600
    # A host is banned if it has generated "maxretry" during the last "findtime"
    # seconds.
    findtime  = 600
    # "maxretry" is the number of failures before a host get banned.
    maxretry = 3
    # "backend" specifies the backend used to get files modification. Available
    # options are "gamin", "polling" and "auto". This option can be overridden in
    # each jail too (use "gamin" for a jail and "polling" for another).
    # gamin:   requires Gamin (a file alteration monitor) to be installed. If Gamin
    #          is not installed, Fail2ban will use polling.
    # polling: uses a polling algorithm which does not require external libraries.
    # auto:    will choose Gamin if available and polling otherwise.
    backend = polling
    # This jail corresponds to the standard configuration in Fail2ban 0.6.
    # The mail-whois action send a notification e-mail with a whois request
    # in the body.
    enabled  = true
    filter   = sshd
    action   = iptables[name=SSH, port=ssh, protocol=tcp]
               sendmail-whois[name=SSH, [email protected], [email protected]]
    logpath  = /var/log/secure
    maxretry = 3
    enabled  = true
    filter   = proftpd
    action   = iptables[name=ProFTPD, port=ftp, protocol=tcp]
               sendmail-whois[name=ProFTPD, [email protected], [email protected]]
    logpath  = /var/log/proftpd/proftpd.log
    maxretry = 3
    # This jail forces the backend to "polling".
    enabled  = true
    filter   = sasl
    backend  = polling
    action   = iptables[name=sasl, port=smtp, protocol=tcp]
               sendmail-whois[name=sasl, [email protected], [email protected]]
    logpath  = /var/log/mail.log
    # Here we use TCP-Wrappers instead of Netfilter/Iptables. "ignoreregex" is
    # used to avoid banning the user "myuser".
    enabled     = true
    filter      = sshd
    action      = hostsdeny
                  sendmail-whois[name=SSH, [email protected], [email protected]]
    ignoreregex = for myuser from
    logpath     = /var/log/secure
    # This jail demonstrates the use of wildcards in "logpath".
    # Moreover, it is possible to give other files on a new line.
    enabled  = true
    filter   = apache-auth
    action   = hostsdeny
    logpath  = /var/log/apache*/*error.log
    maxretry = 3
    # The hosts.deny path can be defined with the "file" argument if it is
    # not in /etc.
    enabled  = true
    filter   = postfix
    action   = hostsdeny[file=/not/a/standard/path/hosts.deny]
               sendmail[name=Postfix, [email protected], [email protected]]
    logpath  = /var/log/postfix.log
    bantime  = 300
    # Do not ban anybody. Just report information about the remote host.
    # A notification is sent at most every 600 seconds (bantime).
    enabled  = true
    filter   = vsftpd
    action   = sendmail-whois[name=VSFTPD, [email protected], [email protected]]
    logpath  = /var/log/vsftpd.log
    maxretry = 5
    bantime  = 1800
    # Same as above but with banning the IP address.
    enabled  = true
    filter   = vsftpd
    action   = iptables[name=VSFTPD, port=ftp, protocol=tcp]
               sendmail-whois[name=VSFTPD, [email protected], [email protected]]
    logpath  = /var/log/vsftpd.log
    maxretry = 5
    bantime  = 1800
    # Ban hosts which agent identifies spammer robots crawling the web
    # for email addresses. The mail outputs are buffered.
    enabled  = true
    filter   = apache-badbots
    action   = iptables-multiport[name=BadBots, port="http,https"]
               sendmail-buffered[name=BadBots, lines=5, [email protected], [email protected]]
    logpath  = /var/www/*/logs/access_log
    bantime  = 172800
    maxretry = 1
    # Use shorewall instead of iptables.
    enabled  = true
    filter   = apache-noscript
    action   = shorewall
               sendmail[name=Postfix, [email protected], [email protected]]
    logpath  = /var/log/apache2/error_log
    # This jail uses ipfw, the standard firewall on FreeBSD. The "ignoreip"
    # option is overridden in this jail. Moreover, the action "mail-whois" defines
    # the variable "name" which contains a comma using "". The characters '' are
    # valid too.
    enabled  = true
    filter   = sshd
    action   = ipfw[localhost=]
               sendmail-whois[name="SSH,IPFW", [email protected], [email protected]]
    logpath  = /var/log/auth.log
    ignoreip =
    # These jails block attacks against named (bind9). By default, logging is off
    # with bind9 installation. You will need something like this:
    # 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.
    # This jail blocks UDP traffic for DNS requests.
    enabled  = true
    filter   = named-refused
    action   = iptables-multiport[name=Named, port="domain,953", protocol=udp]
               sendmail-whois[name=Named, [email protected], [email protected]]
    logpath  = /var/log/named/security.log
    ignoreip =
    # This jail blocks TCP traffic for DNS requests.
    enabled  = true
    filter   = named-refused
    action   = iptables-multiport[name=Named, port="domain,953", protocol=tcp]
               sendmail-whois[name=Named, [email protected], [email protected]]
    logpath  = /var/log/named/security.log
    ignoreip =
  8. rlischer

    rlischer Member

    Here is my break in attempt at 14:14 as root. I get dropped on 7th try.

    Aug 14 14:12:18 server sshd[8838]: reverse mapping checking getaddrinfo for failed - POSSIBLE BREAK-IN ATTEMPT!
    Aug 14 14:12:18 server sshd[8838]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=  user=root
    Aug 14 14:12:19 server sshd[8838]: Failed password for root from port 28645 ssh2
    Aug 14 14:12:43 server last message repeated 7 times
    Aug 14 14:12:43 server sshd[8839]: Disconnecting: Too many authentication failures for root
  9. Wandering-Aimlessly

    Wandering-Aimlessly New Member

    Sorry for the delay in this reply, been a busy weekend.

    I'm am far from being any sort of expert on the topic so please don't berate me if I am wrong. :)

    As I understand it :

    This part "[ssh-iptables]" says "deal with SSH attacks using iptables".

    And :

    This part "[ssh-tcpwrapper]" "deal with SSH attacks using tcpwrapper".

    In your config, you have both methods enabled. I wonder if that is the cause of the problem.

    I suggest that you disable all sections ("enabled = false") with the exception of one SSH section (either iptables or tcpwrapper) and test again.

    If that works ok, just enable the sections you need enabling.

    I initially enabled, SSH, proftpd and sasl testing at each stage. Then I enabled Dovecot which needed a little more work.

    Anyway, get it working in SSH first, then Pro Ftp, and test, then SASL. Once those are working we will sort out Dovecot.

    Good luck.

    Just had an afterthought. You might want to set the ban duration (bantime = 600) to something low during testing if you are using your own IP. I set mine to 60 (1 minute) so that I didn't have to wait ten minutes each time whilst testing.
    Last edited: Aug 17, 2009
  10. rlischer

    rlischer Member

    ok, thanks. I will give it a shot.

  11. rlischer

    rlischer Member

    Thanks a ton! It worked, I just got an email saying I was banned after 3 tries and I can't get back in. ;) Not it's time to get mail and ftp doing the same.
  12. Wandering-Aimlessly

    Wandering-Aimlessly New Member

    Well done.

    Once FTP and SASL are working, then try Dovecot. That one needs a little more work, post back if you need some help.

  13. rlischer

    rlischer Member

    I have FTP working now. I am not sure what SASL is so I am going to need to research that one.
  14. Wandering-Aimlessly

    Wandering-Aimlessly New Member

    SASL is the authentication used by the server when a user tries to send email through it (the server) rather than through their ISP so you might not be using that anyway.
    Last edited: Aug 18, 2009
  15. rlischer

    rlischer Member

    Ok, I do have Squirrel Mail and POP email set up and it seems to work. I guess there is just no security turned on for that yet. I am going to try to figure that out.


Share This Page