swaks

Couteau suisse pour SMTP. Envoie des emails personnalisables via SMTP avec un contrôle total des headers, pièces jointes, TLS, authentification et extensions SMTP : idéal pour les tests de sécurité email. Swiss Army Knife for SMTP. Sends customizable email messages via SMTP with full control over headers, attachments, TLS, authentication, and SMTP extensions — ideal for email security testing.

↗ https://jetmore.org/john/code/swaks/

Overview

swaks (Swiss Army Knife SMTP) is a feature-rich SMTP transaction tester. It handles every aspect of SMTP communication: authentication, TLS, STARTTLS, MIME, custom headers, attachments, SMTP extensions, and relay testing — all from the command line.

Basic Usage

Send a basic test email

swaks --to user@target.com --from attacker@test.com --server mail.target.com

Send with STARTTLS

swaks --to user@target.com --server mail.target.com --tls

Send with authentication

swaks --to user@target.com --server mail.target.com \
  --auth LOGIN --auth-user username --auth-password password

Email Testing

Test SMTP relay (check if open relay)

swaks --to external@gmail.com --from internal@target.com --server mail.target.com

Test with custom From/To headers

swaks --to victim@target.com \
  --from "CEO <ceo@target.com>" \
  --server mail.target.com \
  --header "Subject: Urgent Action Required"

Verbose SMTP transaction

swaks -v --to user@target.com --server mail.target.com

Phishing / Social Engineering Testing

Send with HTML body

swaks --to target@company.com \
  --from "IT Support <helpdesk@company.com>" \
  --server mail.company.com \
  --header "Subject: Password Reset Required" \
  --body "<html><body>Click here to reset: http://phishing.test</body></html>" \
  --add-header "Content-Type: text/html"

Attach a file

swaks --to user@target.com \
  --from attacker@test.com \
  --server mail.target.com \
  --attach /path/to/payload.pdf

Authentication Testing

Test AUTH PLAIN

swaks --server mail.target.com --auth PLAIN \
  --auth-user user --auth-password pass --to test@target.com

Test AUTH LOGIN

swaks --server mail.target.com --auth LOGIN \
  --auth-user user --auth-password pass --to test@target.com

Test NTLM auth (for Exchange)

swaks --server mail.target.com --auth NTLM \
  --auth-user DOMAIN\\user --auth-password pass --to test@target.com

TLS Testing

Force TLS (port 465 implicit TLS)

swaks --to user@target.com --server mail.target.com:465 --tls-on-connect

STARTTLS on port 587

swaks --to user@target.com --server mail.target.com:587 --tls

Check TLS certificate

swaks --to user@target.com --server mail.target.com --tls --tls-verify

Open Relay Check

Check if server relays for external senders

swaks --to external-address@gmail.com \
  --from random@random.com \
  --server mail.target.com
# Response codes:
# 250 OK = open relay (vulnerability!)
# 550/554 = relay denied (expected behavior)

Tips

  • SMTP open relay testing is a standard pentest check — most servers are now locked down
  • Use for phishing simulation campaigns (with authorization)
  • Test NTLM auth on Exchange/O365 with --auth NTLM to verify credential validity
  • The -v flag shows the full SMTP transaction — useful for debugging and documentation
  • Useful for verifying email security controls (SPF, DKIM, DMARC enforcement)
Help / Man page
swaks [options]

--to ADDR       Recipient address
--from ADDR     From address
--server HOST   SMTP server [:port]
--tls           Use STARTTLS
--tls-on-connect Use TLS immediately (port 465)
--auth TYPE     Auth method (PLAIN, LOGIN, NTLM, CRAM-MD5)
--auth-user U   Authentication username
--auth-password P Authentication password
--header H      Additional header
--body TEXT     Email body
--attach FILE   Attach file
-v              Verbose (show SMTP transaction)
-q              Quiet

Vue d’ensemble

swaks (Swiss Army Knife SMTP) est un testeur de transaction SMTP très complet. Il gère tous les aspects de la communication SMTP : authentification, TLS, STARTTLS, MIME, headers personnalisés, pièces jointes, extensions SMTP, et tests de relais, le tout en ligne de commande.

Utilisation de base

# Envoyer un email de test basique
swaks --to user@target.com --from attacker@test.com --server mail.target.com

# Envoyer avec STARTTLS
swaks --to user@target.com --server mail.target.com --tls

# Envoyer avec authentification
swaks --to user@target.com --server mail.target.com \
  --auth LOGIN --auth-user username --auth-password password

Tests email

# Tester le relais SMTP (vérifier s'il s'agit d'un relais ouvert)
swaks --to external@gmail.com --from internal@target.com --server mail.target.com

# Tester avec des headers From/To personnalisés
swaks --to victim@target.com \
  --from "CEO <ceo@target.com>" \
  --server mail.target.com \
  --header "Subject: Urgent Action Required"

# Transaction SMTP verbeuse
swaks -v --to user@target.com --server mail.target.com

Tests de phishing / ingénierie sociale

# Envoyer avec un corps HTML
swaks --to target@company.com \
  --from "IT Support <helpdesk@company.com>" \
  --server mail.company.com \
  --header "Subject: Password Reset Required" \
  --body "<html><body>Click here to reset: http://phishing.test</body></html>" \
  --add-header "Content-Type: text/html"

# Joindre un fichier
swaks --to user@target.com \
  --from attacker@test.com \
  --server mail.target.com \
  --attach /path/to/payload.pdf

Tests d’authentification

# Tester AUTH PLAIN
swaks --server mail.target.com --auth PLAIN \
  --auth-user user --auth-password pass --to test@target.com

# Tester AUTH LOGIN
swaks --server mail.target.com --auth LOGIN \
  --auth-user user --auth-password pass --to test@target.com

# Tester l'auth NTLM (pour Exchange)
swaks --server mail.target.com --auth NTLM \
  --auth-user DOMAIN\\user --auth-password pass --to test@target.com

Tests TLS

# Forcer le TLS (port 465 en TLS implicite)
swaks --to user@target.com --server mail.target.com:465 --tls-on-connect

# STARTTLS sur le port 587
swaks --to user@target.com --server mail.target.com:587 --tls

# Vérifier le certificat TLS
swaks --to user@target.com --server mail.target.com --tls --tls-verify

Vérification de relais ouvert

# Vérifier si le serveur relaie pour des expéditeurs externes
swaks --to external-address@gmail.com \
  --from random@random.com \
  --server mail.target.com
# Codes de réponse :
# 250 OK = relais ouvert (vulnérabilité !)
# 550/554 = relais refusé (comportement attendu)

Conseils

  • Le test de relais SMTP ouvert est une vérification standard en pentest : la plupart des serveurs sont désormais verrouillés
  • À utiliser pour des campagnes de simulation de phishing (avec autorisation)
  • Tester l’auth NTLM sur Exchange/O365 avec --auth NTLM pour vérifier la validité des identifiants
  • Le flag -v affiche la transaction SMTP complète : utile pour le débogage et la documentation
  • Utile pour vérifier les contrôles de sécurité email (application de SPF, DKIM, DMARC)
Aide / Page de manuel
swaks [options]

--to ADDR       Recipient address
--from ADDR     From address
--server HOST   SMTP server [:port]
--tls           Use STARTTLS
--tls-on-connect Use TLS immediately (port 465)
--auth TYPE     Auth method (PLAIN, LOGIN, NTLM, CRAM-MD5)
--auth-user U   Authentication username
--auth-password P Authentication password
--header H      Additional header
--body TEXT     Email body
--attach FILE   Attach file
-v              Verbose (show SMTP transaction)
-q              Quiet