
- by x32x01 ||

What is SMTP Injection?
SMTP Injection is a web security vulnerability that allows an attacker to inject SMTP commands or email headers into an application that sends emails using unsanitized user input. This can lead to email spoofing, mass spam mailing, and sometimes even command injection, depending on the mail server configuration.
Common Areas Where SMTP Injection Happens
SMTP Injection vulnerabilities usually occur in the following areas:




Root Cause: These areas accept user input that is directly used in the email headers (To, From, Subject, etc.) without proper sanitization.
Real-World Example (PHP)
Here’s a vulnerable PHP snippet: PHP:
<?php
$to = "admin@example.com";
$subject = $_POST['subject'];
$message = $_POST['message'];
$headers = "From: ".$_POST['email'];
mail($to, $subject, $message, $headers);
?>
attacker@evil.com%0ACc:victim@example.com
The resulting email headers become:
From:
attacker@evil.com
Cc:
victim@example.com

SMTP Injection Payloads
Below are common payloads used to test or exploit SMTP Injection: Code:
attacker@example.com%0ACc: victim@example.com
attacker@example.com%0ABcc: boss@example.com
attacker@example.com\r\nSubject: Injected Email
%0A%0DTo: victim@example.com%0ASubject: Hacked
Tools for Testing
Burp Suite - Modify HTTP request with payloadsOWASP ZAP - Active scanning and fuzzing
WFuzz - Fuzz headers with SMTP payloads
Python Scripts - Using smtplib or requests for custom testing
Mailtrap.io - For safe testing without sending real emails
Prevention Techniques
To prevent SMTP Injection, follow these best practices:
Strip or block newline characters: \n, \r, %0A, %0D
Whitelist valid email formats using:
Code:
$email = filter_var($_POST['email'], FILTER_VALIDATE_EMAIL);

Use libraries or services that handle email headers automatically:
PHPMailer
SendGrid
Mailgun
SMTP2GO

Avoid inserting raw user input directly in headers like From, Cc, Bcc, or Subject.


Header Injection Inject newline characters and see if additional headers are accepted
Spoofed Headers Try injecting fake From, Cc, or Bcc
Payload Fuzzing Fuzz form inputs with common payloads
Mass Mail Potential Check if multiple recipients can be injected
Response Analysis Analyze server response or email logs
Impact of SMTP Injection





Real Incident:
> A bug bounty hunter found SMTP Injection in a popular retail site’s feedback form. He was able to send spoofed emails to thousands of users using their trusted domain. The company’s domain got blacklisted, and customer trust was lost - all due to a single unsanitized input field.
SMTP Injection is easy to miss, but its impact can be devastating. Always validate user inputs, use secure libraries, and never trust user-controlled data when building emails.