Fail2ban regex qui ne match pas !

Bonsoir à tous,

J’ai un petit problème que je n’arrive pas à régler avec Fail2ban.

Sur mon serveur j’ai des logs “w00tw00t” bien connu sur Apache que je n’arrive pas à ban avec ma regex :

[code]nano /var/log/apache2/default.error.log

[Fri Dec 27 19:22:39 2013] [error] [client 87.98.134.225] client sent HTTP/1.1 request without hostname (see RFC2616 section 14.23): /w00tw00t.at.ISC.SANS.DFind:)
[Fri Dec 27 21:11:10 2013] [error] [client 198.50.168.196] client sent HTTP/1.1 request without hostname (see RFC2616 section 14.23): /w00tw00t.at.ISC.SANS.DFind:)
[Fri Dec 27 22:13:21 2013] [error] [client 198.50.168.196] client sent HTTP/1.1 request without hostname (see RFC2616 section 14.23): /w00tw00t.at.ISC.SANS.DFind:)
[Sat Dec 28 00:11:06 2013] [error] [client 37.59.73.93] client sent HTTP/1.1 request without hostname (see RFC2616 section 14.23): /w00tw00t.at.ISC.SANS.DFind:)
[Sat Dec 28 12:41:46 2013] [error] [client 94.23.26.88] client sent HTTP/1.1 request without hostname (see RFC2616 section 14.23): /w00tw00t.at.ISC.SANS.DFind:)[/code]

[code]nano /etc/fail2ban/jail.local

[apache-w00tw00t]

enabled = true
filter = apache-w00tw00t
action = iptables[name=apache-w00tw00t,port=80,protocol=tcp]
logpath = /var/log/apache*/*error.log
maxretry = 1[/code]

[code]nano /etc/fail2ban/filter.d/apache-w00tw00t.conf

[Definition]

failregex = ^ -."GET /w00tw00t.at.ISC.SANS.DFind:).".*

ignoreregex =[/code]

Quand je test ma regex rien ne match :

[code]fail2ban-regex /var/log/apache2/default.error.log /etc/fail2ban/filter.d/apache-w00tw00t.conf

Running tests

Use regex file : /etc/fail2ban/filter.d/apache-w00tw00t.conf
Use log file : /var/log/apache2/default.error.log

Results

Failregex
|- Regular expressions:
| [1] ^ -."GET /w00tw00t.at.ISC.SANS.DFind:).".*
|
`- Number of matches:
[1] 0 match(es)

Ignoreregex
|- Regular expressions:
|
`- Number of matches:

Summary

Sorry, no match

Look at the above section ‘Running tests’ which could contain important
information.[/code]

Auriez-vous une idée du problème car je comprend pas, la regex devrait en théorie fonctionner…

Merci
Cordialement

Pour ceux à qui il leur arrive le même problème, à force de chercher sur google, j’ai trouvé une regex qui fonctionne correctement.
Dans “/etc/fail2ban/filter.d/apache-w00tw00t.conf” mettre :

[code]# w00tw00t.at.ISC.SANS.DFind

[Definition]

Option: failregex

Notes.: regex to match the w00tw00t scan messages in the logfile. The

host must be matched by a group named “host”. The tag “” can

be used for standard IP/hostname matching.

Values: TEXT

failregex = [[]client []] (client sent HTTP/1.1 request without hostname|Invalid method in request|request failed: URI too long|erroneous characters after protocol string)

Option: ignoreregex

Notes.: regex to ignore. If this regex matches, the line is ignored.

Values: TEXT

ignoreregex =[/code]

Salut,

Ceci devrait largement conforter cette dernière et ta quête. :wink:

failregex = [[]client <HOST>[]] (client sent HTTP/1.1 request without hostname|Invalid method in request|request failed: URI too long|erroneous characters after protocol string) ^<HOST> -.*"GET \/w00tw00t\.at\.ISC\.SANS\.DFind\:\).*".* ^<HOST> -.*"GET \/w00tw00t.*".* .*\[client <HOST>.*w00tw00t.* ^<HOST> -.*"GET \/w00tw00t.at.ISC.SANS.DFind\:\).*".* ^<HOST> -.*"GET \/w00tw00t.at.ISC.SANS.MSlog\:\).*".* ^<HOST> -.*"GET \/w00tw00t.at.ISC.SANS.test0\:\).*".* ^<HOST> -.*"GET \/w00tw00t.at.ISC.SANS.test\:\).*".* ^<HOST> -.*"GET \/w00tw00t.at.ISC.SANS.test1\:\).*".* ^<HOST> -.*"GET \/w00tw00t.at.blackhats.romanian.anti-sec\:\).*".* ^<HOST> -.*"GET \[\w{1,3} \w{1,3} \d{1,2} \d{1,2}:\d{1,2}:\d{1,2} \d{1,4}] \[error] \[client Ton_IP File does not exist: \/.{1,20}\/(w00tw00t|wootwoot|WootWoot|WooTWooT).{1,250}.*".* ^<HOST> -.*"GET \/nonexistenshit.*".* ^<HOST> -.*"GET .*xmlrpc\.php.*".* ^<HOST> -.*"GET .*html2text\.php.*".*

Nota : [mono]^ -.*"GET [\w{1,3} \w{1,3} \d{1,2} \d{1,2}:\d{1,2}:\d{1,2} \d{1,4}] [error] [client Ton_IP] File does not exist:[/mono]

Bonjour et merci BelZéButh,

Je vais rajouter ce que tu me propose dans mon “apache2-w00tw00t.conf”.
Pour cette ligne :
^ -.*"GET [\w{1,3} \w{1,3} \d{1,2} \d{1,2}:\d{1,2}:\d{1,2} \d{1,4}] [error] [client Ton_IP] File does not exist:

Je dois renseigner l’IP de mon dédié ?

J’ai des erreurs avec fail2ban avec une autre regex qui match mais ban pas j’ai l’impression… :

2013-12-29 03:42:50,455 fail2ban.filter : ERROR No 'host' found in '[Sun 2013] [error] [client 89.248.171.55] File does not exist: /var/www/pma ' using '<_sre.SRE_Pattern object at 0x2a3df60>'

Aurais-tu une idée ?

Putainggg, si ta regex elle match mais qu’elle ne ban pas, faut l’amener chez le médecin :unamused: :005 :005 :005

Y a beaucoup plus simple :

failregex = ^%(_apache_error_client)s .*w00tw00t.*$

Finalement ma regex pour les scans, (pma,mysql etc…) ne match pas.
Je comprend plus rien avec ce logiciel un coup ça fonctionne puis après plus rien !

Tout à fait.

C’est à dire … de quel prison s’agit-il ?


[13:32:41]:~$ ls -a /etc/fail2ban/filter.d/
.                         apache-bloquescan.conf  apache-noscript.conf             ban.conf           dovecot-pop3imap.conf  multiban.conf       proftpd.conf    sshd-ddos.conf
..                        apache-common.conf      apache-overflows.conf            common.conf        dropbear.conf          mysqld.conf         pure-ftpd.conf  vsftpd.conf
apache-404.conf           apache-dosevasive.conf  apache-overflows.conf.dpkg-dist  courierlogin.conf  exim.conf              named-refused.conf  qmail.conf      webmin-auth.conf
apache-anti-scripts.conf  apache-nodnsuse.conf    apache-phpmyadmin.conf           couriersmtp.conf   gssftpd.conf           pam-generic.conf    sasl.conf       wuftpd.conf
apache-auth.conf          apache-no-exist.conf    apache-slowloris.conf            cyrus-imap.conf    http-get-dos.conf      php-url-fopen.conf  sieve.conf      xinetd-fail.conf
apache-badbots.conf       apache-nohome.conf      apache-w00tw00t.conf             dovecot.conf       lighttpd-fastcgi.conf  postfix.conf        sshd.conf
[13:32:49]:~$ 

Ne faut-il pas reload le service pour la prise en compte, après avoir tester ces dernières …

J’ai réussi à trouver une règle qui fonctionne très bien :

[mono]# Fail2Ban configuration file

Bans bots scanning for non-existing phpMyAdmin installations on your webhost.

[Definition]

Option: failregex

Notes.: Regexp to match often probed and not available phpmyadmin paths.

Values: TEXT

failregex = [[]client []] File does not exist: .*(PMA|phpmyadmin|myadmin|mysql|mysqladmin|sqladmin|mypma|admin|xampp|mysqldb|mydb|
db|pmadb|phpmyadmin1|myadmin2)

Option: ignoreregex

Notes.: regex to ignore. If this regex matches, the line is ignored.

Values: TEXT

ignoreregex =[/mono]

C’est bien les recherches sur internet mais par moment on trouve des choses qui fonctionne pas.
Du coup obligé de prendre des heures pour trouver des règles qui match !

Merci pour votre aide

Penses-tu qu’avec ta regex, tu ne vas pas bloquer tes propres sites web avec des pages 404 ?

[quote=“Rathorian”]…

Du coup obligé de prendre des heures pour trouver des règles qui match [/quote]
Dis, Camarade, tu ne peux pas faire un effort pour employer au maximum des mots français ?
Je ne sais pas si tu as remarqué mais ici, on est sur "debian-[size=200]fr[/size].org"
Pour les “regex”, passe encore mais pour “match”, il y a suffisamment de verbes correspondants.
Merci d’en tenir compte à l’avenir.

Je suis pas un expert dans le domaine mais cette règle permet à mon sens de bloquer les utilisateurs/scripts qui essaye de trouver un dossier nommé seulement par (PMA|phpmyadmin|myadmin|mysql|mysqladmin|sqladmin|mypma|admin|xampp|mysqldb|mydb|
db|pmadb|phpmyadmin1|myadmin2) et qui n’existe pas.

Donc je ne vois aucun souci qui pourrait bloquer mes sites web…

[quote=“ricardo”][quote=“Rathorian”]…

Du coup obligé de prendre des heures pour trouver des règles qui match [/quote]
Dis, Camarade, tu ne peux pas faire un effort pour employer au maximum des mots français ?
Je ne sais pas si tu as remarqué mais ici, on est sur "debian-[size=200]fr[/size].org"
Pour les “regex”, passe encore mais pour “match”, il y a suffisamment de verbes correspondants.
Merci d’en tenir compte à l’avenir.[/quote]

Désolé Ricardo, je ferais attention la prochaine fois même si ça me parait légèrement absurde pour 1 mot.
Sachant quand même que ce genre de mots est utilisé de partout dans l’informatique même si on est en France.
Enfin… c’est toi le patron sur le forum.