SMTP

SMTP Services

Simple Mail Transfer Protocol (SMTP) is the backbone of email communication across the internet. It handles the transfer of emails between mail servers and from clients to servers. Understanding SMTP's structure and common misconfigurations is essential for comprehensive security assessments.

Protocol Basics

SMTP typically operates on:

  • Port 25: Standard unencrypted SMTP

  • Port 465: SMTP with SSL/TLS encryption (SMTPS)

  • Port 587: SMTP with STARTTLS (submission port)

Protocol Flow

The email delivery process involves multiple components:

  1. MUA (Mail User Agent): Email client that composes messages

  2. MSA (Mail Submission Agent): Validates email before sending

  3. MTA (Mail Transfer Agent): Handles routing between mail servers

  4. MDA (Mail Delivery Agent): Delivers email to recipient's mailbox

SMTP Flow

SMTP Commands

SMTP uses a set of commands for communication between clients and servers:

Command

Description

AUTH PLAIN

Authentication service extension

HELO

Client identifies itself with hostname

MAIL FROM

Specifies the email sender

RCPT TO

Specifies the email recipient

DATA

Initiates the transmission of the email

RSET

Aborts the current transaction but keeps connection

VRFY

Verifies if a mailbox is available

EXPN

Checks mailbox availability and expands mailing lists

NOOP

No operation; prevents disconnection due to timeout

QUIT

Terminates the session

Enumeration Techniques

Example output:

Scanning with Nmap

MX Record Enumeration

Identify mail servers using DNS queries:

Example output:

User Enumeration

SMTP servers can often be abused to enumerate valid email accounts.

Using VRFY Command

Example response:

Using EXPN Command

Particularly useful for finding users in distribution lists:

Example response:

Using RCPT TO Command

This requires initiating an email transaction:

Example response:

Automated User Enumeration

Using the smtp-user-enum tool:

Example output:

Authentication Attacks

Once valid users are identified, authentication attacks can be attempted.

Password Spraying with Hydra

Example output:

Open Relay Abuse

An SMTP open relay allows anyone to send emails through the server, which can be abused for spam or phishing.

Testing for Open Relay

Example output:

Exploiting Open Relay

Using the swaks tool to send emails through an open relay:

Cloud Email Services Enumeration

Modern environments often use cloud email services like Microsoft 365 or Google Workspace.

O365 Enumeration Example

Using the o365spray tool:

Password Spraying against Cloud Services

Vulnerability Assessment

Common SMTP Vulnerabilities

  1. Open Relay: Allows unauthorized email sending

  2. User Enumeration: Leaks valid usernames

  3. Cleartext Authentication: Transmits credentials in plaintext

  4. Outdated Software: May have known vulnerabilities

  5. Missing TLS: Allows eavesdropping on email communications

  6. Weak Authentication: Susceptible to brute force attacks

Software-Specific Vulnerabilities

Mail Server
Notable Vulnerabilities

Sendmail < 8.14.9

Multiple buffer overflows

Exim < 4.92.3

Remote code execution vulnerabilities

Postfix < 3.3.1

Denial of service vulnerabilities

Microsoft Exchange

ProxyLogon, ProxyShell, etc.

Defense Evasion Techniques

Avoiding Detection during SMTP Testing

  1. Rate limiting: Space out requests to avoid triggering alerts

  2. Careful user selection: Target non-privileged accounts in password spraying

  3. Session awareness: Avoid multiple failed authentication attempts

  4. Timeout management: Use longer timeouts to reduce concurrent connections

Penetration Testing Methodology

When testing SMTP services, follow these steps:

  1. Discovery: Identify mail servers through DNS and port scanning

  2. Version Enumeration: Determine SMTP server type and version

  3. User Enumeration: Identify valid email addresses or accounts

  4. Authentication Testing: Test for weak credentials

  5. Open Relay Testing: Check if the server can be abused to send emails

  6. TLS Configuration: Verify proper encryption implementation

  7. Vulnerability Assessment: Check for known CVEs based on version

  8. Exploitation: Test identified vulnerabilities

  9. Post-Exploitation: Leverage access for further objectives

Remediation Strategies

When reporting SMTP vulnerabilities, consider recommending:

  1. Disable VRFY/EXPN commands unless required

  2. Implement authentication for all SMTP transactions

  3. Enable TLS for all communications

  4. Update mail server software regularly

  5. Implement rate limiting to prevent brute force attacks

  6. Configure SPF, DKIM, and DMARC to prevent spoofing

  7. Regular security testing of email infrastructure

Practical Testing Scripts

Simple SMTP User Enumeration Script

Testing All SMTP Commands

By understanding SMTP services and their security implications, penetration testers can effectively identify and exploit misconfigurations and vulnerabilities in email systems.

Last updated