Malgré DKIM + SPF + dmarc et conf postfix adéquate, spoofing possible !

Hello,

Malgré que mes domaines soient bien configurés, que postfix soit lui aussi correct, avec du dkim, du SPF et du dmarc, je peux malgré tout envoyer des mails anonymes en tant que @mondomaine.fr à mes adresses @mondomaine.fr sans m’authenfier… c’est effrayant et je ne vois pas ce qui coince.

Voici ma conf postfix :

#
## restrictions au moment de la connexion
#
smtpd_client_restrictions =
     permit_mynetworks,
     permit_sasl_authenticated,
     reject_unknown_client_hostname,
     check_client_access hash:/etc/postfix/client_access,
     permit_inet_interfaces
#
## restrictions après réception de la commande « HELO ou EHLO »
#
smtpd_helo_restrictions =
     permit_mynetworks,
     permit_sasl_authenticated,
     reject_invalid_helo_hostname,
     reject_non_fqdn_helo_hostname,
     reject_unknown_helo_hostname
#
## restrictions après réception de la commande « MAIL FROM »
#
smtpd_sender_restrictions =
     permit_mynetworks,
     permit_sasl_authenticated,
     reject_sender_login_mismatch,
     reject_unauth_pipelining,
     reject_unknown_sender_domain,
     reject_unlisted_sender,
     reject_non_fqdn_sender,
     check_sender_access hash:/etc/postfix/sender_access,

#
## restrictions après réception de la commande « RCPT TO »
#
smtpd_recipient_restrictions =
     permit_mynetworks,
     permit_sasl_authenticated,
     reject_unauth_destination,
     reject_non_fqdn_sender,
     reject_invalid_hostname,
     reject_non_fqdn_hostname,
     reject_unlisted_recipient,
     reject_non_fqdn_recipient,
     reject_unknown_recipient_domain,
     reject_unauth_pipelining,
     #reject_rbl_client sbl-xbl.spamhaus.org,
     check_recipient_access hash:/etc/postfix/recipient_access,
     #reject_rbl_client all.s5h.net,
     reject_rbl_client cbl.abuseat.org,
     reject_rbl_client dnsbl.inps.de,
     permit

#
## restrictions après réception de la commande « DATA »
#
smtpd_data_restrictions =
     reject_unauth_pipelining
#
## restrictions mécanisme ETRN
#
smtpd_etrn_restrictions = reject
#

et le retour de spoofcheck :

`--# ./spoofcheck.py mondomaine.net
[*] Found SPF record:
[*] v=spf1 a mx ip4:x.x.x.x -all
[*] SPF record contains an All item: -all
[*] Found DMARC record:
[*] v=DMARC1; p=reject; rua=mailto:postmaster@mondomaine.net; ruf=mailto:mondomaine.net; adkim=s; aspf=s; pct=100; rf=afrf; sp=reject
[-] DMARC policy set to reject
[*] Aggregate reports will be sent: mailto:postmaster@mondomaine.net
[*] Forensics reports will be sent: mailto:webadmin@mondomaine.net
[-] Spoofing not possible for mondomaine.net

Pourtant, via https://www.envoyer-mail.fr/ je peux tranquillement me faire passer pour qui je veux sur @mondomaine.net et l’envoyer à qui je veux sur @mondomaine.net.

A noter qu’évidemment, l’ami gmail.fr, lui, ne se fait pas avoir : si j’envoie un mail de admin@gmail.com en mode anonyme vers mon adresse gmail, le mail n’arrivera jamais… en revanche, si je l’envoie chez @mondomaine.net ou même chez @free.fr (ou sfr.fr), là il passera. Quelle différence y a t il entre la conf gmail et la mienne ?

Qu’est-ce qui ne va pas dans ma conf ?

J’ai fait un test intéressant :

  • Envoie de mail en tant que admin@mondomaine.net en mode anonyme vers mon adresse gmail.fr : gmail a catalogué ça en SPAM et en regardant la source du mail, je vois que DMARC : FAIL

  • Envoie de mail en tant que admin@mondomaine.net en mode anonyme vers mon adresse @mondomaine.net : mon serveur l’accepte bien et aucune mention de DMARC dans la source du mail !

  • Envoie de mail en tant que admin@mondomaine.net en mode authentifié (donc depuis mon serveur, de manière légitime) vers mon adresse gmail.fr : gmail l’a bien accepté et en regardant la source du mail, je vois que DMARC : PASS

Donc, c’est qu’il y a une bricole qui coince au niveau de ma conf DMARC sur mon serveur d’envoi/réception, si lui n’est pas capable de reconnaître du spoofing, alors que les serveurs de gmail sont capable de le faire, non ?

Ma conf dmarc est la suivante au niveau DNS :

;Delivrabilite mail
mail._domainkey IN      TXT     ( "v=DKIM1; h=sha256; k=rsa; "
          "p=******************" )  ; ----- DKIM key mail for mondomaine.net

@               IN      TXT     "v=spf1 a mx ip4:x.x.x.x ~all"
_dmarc          IN      TXT     "v=DMARC1; p=quarantine; rua=mailto:webadmin@mondomaine.net; ruf=mailto:webadmin@mondomaine.net; adkim=s; aspf=s; pct=100; rf=afrf; sp=reject"

L’enregistrement DMARC est bien présent et est correctement retourné lorsque je teste via dmarc inspector par exemple (qui me retourne bien Your DMARC record is valid.)

J’ai fait un autre test : j’ai pris la config dmarc de gmail.com, mais même en l’appliquant à ma conf, rien à faire, les mails passent quand même… Pourquoi ?

SVP, help :frowning:

Bonjour,

Je ne fais que lire, parce que je suis loin d’être un expert.

Qu’en est-il du status du SPF dans les entête sur gmail ? Normalement, il devrait avoir échoué.

Tu vérifies le SPF et le DMARC en entrée ? Parce que si non, c’est normal que ça passe.

Voilà, je laisse le reste aux experts :slight_smile:

Bonjour,

Pour te répondre :slight_smile:

  • lorsque gmail trape le mail en SPAM, bizarrement, le SPF est bon, voici l’enregistrement :

|SPF :|PASS avec IP 212.227.126.133 En savoir plus|
|DMARC :|‘FAIL’ En savoir plus|

  • Concernant SPF et DMARC en entrée, peux-tu développer SVP ? Peut-être que le souci est là. A quel endroit je devrais vérifier ça ? Pour info, dans les milter (dans postfix donc), j’ai ceci :
milter_protocol = 6
milter_default_action = accept
smtpd_milters = unix:/opendkim/opendkim.sock, unix:/opendkim/opendkim.sock, unix:/clamav/clamav-milter.ctl
non_smtpd_milters = unix:/opendkim/opendkim.sock, unix:/opendkim/opendkim.sock, unix:/clamav/clamav-milter.ctl 

J’aurais tendance à dire que ton enregistrement SPF est incorrect, mais j’en suis pas sûr.
Tu confirme que l’IP 212.227.126.133 n’est pas ton serveur ip4:x.x.x.x ?
Chez OVH, j’ai ça:

IN TXT    "spf2.0/pra mx a:hote.tld ip4:xxx.xxx.xxx.xxx -all"
IN TXT    "v=spf1 mx a:hote.tld ip4:xxx.xxx.xxx.xxx -all"

Je n’utilise pas postfix et je suis débutant sur opensmtpd, mais j’imagine que l’envoyer ne veut pas dire le vérifier en entrée. Je parle de ce cas là :

Je crois aussi que c’est le SPF qui ne semble pas bon. D’ailleurs pourquoi il marque PASS alors que l’ip ne match pas avec le domaine ?

Cette IP n’est pas celle de mon serveur, effectivement.

J’ai refait le test en utilisant la conf OVH que tu me proposes et j’ai ceci :

spf:mondomaine.net

spf v=spf1 a mx ip4:x.x.x.x ~all

Prefix	Type	Value	PrefixDesc	Description
v	version	spf1		The SPF record version
+	a		Pass	Match if IP has a DNS 'A' record in given domain
+	mx		Pass	Match if IP is one of the MX hosts for given domain name
+	ip4	x.x.x.x	Pass	Match if IP is in the given range
**~	all		SoftFail	Always matches. It goes at the end of your record.**
Test	Result
	DNS Record Published	DNS Record found
	SPF Record Published	SPF Record found
	SPF Record Deprecated	No deprecated records found
	SPF Multiple Records	Less than two records found
	SPF Syntax Check	The record is valid
	SPF Included Lookups	Number of included lookups is OK
	SPF Type PTR Check	No type PTR found
	SPF Void Lookups	Number of void lookups is OK

Bon j’ai trouvé une partie du problème… j’ai protégé le domaine au sens DNS, mais à postfix, je ne lui ai rien dit…

J’ai oublié de mettre un bouncer entre Postfix et SPF… voir l’article suivant.

A présent que je refais un test en mode anonyme avec une réception sur mon serveur @mondomaine.net, je vois bien une référence à SPF :

Jun 29 11:41:16 test policyd-spf[4912]: prepend Received-SPF: Temperror (mailfrom) identity=mailfrom; client-ip=212.227.126.130; helo=mout.kundenserver.de; envelope-from=cgi-mailer-bounces-503968316@kundenserver.de; receiver=<UNKNOWN>

Mais ça n’est pas encore bon, car je reçois toujours le mail et il n’est pas encore trapé comme il faut.

En fait, non, il faut que je reçoive le mail, mais c’est le tag qui me perturbe, j’aimerais que mon client mail le voit bien comme du SPAM, mais je ne sais pas si c’est le tag envoyé (prepend Received-SPF: Temperror) qui n’est pas bon, ou si il s’agit juste d’une configuration du client mail.

Par ailleurs c’est quand même délirant : quand j’envoie un mail en mode anonyme, en tant que @mondomaine.net vers mon adresse gmail, le mail ne passe pas, mais il est bloqué par DMARC et non SPF !

Received-SPF: pass (google.com: domain of cgi-mailer-bounces-503968316@kundenserver.de designates 212.227.126.131 as permitted sender) client-ip=212.227.126.131;
Authentication-Results: mx.google.com;
       spf=pass (google.com: domain of cgi-mailer-bounces-503968316@kundenserver.de designates 212.227.126.131 as permitted sender) smtp.mailfrom=cgi-mailer-bounces-503968316@kundenserver.de;
       dmarc=fail (p=QUARANTINE sp=REJECT dis=QUARANTINE) header.from=mondomaine.net

Pourquoi 212.227.126.131 as permitted sender ? Je ne veux pas moi qu’il puisse envoyer en mon nom ! cette ip n’est pas du tout l’ip de mon serveur de mail.

Voici un extrait de la log, avec toute la partie SPF (en mode log 4), à savoir que c’est le même phénomène pour tous les serveurs sur lesquels je m’appuie pour faire mes envois anonymes :

Jun 29 17:34:34 test policyd-spf[3802]: Read line: "request=smtpd_access_policy"
Jun 29 17:34:34 test policyd-spf[3802]: Read line: "protocol_state=RCPT"
Jun 29 17:34:34 test policyd-spf[3802]: Read line: "protocol_name=ESMTP"
Jun 29 17:34:34 test policyd-spf[3802]: Read line: "client_address=212.227.126.131"
Jun 29 17:34:34 test policyd-spf[3802]: Read line: "client_name=mout.kundenserver.de"
Jun 29 17:34:34 test policyd-spf[3802]: Read line: "client_port=54660"
Jun 29 17:34:34 test policyd-spf[3802]: Read line: "reverse_client_name=mout.kundenserver.de"
Jun 29 17:34:34 test policyd-spf[3802]: Read line: "helo_name=mout.kundenserver.de"
Jun 29 17:34:34 test policyd-spf[3802]: Read line: "sender=cgi-mailer-bounces-503968316@kundenserver.de"
Jun 29 17:34:34 test policyd-spf[3802]: Read line: "recipient=webadmin@mondomaine.net"
Jun 29 17:34:34 test policyd-spf[3802]: Read line: "recipient_count=0"
Jun 29 17:34:34 test policyd-spf[3802]: Read line: "queue_id="
Jun 29 17:34:34 test policyd-spf[3802]: Read line: "instance=ed4.5b365189.e3501.0"
Jun 29 17:34:34 test policyd-spf[3802]: Read line: "size=2016"
Jun 29 17:34:34 test policyd-spf[3802]: Read line: "etrn_domain="
Jun 29 17:34:34 test policyd-spf[3802]: Read line: "stress="
Jun 29 17:34:34 test policyd-spf[3802]: Read line: "sasl_method="
Jun 29 17:34:34 test policyd-spf[3802]: Read line: "sasl_username="
Jun 29 17:34:34 test policyd-spf[3802]: Read line: "sasl_sender="
Jun 29 17:34:34 test policyd-spf[3802]: Read line: "ccert_subject="
Jun 29 17:34:34 test policyd-spf[3802]: Read line: "ccert_issuer="
Jun 29 17:34:34 test policyd-spf[3802]: Read line: "ccert_fingerprint="
Jun 29 17:34:34 test policyd-spf[3802]: Read line: "ccert_pubkey_fingerprint="
Jun 29 17:34:34 test policyd-spf[3802]: Read line: "encryption_protocol=TLSv1.2"
Jun 29 17:34:34 test policyd-spf[3802]: Read line: "encryption_cipher=ECDHE-RSA-AES256-GCM-SHA384"
Jun 29 17:34:34 test policyd-spf[3802]: Read line: "encryption_keysize=256"
Jun 29 17:34:34 test policyd-spf[3802]: Read line: "policy_context="
Jun 29 17:34:34 test policyd-spf[3802]: Read line: ""
Jun 29 17:34:34 test policyd-spf[3802]: Found the end of entry
Jun 29 17:34:34 test policyd-spf[3802]: Config: {'PermError_reject': 'False', 'Header_Type': 'SPF', 'Mail_From_reject': 'False', 'TempError_Defer': 'False', 'Void_Limit': 2, 'debugLevel': 4, 'skip_addresses': '127.0.0.0/8,::ffff:127.0.0.0/104,::1', 'TestOnly': 1, 'Reason_Message': 'Message {rejectdefer} due to: {spf}. Please see {url}', 'HELO_reject': 'False', 'Authserv_Id': 'test', 'Mock': False, 'Hide_Receiver': 'Yes', 'SPF_Enhanced_Status_Codes': 'Yes', 'Whitelist_Lookup_Time': 10, 'Lookup_Time': 20}
Jun 29 17:34:34 test policyd-spf[3802]: Cached data for this instance: []
Jun 29 17:34:34 test policyd-spf[3802]: skip_addresses enabled.
Jun 29 17:34:34 test policyd-spf[3802]: spfcheck: pyspf result: "['Temperror', 'SPF Temporary Error: DNS No working name servers discovered', 'helo']"
Jun 29 17:34:34 test policyd-spf[3802]: Temperror; identity=helo; client-ip=212.227.126.131; helo=mout.kundenserver.de; envelope-from=cgi-mailer-bounces-503968316@kundenserver.de; receiver=<UNKNOWN>
Jun 29 17:34:34 test policyd-spf[3802]: spfcheck: pyspf result: "['Temperror', 'SPF Temporary Error: DNS No working name servers discovered', 'mailfrom']"
Jun 29 17:34:34 test policyd-spf[3802]: Temperror; identity=mailfrom; client-ip=212.227.126.131; helo=mout.kundenserver.de; envelope-from=cgi-mailer-bounces-503968316@kundenserver.de; receiver=<UNKNOWN>
Jun 29 17:34:34 test policyd-spf[3802]: not peruser
Jun 29 17:34:34 test policyd-spf[3802]: Action: prepend: Text: Received-SPF: Temperror (mailfrom) identity=mailfrom; client-ip=212.227.126.131; helo=mout.kundenserver.de; envelope-from=cgi-mailer-bounces-503968316@kundenserver.de; receiver=<UNKNOWN>  Reject action: 550 5.7.23
Jun 29 17:34:34 test policyd-spf[3802]: prepend Received-SPF: Temperror (mailfrom) identity=mailfrom; client-ip=212.227.126.131; helo=mout.kundenserver.de; envelope-from=cgi-mailer-bounces-503968316@kundenserver.de; receiver=<UNKNOWN>

Pour ce message SPF Temporary Error: DNS No working name servers discovered ? Est-ce qu’il manque encore quelque-chose côté DNS ? Je n’arrive pas à trouver plus d’infos par rapport à cette erreur.

Vraisemblablement, le problème viendrait du fait que mon resolv.conf contienne moins de 2 entrées nameserver.

J’ai donc testé le trick trouvé ici et visiblement ça passe, je n’ai plus cette erreur. J’ai donc rajouté 2 entrées ‘nameserver 127.0.0.1’. Pas propre, mais faute de mieux…

Bon, un dernier truc que je ne comprends pas.

Soit la séquence SPF suivante, testée et à priori validée, puisque l’ip testée n’est PAS autorisée à envoyer un mail depuis mondomaine.net, j’en conclue que le mécanisme SPF fonctionne :

+0 msSPF check starting.
IP:x.x.x.1
Sender: toto@mondomaine.net
Domain: mondomaine.net
EHLO/HELO domain:
+0 msRetrieving DNS TXT record for "mondomaine.net".
+24 msTXT record found.
Line #1: "v=spf1 mx a:mail.mondomaine.net ip4:x.x.x.11 -all"
+0 msStarting SPF policy evaluation.
Policy: "v=spf1 mx a:mail.mondomaine.net ip4:x.x.x.11 -all"
+0 msThe policy passed syntax validation.
+0 msEvaluating SPF mechanisms.
+1 msEvaluating mechanism "mx".
Qualifier: "pass"
DNS limits status: DNS terms 0 of 10 allowed. Void lookups 0 of 2 allowed. See RFC7208 Section 4.6.4.
+0 msNo domain argument is present, using the current domain: "mondomaine.net".
+0 msRetrieving DNS MX record for "mondomaine.net".
+24 msMX record found.
Answer #1: "10,mail.mondomaine.net"
+0 msRetrieving DNS A record for "mail.mondomaine.net".
+48 msA record found.
Answer #1: "x.x.x.11"
+0 msThe mechanism did not match.
+0 msEvaluating mechanism "a".
Qualifier: "pass"
Domain argument: "mail.mondomaine.net"
DNS limits status: DNS terms 1 of 10 allowed. Void lookups 0 of 2 allowed. See RFC7208 Section 4.6.4.
+0 msDomain argument after macro expansion: "mail.mondomaine.net".
+0 msRetrieving DNS A record for "mail.mondomaine.net".
+1 msDNS A record found.
Answer #1: "x.x.x.11"
+0 msThe mechanism did not match.
+1 msEvaluating mechanism "ip4".
Qualifier: "pass"
Network argument: "x.x.x.11"
+0 msThe mechanism did not match.
+0 msEvaluating mechanism "all".
Qualifier: "fail"
+0 msThe mechanism matched with the "fail" qualifier.
+0 msFinished evaluating SPF mechanisms.
+0 msFinished SPF policy evaluation.
DNS limits status: DNS terms 2 of 10 allowed. Void lookups 0 of 2 allowed. See RFC7208 Section 4.6.4.
+0 msPolicy evaluation finished with SPF "fail".
TEST SUMMARY
The evaluation completed in 99 ms, with 0 error and 0 warning.
Result: SPF fail
The policy does NOT designate the argument IP as permitted sender.

On peut crier victoire dans l’absolu, mais non ! Car depuis https://www.envoyer-mail.fr/ tous les mails que j’envoie en tant que toto@mondomaine.net passent en PASS dans SPF, alors qu’ils ne le devraient pas en toute logique ! envoyer-mail.fr n’a aucun lien avec mon serveur de mail, donc normalement SPF devrait lui retirer toute légitimité à envoyer des mails. WTF ?

Bon, ben finalement j’avais la non solution sous les yeux… L’outil de mail dont je me servais pour faire du spoofing de mail passait simplement par un mail de rebond qui était au même nom de domaine que le serveur de mail utilisé pour le rebond… donc au final le SPF matchait.

La partie SPF est chez moi pleinement fonctionnelle, il faut juste qu’arrive à tagger les mails en réceptions dans l’adresse destinataire est forgée.