-
Notifications
You must be signed in to change notification settings - Fork 0
TP7 : Sécurisation du service mail
Ce TP vise à mettre en place et sécuriser un service mail complet utilisant Docker Mailserver (DMS) avec authentification de domaine, chiffrement TLS et filtrage anti-spam.
- VPS Principal : Hébergement du service mail (mail.l2-2.ephec-ti.be)
- IP du serveur : 54.36.181.95
- Domaine utilisé : ephec-ti.be
- Container : Docker Mailserver (DMS) avec Postfix/Dovecot
Le service mail est isolé dans un container Docker pour faciliter la maintenance et la sécurité.
# Records DNS ajoutés
ephec-ti.be. IN MX 10 mail.l2-2.ephec-ti.be.
mail.l2-2.ephec-ti.be. IN A 54.36.181.95DMS_GITHUB_URL="https://raw.githubusercontent.com/docker-mailserver/docker-mailserver/master"
wget "${DMS_GITHUB_URL}/compose.yaml"
wget "${DMS_GITHUB_URL}/mailserver.env"-
compose.yaml : Modification du hostname vers
mail.l2-2.ephec-ti.be -
mailserver.env : Configuration
SSL_TYPE=letsencrypt
sudo certbot certonly --standalone -d mail.l2-2.ephec-ti.bedocker compose up -d
# Création des utilisateurs (dans les 2 minutes suivant le démarrage)
docker exec -ti mailserver setup email list
* user1@l2-2.ephec-ti.be ( 0 / ~ ) [0%]
[ aliases -> postmaster@l2-2.ephec-ti.be ]
* user2@l2-2.ephec-ti.be ( 0 / ~ ) [0%]theocle@anzeyimavps:/home/anzeyima/tp7$ swaks --to user2@l2-2.ephec-ti.be \
--from user1@l2-2.ephec-ti.be \
--server mail.l2-2.ephec-ti.be:587 \
--tls \
--auth \
--auth-user user1@l2-2.ephec-ti.be \
--auth-password user1
=== Trying mail.l2-2.ephec-ti.be:587...
=== Connected to mail.l2-2.ephec-ti.be.
<- 220 mail.l2-2.ephec-ti.be ESMTP
-> EHLO anzeyimavps
<- 250-mail.l2-2.ephec-ti.be
<- 250-PIPELINING
<- 250-SIZE 10240000
<- 250-ETRN
<- 250-STARTTLS
<- 250-ENHANCEDSTATUSCODES
<- 250-8BITMIME
<- 250-DSN
<- 250 CHUNKING
-> STARTTLS
<- 220 2.0.0 Ready to start TLS
=== TLS started with cipher TLSv1.3:TLS_AES_256_GCM_SHA384:256
=== TLS no local certificate set
=== TLS peer DN="/CN=mail.l2-2.ephec-ti.be"
~> EHLO anzeyimavps
<~ 250-mail.l2-2.ephec-ti.be
<~ 250-PIPELINING
<~ 250-SIZE 10240000
<~ 250-ETRN
<~ 250-AUTH PLAIN LOGIN
<~ 250-AUTH=PLAIN LOGIN
<~ 250-ENHANCEDSTATUSCODES
<~ 250-8BITMIME
<~ 250-DSN
<~ 250 CHUNKING
~> AUTH LOGIN
<~ 334 VXNlcm5hbWU6
~> dXNlcjFAbDItMi5lcGhlYy10aS5iZQ==
<~ 334 UGFzc3dvcmQ6
~> dXNlcjE=
<~ 235 2.7.0 Authentication successful
~> MAIL FROM:<user1@l2-2.ephec-ti.be>
<~ 250 2.1.0 Ok
~> RCPT TO:<user2@l2-2.ephec-ti.be>
<~ 250 2.1.5 Ok
~> DATA
<~ 354 End data with <CR><LF>.<CR><LF>
~> Date: Tue, 10 Jun 2025 07:10:43 +0000
~> To: user2@l2-2.ephec-ti.be
~> From: user1@l2-2.ephec-ti.be
~> Subject: test Tue, 10 Jun 2025 07:10:43 +0000
~> Message-Id: <20250610071043.594123@anzeyimavps>
~> X-Mailer: swaks v20201014.0 jetmore.org/john/code/swaks/
~>
~> This is a test mailing
~>
~>
~> .
<~ 250 2.0.0 Ok: queued as EF8618C6DF
~> QUIT
<~ 221 2.0.0 Bye
=== Connection closed with remote host.
theocle@anzeyimavps:/home/anzeyima/tp7$
##Test mail exterieur
theocle@anzeyimavps:/home/anzeyima/tp7$ swaks --to theo7.kill@gmail.com \
--from user1@l2-2.ephec-ti.be \
--server mail.l2-2.ephec-ti.be:587 \
--tls \
--auth \
--auth-user user1@l2-2.ephec-ti.be \
--auth-password user1
=== Trying mail.l2-2.ephec-ti.be:587...
=== Connected to mail.l2-2.ephec-ti.be.
<- 220 mail.l2-2.ephec-ti.be ESMTP
-> EHLO anzeyimavps
<- 250-mail.l2-2.ephec-ti.be
<- 250-PIPELINING
<- 250-SIZE 10240000
<- 250-ETRN
<- 250-STARTTLS
<- 250-ENHANCEDSTATUSCODES
<- 250-8BITMIME
<- 250-DSN
<- 250 CHUNKING
-> STARTTLS
<- 220 2.0.0 Ready to start TLS
=== TLS started with cipher TLSv1.3:TLS_AES_256_GCM_SHA384:256
=== TLS no local certificate set
=== TLS peer DN="/CN=mail.l2-2.ephec-ti.be"
~> EHLO anzeyimavps
<~ 250-mail.l2-2.ephec-ti.be
<~ 250-PIPELINING
<~ 250-SIZE 10240000
<~ 250-ETRN
<~ 250-AUTH PLAIN LOGIN
<~ 250-AUTH=PLAIN LOGIN
<~ 250-ENHANCEDSTATUSCODES
<~ 250-8BITMIME
<~ 250-DSN
<~ 250 CHUNKING
~> AUTH LOGIN
<~ 334 VXNlcm5hbWU6
~> dXNlcjFAbDItMi5lcGhlYy10aS5iZQ==
<~ 334 UGFzc3dvcmQ6
~> dXNlcjE=
<~ 235 2.7.0 Authentication successful
~> MAIL FROM:<user1@l2-2.ephec-ti.be>
<~ 250 2.1.0 Ok
~> RCPT TO:<theo7.kill@gmail.com>
<~ 250 2.1.5 Ok
~> DATA
<~ 354 End data with <CR><LF>.<CR><LF>
~> Date: Tue, 10 Jun 2025 07:30:59 +0000
~> To: theo7.kill@gmail.com
~> From: user1@l2-2.ephec-ti.be
~> Subject: test Tue, 10 Jun 2025 07:30:59 +0000
~> Message-Id: <20250610073059.597858@anzeyimavps>
~> X-Mailer: swaks v20201014.0 jetmore.org/john/code/swaks/
~>
~> This is a test mailing
~>
~>
~> .
<~ 250 2.0.0 Ok: queued as 14B638C72E
~> QUIT
<~ 221 2.0.0 Bye
=== Connection closed with remote host.
theocle@anzeyimavps:/home/anzeyima/tp7$
Résultats attendus avant sécurisation :
- SPF Record : Absent
- DKIM : Non configuré
- DMARC : Absent
- PTR Record : Non aligné
- MX Record : Configuré
- Ports ouverts : 25, 587, 465, 143, 993
Les utilisateurs sont gérés via un fichier plat dans Docker Mailserver :
- Stockage dans
/var/mail/ - Commande :
docker exec -ti mailserver setup email add - Pas d'intégration Unix directe ni de base de données
Le format utilisé est Maildir :
- Un répertoire par utilisateur
- Emails stockés individuellement
- Structure :
/var/mail/domaine.com/utilisateur/
docker exec -ti mailserver netstat -tlnpPorts identifiés :
- Port 25 : SMTP standard (non chiffré, STARTTLS disponible)
- Port 587 : SMTP soumission avec STARTTLS (TLS explicite)
- Port 465 : SMTPS (TLS implicite)
- Port 143 : IMAP standard (STARTTLS disponible)
- Port 993 : IMAPS (TLS implicite)
Configuration de capture :
# Capture sur l'interface réseau du client
# Filtres : tcp.port == 587 or tcp.port == 993Résultats attendus :
Pour l'envoi (SMTP) :
- Port utilisé : 587
- Type TLS : Explicite (STARTTLS)
- Séquence : Connexion claire → EHLO → STARTTLS → Négociation TLS → Authentication
Pour la réception (IMAP) :
- Port utilisé : 993
- Type TLS : Implicite
- Séquence : Connexion TLS directe → Authentication
Configuration PTR :
# - IP : 54.36.181.95
# - PTR souhaité : mail.l2-2.ephec-ti.be
# - Nom actuel : vps-6fe8e7f5.vps.ovh.netVérification :
dig -x 54.36.181.95
nslookup 54.36.181.95Résultat MXToolbox attendu :
- MX Record pointe vers mail.l2-2.ephec-ti.be
- A Record résout vers 54.36.181.95
- PTR Record inverse vers mail.l2-2.ephec-ti.be
Configuration DNS :
# Record TXT ajouté
ephec-ti.be. IN TXT "v=spf1 mx -all"
Configuration :
# Génération des clés
docker exec -it mailserver setup config dkim
# Vérification du fichier généré
cat config/dkim/mail.txtAjout du record DNS :
# Contenu du fichier mail.txt à ajouter en tant que record TXT
# Exemple :
mail._domainkey.ephec-ti.be. IN TXT "v=DKIM1; h=sha256; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA..."Redémarrage :
docker compose down
docker compose up -dValidation en-tête email :
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ephec-ti.be;
s=mail; h=Date:From:To:Subject; bh=xxx; b=yyy
Résultat DKIM Validator :

Configuration DNS :
# Record TXT ajouté
_dmarc.ephec-ti.be. IN TXT "v=DMARC1; p=quarantine; rua=mailto:postmaster@ephec-ti.be"
Configuration :
# Édition mailserver.env
nano mailserver.env
# Ajout de la ligne :
ENABLE_SPAMASSASSIN=1
# Redémarrage
docker compose down
docker compose up -dVérification :
docker logs mailserver | grep -i spamTest :
# Email normal envoyé
Subject: Test normal
Content: Bonjour, ceci est un test de mail normal.Résultat attendu :
X-Spam-Status: No, score=-0.1 required=5.0
X-Spam-Score: -0.1
Test GTUBE :
cat > test_spam.txt << 'EOF'
Subject: Test SPAM
XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X
FREE MONEY!!! CLICK HERE NOW!!!
This is a test email to trigger spam filters.
EOFRésultat attendu :
X-Spam-Status: Yes, score=1000.0 required=5.0
X-Spam-Flag: YES
X-Spam-Level: **************************************************
Action : Email marqué comme spam et déplacé vers le dossier Junk.