SMTP Pentest Guide

Vulnerability Analysis Phase

The vulnerability analysis phase involves examining the information gathered during reconnaissance and scanning to identify potential security weaknesses in the SMTP server. This phase bridges the gap between discovery and exploitation.

Common SMTP Vulnerabilities

SMTP servers can suffer from a variety of vulnerabilities and misconfigurations:

1. Open Mail Relay

A server that allows unauthorized users to send emails to any destination is called an "open relay." These servers can be abused for spam and phishing campaigns.

Testing for Open Relay

Check if the server allows unauthorized relaying

telnet mail.example.com 25\nHELO pentest.local\nMAIL FROM: <attacker@external.com>\nRCPT TO: <victim@another-domain.com>\nQUIT
Explanation: This test checks if the server allows you to send emails from an external address to another external address (relaying). If the server accepts the RCPT TO command with a 250 status code as shown, it's vulnerable to being used as an open relay. Properly configured servers should reject this with a 550 'Relaying denied' message.

2. SMTP Injection

SMTP injection vulnerabilities occur when user input is not properly sanitized, allowing attackers to insert SMTP commands into messages [^4].

Testing for SMTP Injection

Checking if a web application is vulnerable to SMTP injection

Name: Test User\nEmail: attacker@evil.com\nMessage: Hello\n.\nMAIL FROM: <spoofed@victim.com>\nRCPT TO: <target@example.com>\nDATA\nFrom: CEO <ceo@company.com>\nSubject: Urgent payment\n\nPlease wire $10,000 immediately.\n.\n
Explanation: This test would typically be performed through a web form that sends emails. The payload attempts to terminate the current email with a dot on a new line (SMTP's end-of-data marker), then inject new SMTP commands to send a second, spoofed email. If successful, the server would process these commands, allowing message spoofing [^4].

3. STARTTLS Downgrade

Attackers can force a downgrade from encrypted to plaintext communications when STARTTLS is not properly enforced.

Testing STARTTLS Enforcement

Check if the server requires encryption

openssl s_client -connect mail.example.com:587 -starttls smtp -crlf
Explanation: After establishing the connection, verify if the server offers STARTTLS (looks for '250-STARTTLS' in capabilities). Then attempt to send commands without upgrading to TLS. If the server allows sensitive operations without encryption, it's vulnerable to STARTTLS downgrade attacks and credential interception.

4. User Enumeration

Some servers disclose whether email addresses exist, helping attackers build lists of valid targets.

SMTP VRFY Command Vulnerability

Check if VRFY command leaks user information

telnet mail.example.com 25\nHELO pentest.local\nVRFY admin\nVRFY nonexistent
Explanation: This test checks if the VRFY command can be used to validate email addresses. If the server returns different responses for existing versus non-existent users (like a 252 versus 550 code), an attacker can enumerate valid accounts. Modern secure configurations typically disable VRFY or provide ambiguous responses.

5. Weak Authentication

SMTP servers with weak authentication mechanisms or poor credential management are vulnerable to unauthorized access.

Testing Authentication Methods

Identify supported SMTP authentication mechanisms

telnet mail.example.com 25\nEHLO pentest.local
Explanation: Look for '250-AUTH' in the response to see what authentication methods are supported. PLAIN sends credentials in base64 encoding (not encryption), which is insecure without TLS. LOGIN is similarly weak. Secure servers should only offer authentication after STARTTLS or on SSL ports.

SMTP Software-Specific Vulnerabilities

Different SMTP server software has different vulnerabilities. Once you've identified the server software (e.g., Postfix, Exchange, Sendmail), look for known vulnerabilities specific to that software and version.

Using Searchsploit for SMTP Vulnerabilities

Search for known exploits in the Exploit Database

searchsploit postfix 3.1
Explanation: Searchsploit is a command-line tool for searching the Exploit Database. This command searches for exploits specific to Postfix version 3.1. The results show potential vulnerabilities that could be exploited, including a buffer overflow and a credential exposure issue.

Vulnerability Scanning with Metasploit

Using Metasploit Framework to scan for SMTP vulnerabilities

msfconsole\nuse auxiliary/scanner/smtp/smtp_version\nset RHOSTS mail.example.com\nrun
Explanation: Metasploit contains numerous modules for testing SMTP servers. This example uses the smtp_version scanner to identify the server software. Once identified, you can search for other modules specific to that software: 'search smtp postfix'. Metasploit has modules for testing open relay, user enumeration, and known vulnerabilities.

Common Configuration Issues

Beyond software vulnerabilities, SMTP servers often suffer from configuration weaknesses:

  • Lack of SPF, DKIM, and DMARC - Makes spoofing emails from the domain easier
  • Weak TLS Configuration - Accepting outdated protocols or weak ciphers
  • Missing or Outdated SSL Certificates - Enabling man-in-the-middle attacks
  • Unrestricted Internal Relaying - Allowing any internal user to send as anyone else
  • Verbose Error Messages - Providing attackers with useful information

Risk Assessment

For each identified vulnerability, assess the risk by considering:

  • Impact - What could an attacker do if they exploited this vulnerability?
  • Likelihood - How easy is it to exploit? Are there mitigating factors?
  • Exploitability - Are there public exploits available? Does it require special access?

Documenting Findings

Document each vulnerability with:

  • A clear description of the issue
  • Steps to reproduce
  • Evidence (logs, screenshots, command output)
  • Risk rating
  • Remediation recommendations