Forum Linux.débutant fail2ban ne ban pas (enfin pas souvent)

Posté par  .
Étiquettes : aucune
1
22
mar.
2010
Bonjour,
ayant eu marre des :
sshd:
Authentication Failures:
unknown (95-107-30-77.dsl.orel.ru): 32 Time(s)
dans mes logs, je me suis dit qu'il était temps d'installer fail2ban.
Après avoir mis iptable et fail2ban, j'ai configuré ce dernier comme ceci :
less /etc/fail2ban/fail2ban.conf

# Option: loglevel
loglevel = 3

# Option: logtarget
logtarget = /var/log/fail2ban.log

# Option: socket
socket = /var/run/fail2ban/fail2ban.sock

et le fichier jail :
less /etc/fail2ban/jail.conf

[DEFAULT]

# "ignoreip" can be an IP address, a CIDR mask or a DNS host
ignoreip = 127.0.0.1
bantime = 600
maxretry = 3

backend = polling
banaction = iptables-multiport

[ssh]

enabled = true
port = ssh
filter = sshd
logpath = /var/log/auth.log
maxretry = 3

j'ai vérifié avec :
fail2ban-client status
Status
|- Number of jail: 2
`- Jail list: proftpd, ssh

j'ai testé avec
fail2ban-regex /var/log/auth.log /etc/fail2ban/filter.d/sshd.conf
résultat :
Date template hits:
6656835 hit(s): Month Day Hour:Minute:Second
0 hit(s): Weekday Month Day Hour:Minute:Second Year
0 hit(s): Weekday Month Day Hour:Minute:Second
0 hit(s): Year/Month/Day Hour:Minute:Second
0 hit(s): Day/Month/Year:Hour:Minute:Second
0 hit(s): Year-Month-Day Hour:Minute:Second
0 hit(s): Day-Month-Year Hour:Minute:Second[.Millisecond]
0 hit(s): TAI64N
0 hit(s): Epoch

Success, the total number of match is 100380

However, look at the above section 'Running tests' which could contain important
information.

(mon fichier commence au 10 fevrier jusqu'a maintenant)

j'ai testé depuis mon réseau local, et dans auth.log j'ai bien des erreurs :
Mar 10 21:08:13 valinor sshd[19907]: Failed none for invalid user zlol from 192.168.1.5 port 36557 ssh2
Mar 10 21:08:16 valinor sshd[19907]: Failed password for invalid user zlol from 192.168.1.5 port 36557 ssh2
Mar 10 21:22:29 valinor sshd[21102]: Invalid user zlol from 192.168.1.5
Mar 10 21:22:29 valinor sshd[21102]: Failed none for invalid user zlol from 192.168.1.5 port 34582 ssh2

et je suis bien banni :
less /var/log/fail2ban.log
2010-03-10 21:08:16,584 fail2ban.actions: WARNING [ssh] Ban 192.168.1.5
2010-03-10 21:18:16,748 fail2ban.actions: WARNING [ssh] Unban 192.168.1.5

j'ai même testé depuis le boulot, et là encore je suis banni :
2010-03-15 12:00:26,189 fail2ban.actions: WARNING [ssh] Ban xx.23.212.xx
2010-03-15 12:00:26,258 fail2ban.actions.action: ERROR iptables -n -L INPUT | grep -q fail2ban-ssh returned 100
2010-03-15 12:00:26,258 fail2ban.actions.action: ERROR Invariant check failed. Trying to restore a sane environment
2010-03-15 12:00:26,414 fail2ban.actions.action: ERROR iptables -D INPUT -p tcp -m multiport --dports ssh -j fail2ban-ssh
iptables -F fail2ban-ssh
iptables -X fail2ban-ssh returned 100
2010-03-15 12:10:26,389 fail2ban.actions: WARNING [ssh] Unban xx.23.212.xx
(alors là, j'avoue y'a eu des erreurs, et je ne vois pas trop ce que c'est)

mais les vrais méchants, eu, ils passent toujours, comme je peux le voir dans mes logs, par ex le 21 :
sshd:
Authentication Failures:
unknown (static-217-133-97-38.clienti.tiscali.it): 12295 Time(s)
root (static-217-133-97-38.clienti.tiscali.it): 70 Time(s)
ftp (static-217-133-97-38.clienti.tiscali.it): 16 Time(s)
backup (static-217-133-97-38.clienti.tiscali.it): 11 Time(s)
games (static-217-133-97-38.clienti.tiscali.it): 11 Time(s)
mail (static-217-133-97-38.clienti.tiscali.it): 9 Time(s)
mysql (static-217-133-97-38.clienti.tiscali.it): 9 Time(s)
news (static-217-133-97-38.clienti.tiscali.it): 8 Time(s)
clamav (static-217-133-97-38.clienti.tiscali.it): 7 Time(s)
postfix (static-217-133-97-38.clienti.tiscali.it): 7 Time(s)
daemon (static-217-133-97-38.clienti.tiscali.it): 6 Time(s)
nobody (static-217-133-97-38.clienti.tiscali.it): 6 Time(s)
proxy (static-217-133-97-38.clienti.tiscali.it): 6 Time(s)
sshd (static-217-133-97-38.clienti.tiscali.it): 6 Time(s)
www-data (static-217-133-97-38.clienti.tiscali.it): 6 Time(s)
lp (static-217-133-97-38.clienti.tiscali.it): 4 Time(s)
amavis (static-217-133-97-38.clienti.tiscali.it): 3 Time(s)
sync (static-217-133-97-38.clienti.tiscali.it): 3 Time(s)
uucp (static-217-133-97-38.clienti.tiscali.it): 3 Time(s)
bug (static-217-133-97-38.clienti.tiscali.it): 2 Time(s)
gnats (static-217-133-97-38.clienti.tiscali.it): 2 Time(s)
list (static-217-133-97-38.clienti.tiscali.it): 2 Time(s)
man (static-217-133-97-38.clienti.tiscali.it): 2 Time(s)
media (static-217-133-97-38.clienti.tiscali.it): 2 Time(s)
gart (localhost): 1 Time(s)
root (192.107.104.23): 1 Time(s)
root (222.169.228.77): 1 Time(s)
sys (static-217-133-97-38.clienti.tiscali.it): 1 Time(s)
unknown (221.194.128.66): 1 Time(s)
Invalid Users:
Unknown Account: 12296 Time(s)
Sessions Opened:
gart: 8 Time(s)
nx: 8 Time(s)

Des idées sur ce que je n'ai pas bien fait ou ce qui ne vas pas ?
  • # ftp

    Posté par  (site web personnel) . Évalué à 1.

    La section ftp dans le fichier jail.conf est-elle validée ?

    Système - Réseau - Sécurité Open Source

    • [^] # Re: ftp

      Posté par  . Évalué à 1.

      oui, la section proftpd est active et fonctionne
      [proftpd]

      enabled = true
      port = ftp,ftp-data,ftps,ftps-data
      filter = proftpd
      logpath = /var/log/proftpd/proftpd.log
      maxretry = 4

      je n'en ai pas parlé, parce qu'elle a l'air de marcher comme il faut (testé depuis le reseau local aussi, et j'ai été banni. Pas testé depuis ailleurs, je n'ai pas de tentative de ce coté)
  • # Lignes ERROR

    Posté par  . Évalué à 2.

    Les lignes avec ERROR sont étranges. Il faut vérifier que le problème ne vienne pas de là.

    Débrouilles-toi pour être banni depuis une adresse. Pour être vraiment banni, pas juste une indication dans le journal de fail2ban. Ensuite tu vérifies que netfilter contient bien le banissement. Avec iptables-save ou iptables -L par exemple.

    iptables-save --> -A fail2ban-ssh -s 1.2.3.4/32 -j DROP
    iptables -L --> DROP all -- 1.2.3.4 anywhere

    note: nos règles sont bannissement total (au lieu d'un seul port).
    • [^] # Re: Lignes ERROR

      Posté par  . Évalué à 2.

      oui, les lignes d'erreur sont bizarres, mais je ne sais pas trop d'où ça vient.
      J'ai essayé avec un ami de voir s'il était banni, et le résultat est oui :

      auth.log :
      Mar 23 21:36:51 valinor sshd[27702]: Invalid user bbob from xx.168.169.xx
      Mar 23 21:36:51 valinor sshd[27702]: Failed none for invalid user bbob from xx.168.169.xx port 53209 ssh2
      Mar 23 21:37:00 valinor sshd[27702]: pam_unix(sshd:auth): check pass; user unknown
      Mar 23 21:37:00 valinor sshd[27702]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=rke29-1-xx-168-169-xx.fbx.proxad.net
      Mar 23 21:37:02 valinor sshd[27702]: Failed password for invalid user bbob from xx.168.169.xx port 53209 ssh2


      fail2ban.log
      2010-03-23 21:37:04,441 fail2ban.actions: WARNING [ssh] Ban xx.168.169.xx
      2010-03-23 21:47:04,661 fail2ban.actions: WARNING [ssh] Unban xx.168.169.xx


      iptables -L

      iptables -L
      [sudo] password for gart:
      Chain INPUT (policy ACCEPT)
      target prot opt source destination
      fail2ban-ssh tcp -- anywhere anywhere multiport dports ssh
      ACCEPT all -- anywhere anywhere
      ACCEPT icmp -- anywhere anywhere
      ACCEPT igmp -- anywhere anywhere
      ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
      ACCEPT tcp -- anywhere anywhere tcp dpt:ssh
      ACCEPT tcp -- anywhere anywhere tcp dpt:smtp
      ACCEPT tcp -- anywhere anywhere tcp dpt:imap2
      ACCEPT tcp -- anywhere anywhere tcp dpt:ftp
      ACCEPT tcp -- anywhere anywhere tcp dpt:www
      ACCEPT tcp -- anywhere anywhere tcp dpt:https
      ACCEPT udp -- anywhere anywhere udp dpt:1234
      ACCEPT udp -- anywhere 224.0.0.251 udp dpt:mdns
      LOG all -- anywhere anywhere LOG level warning prefix `paquet IPv4 inattendu '
      REJECT all -- anywhere anywhere reject-with icmp-port-unreachable

      Chain FORWARD (policy ACCEPT)
      target prot opt source destination

      Chain OUTPUT (policy ACCEPT)
      target prot opt source destination

      Chain fail2ban-ssh (1 references)
      target prot opt source destination
      DROP all -- rke29-1-xx-168-169-xx.fbx.proxad.net anywhere
      RETURN all -- anywhere anywhere

      mais les vrais méchants, ils ont l'air de toujours passer eux :(
      • [^] # Re: Lignes ERROR

        Posté par  . Évalué à 2.

        On voit dans l'exemple d'attaque réelle que tu donnes que les deux tentatives ont été effectuées à 14 minutes d'écart. Il s'agit peut-être du paramètre "findtime" qui est trop court. N'hésites pas à mettre une bonne grosse valeur (au moins 600, mais plutôt 3600). Profites-en pour mettre "maxretry" à une valeur faible, et "bantime" à une valeur élevée (au minimum 24 heures).

        Avantage: ça filtre bien les chiants-mais-pas-malins.
        Inconvénient: si tu t'authentifie mal 3 fois en une heure, bye bye :-)

        Ce que j'utilise est un sshd sur le port 22 qui refuse _toujours_ les connexions. Et le vrai sshd est sur un autre port.
        Résultat, l'autre port n'ai jamais attaqué.
        • [^] # Re: Lignes ERROR

          Posté par  . Évalué à 1.

          je vais essayer de changer ces valeurs, mais ce que tu me dis par rapport au findtime me parait bizarre, car dans mes logs, pour hier :

          grep "^Mar 23.*sshd" /var/log/auth.log :

          Mar 23 09:28:30 valinor sshd[14093]: Failed password for invalid user simanekv from 173.45.64.202 port 53218 ssh2
          Mar 23 09:28:32 valinor sshd[14096]: Invalid user kankova from 173.45.64.202
          Mar 23 09:28:32 valinor sshd[14096]: pam_unix(sshd:auth): check pass; user unknown
          Mar 23 09:28:32 valinor sshd[14096]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=ca.40.2d.static.xlhost.com
          Mar 23 09:28:34 valinor sshd[14096]: Failed password for invalid user kankova from 173.45.64.202 port 53422 ssh2
          Mar 23 09:28:35 valinor sshd[14099]: Invalid user heimlich from 173.45.64.202
          Mar 23 09:28:35 valinor sshd[14099]: pam_unix(sshd:auth): check pass; user unknown
          Mar 23 09:28:35 valinor sshd[14099]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=ca.40.2d.static.xlhost.com
          Mar 23 09:28:37 valinor sshd[14099]: Failed password for invalid user heimlich from 173.45.64.202 port 53623 ssh2
          Mar 23 09:28:38 valinor sshd[14101]: Invalid user fiala from 173.45.64.202
          Mar 23 09:28:38 valinor sshd[14101]: pam_unix(sshd:auth): check pass; user unknown
          Mar 23 09:28:38 valinor sshd[14101]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=ca.40.2d.static.xlhost.com
          Mar 23 09:28:40 valinor sshd[14101]: Failed password for invalid user fiala from 173.45.64.202 port 53805 ssh2
          Mar 23 09:28:41 valinor sshd[14104]: Invalid user brazda from 173.45.64.202

          plusieurs essais depuis la même ip, en quelques secondes, il aurait du etre banni, non ? et bien non :(

          un truc que je n'ai pas précisé, mon serveur est derrière un routeur, et le port 22 est bloqué sur le routeur, et le port 2214 est redirigé vers cette machine, sur le port 22. Mais au final ils (les méchants) devraient etre banni quand même, vu que moi (et mon pote) on se fait bannir. Ou alors mon fail2ban est con
          • [^] # Re: Lignes ERROR

            Posté par  . Évalué à 2.

            Heu... en effet :-)

            Tu es certain que le bannissement fonctionne toujours ? Par exemple depuis ton travail. Ensuite tu compares les entrées de auth.log histoire de voir si l'expression régulière ne poserait pas problème.
            • [^] # Re: Lignes ERROR

              Posté par  . Évalué à 1.

              oui, normalement ça marche toujours, et pour les entrées dans auth.log, elles me semblent a peu pres pareil.
              Par ex, les logs de mon pote, qui est banni sont bien :
              Mar 23 21:36:51 valinor sshd[27702]: Invalid user bbob from xx.168.169.xx
              Mar 23 21:36:51 valinor sshd[27702]: Failed none for invalid user bbob from xx.168.169.xx port 53209 ssh2
              Mar 23 21:37:00 valinor sshd[27702]: pam_unix(sshd:auth): check pass; user unknown
              Mar 23 21:37:00 valinor sshd[27702]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=rke29-1-xx-168-169-xx.fbx.proxad.net
              Mar 23 21:37:02 valinor sshd[27702]: Failed password for invalid user bbob from xx.168.169.xx port 53209 ssh2

              et
              pour un mec pas banni :
              Mar 23 09:28:32 valinor sshd[14096]: Invalid user kankova from 173.45.64.202
              Mar 23 09:28:32 valinor sshd[14096]: pam_unix(sshd:auth): check pass; user unknown
              Mar 23 09:28:32 valinor sshd[14096]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=ca.40.2d.static.xlhost.com
              Mar 23 09:28:34 valinor sshd[14096]: Failed password for invalid user kankova from 173.45.64.202 port 53422 ssh2

              bref, un gros mystère pour moi :(

Suivre le flux des commentaires

Note : les commentaires appartiennent à celles et ceux qui les ont postés. Nous n’en sommes pas responsables.