# Fail2ban regex SASL

**URL:** <https://www.debian-fr.org/t/fail2ban-regex-sasl/75542>\
**Category:** Support Debian\
**Tags:** fail2ban\
**Created:** [Janvier 4, 2018, 7:25 UTC](https://www.debian-fr.org/t/fail2ban-regex-sasl/75542 "2018-01-04T07:25:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![leatherface](https://www.debian-fr.org/user_avatar/www.debian-fr.org/leatherface/32/2994_2.png) [@leatherface](https://www.debian-fr.org/u/leatherface)\
**Post date:** [Janvier 4, 2018, 7:25 UTC](https://www.debian-fr.org/t/fail2ban-regex-sasl/75542/1 "2018-01-04T07:25:32Z")

</div>

Bonjour,

Depuis la mise à jour récente de mon dédié vers Stretch, mon filtre fail2ban destiné à postfix-sasl, ne semble plus fonctionner.  
Il n’y a jamais d’IPs inscrites dans la chaîne iptables.  
Pourtant fail2ban-regex trouve les bonnes lignes:

```
fail2ban-regex /var/log/mail.warn /etc/fail2ban/filter.d/postfix-sasl.conf

```

# Running tests

Use failregex filter file : postfix-sasl, basedir: /etc/fail2ban  
Use log file : /var/log/mail.warn  
Use encoding : UTF-8

# Results

Failregex: 4970 total  
|- #) [# of hits] regular expression  
| 1) [4970] ^(?:[])?\s\*(?:\<[^.]+.[^.]+\>\s+)?(?:\S+\s+)?(?:kernel: [_\d+.\d+]\s+)?(?:@vserver\_\S+\s+)?(?:(?:(?:[\d+])?:\s+[[(]?postfix(-\w+)?/(?:submission/|smtps/)?smtpds?[])]?:?|[[(]?postfix(-\w+)?/(?:submission/|smtps/)?smtpds?[])]?:?(?:[\d+])?:?)\s+)?(?:[ID \d+ \S+]\s+)?warning: [-.\_\w]+[]: SASL ((?i)LOGIN|PLAIN|(?:CRAM|DIGEST)-MD5) authentication failed(:[A-Za-z0-9+/:]_={0,2})?\s\*$  
`-

Ignoreregex: 0 total

Date template hits:  
|- [# of hits] date format  
| [8885] (?:DAY )?MON Day 24hour:Minute:Second(?:.Microseconds)?(?: Year)?  
`-

Lines: 8885 lines, 0 ignored, 4970 matched, 3915 missed  
[processed in 0.72 sec]

Voici la regex positionnée dans le filtre:

```
failregex = ^%(__prefix_line)swarning: [-._\w]+\[<HOST>\]: SASL ((?i)LOGIN|PLAIN|(?:CRAM|DIGEST)-MD5) authentication failed(:[A-Za-z0-9+/:]*={0,2})?\s*$

```

Auriez-vous des pistes pour que je pourrais explorer ?

Merci d’avance pour vos réponses.

---

<div class="post-metadata">

**Author:** ![mattotop](https://www.debian-fr.org/user_avatar/www.debian-fr.org/mattotop/32/3942_2.png) [@mattotop](https://www.debian-fr.org/u/mattotop)\
**Post date:** [Janvier 4, 2018, 8:11 UTC](https://www.debian-fr.org/t/fail2ban-regex-sasl/75542/2 "2018-01-04T08:11:49Z")

</div>

Chez moi, il y a une petite différence sur la regex:  
`failregex = ^%(__prefix_line)swarning: [-._\w]+\[<HOST>\]: SASL (?:LOGIN|PLAIN|(?:CRAM|DIGEST)-MD5) authentication failed(: [A-Za-z0-9+/]*={0,2})?\s*$`

SASL ((?i)LOGIN  
-\>  
SASL (?:LOGIN

Mais bon, le problème n’est pas dans la regex, puisque ton teste indique des lignes qui matchent.

Sinon, es tu sur que ça ne fonctionne plus ?  
Tu es sur que tu n’as pas juste regardé à un moment ou il n’y avait plus aucun blocage en cours ?  
Tu as regardé la date et l’heure de la ligne “matched” la plus récente dans ton mail.warn ?

---

<div class="post-metadata">

**Author:** ![leatherface](https://www.debian-fr.org/user_avatar/www.debian-fr.org/leatherface/32/2994_2.png) [@leatherface](https://www.debian-fr.org/u/leatherface)\
**Post date:** [Janvier 4, 2018, 9:13 UTC](https://www.debian-fr.org/t/fail2ban-regex-sasl/75542/3 "2018-01-04T09:13:45Z")

</div>

Hello,

Tout d’abord merci pour ta réponse.  
Dans le mail.warn je n’ai aucune ligne concernant fail2ban. Je suis sûr que ça ne fonctionne plus car le comptage des paquets dans la sortie iptables est à 0:

```
Chain f2b-sasl (0 references)
pkts bytes target prot opt in out source destination         
0 0 RETURN all -- any any anywhere anywhere           

```

C’est étrange que la regex soit différente chez toi. Mais je me dis qu’à partir du moment où le test me  
retourne des lignes de match, je pense que c’est bon. Peut-être que le problème se situe au moment où il essaye d’inscrire les adresses dans iptables …

Je viens de faire le test sur la jail ssh et ça fonctionne nickel.

---

<div class="post-metadata">

**Author:** ![mattotop](https://www.debian-fr.org/user_avatar/www.debian-fr.org/mattotop/32/3942_2.png) [@mattotop](https://www.debian-fr.org/u/mattotop)\
**Post date:** [Janvier 4, 2018, 11:45 UTC](https://www.debian-fr.org/t/fail2ban-regex-sasl/75542/4 "2018-01-04T11:45:51Z")

</div>

C’est bizarre ce nom de chaine f2b-sasl, chez moi, les chaines fail2ban ont fail2ban dans le nom:

````auto
:fail2ban-ssh - [0:0]
-A INPUT -p tcp -m multiport --dports 22 -j fail2ban-ssh
-A fail2ban-ssh -s 59.63.188.32/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-ssh -j RETURN```
Sinon, je n'ai pas d'autre idée.
````

---

<div class="post-metadata">

**Author:** ![leatherface](https://www.debian-fr.org/user_avatar/www.debian-fr.org/leatherface/32/2994_2.png) [@leatherface](https://www.debian-fr.org/u/leatherface)\
**Post date:** [Janvier 4, 2018, 2:52 UTC](https://www.debian-fr.org/t/fail2ban-regex-sasl/75542/5 "2018-01-04T14:52:37Z")

</div>

La chaîne SSH s’appelle de la même façon et ça fonctionne. Par contre dans les logs fail2ban j’ai des erreurs liées à multiport. Il détecte bien l’IP à bannir, mais il y a une erreur dans l’action:

```
iptables -w -I INPUT -p tcp -m multiport --dports smtp,ssmtp,submission,imap2,imap3,imaps,pop3,pop3s -j f2b-sasl -- stderr: b"iptables v1.6.0: invalid port/service `imap3' specified\nTry `iptables -h' or 'iptables --help' for more information.\n"

```

Il y a un souci lié à imap3. Il faut que je regarde du côté des actions et virer imap3 je pense.

---

<div class="post-metadata">

**Author:** ![leatherface](https://www.debian-fr.org/user_avatar/www.debian-fr.org/leatherface/32/2994_2.png) [@leatherface](https://www.debian-fr.org/u/leatherface)\
**Post date:** [Janvier 4, 2018, 3:11 UTC](https://www.debian-fr.org/t/fail2ban-regex-sasl/75542/6 "2018-01-04T15:11:50Z")

</div>

C’est bon j’ai réglé le souci !  
J’ai viré imap3 de la jail postfix-sasl dans jail.local et ça bannit à mort maintenant 😉

```
Chain f2b-sasl (1 references)
pkts bytes target prot opt in out source destination         
0 0 REJECT all -- any any no-reverse-dns-configured.com anywhere reject-with icmp-port-unreachable
0 0 REJECT all -- any any walkerj235.com anywhere reject-with icmp-port-unreachable
0 0 REJECT all -- any any 5.101.0.34 anywhere reject-with icmp-port-unreachable
0 0 REJECT all -- any any 37.49.227.159 anywhere reject-with icmp-port-unreachable
0 0 REJECT all -- any any 178.62.72.67 anywhere reject-with icmp-port-unreachable
14 658 RETURN all -- any any anywhere anywhere
```
