SMTP Smuggling
Reading time: 10 minutes
tip
学习和实践 AWS 黑客技术:
HackTricks Training AWS Red Team Expert (ARTE)
学习和实践 GCP 黑客技术:
HackTricks Training GCP Red Team Expert (GRTE)
学习和实践 Azure 黑客技术:
HackTricks Training Azure Red Team Expert (AzRTE)
支持 HackTricks
- 查看 订阅计划!
- 加入 💬 Discord 群组 或 Telegram 群组 或 在 Twitter 🐦 上关注我们 @hacktricks_live.
- 通过向 HackTricks 和 HackTricks Cloud GitHub 仓库提交 PR 来分享黑客技巧。
基本信息
This type of vulnerability was originally discovered in this post were it's explained that It's possible to exploit discrepancies in how the SMTP protocol is interpreted when finalising an email, allowing an attacker to smuggle more emails in the body of the legit one, allowing to impersonate other users of the affected domain (such as admin@outlook.com) bypassing defenses such as SPF.
为什么
这是因为在 SMTP 协议中,邮件中要发送的消息数据是由用户(攻击者)控制的,攻击者可以发送精心构造的数据,利用解析器之间的差异将额外的邮件走私进接收端。请查看原文中的示意图示例:
 (1) (1) (1) (1).png)
如何
为利用此漏洞,攻击者需要发送一些数据,让出站 SMTP 服务器认为这只是 1 封邮件,但入站 SMTP 服务器认为这是多封邮件。
研究人员发现,不同的入站服务器将不同字符视为邮件 DATA 结束,而出站服务器则不然。
例如,常见的 DATA 结束是 \r\n.\r。但如果入站 SMTP 服务器也支持 \n.,攻击者可以在他的邮件中加入该数据,然后开始指示新的 SMTP 命令,从而像上图那样走私额外的邮件。
当然,这只有在出站 SMTP 服务器不会把这些数据也当作消息 DATA 结束时才会奏效,否则出站会看到两封邮件而不是一封,最终这就是该漏洞中被滥用的不同步问题。
可能导致不同步的序列示例:
\n.\n.\r
另外请注意,SPF 会被绕过:例如如果你从 user@outlook.com 的邮件中走私出自 admin@outlook.com 的邮件,发送域仍然是 outlook.com。
攻击者检查表(需要满足的条件)
要成功走私第二封邮件,通常需要:
- 一个你能通过发送的出站服务器 A(通常有有效凭据),它会原样转发非标准的 end‑of‑DATA 序列。许多服务历史上会转发像
\n.\r\n或\n.\n这样的变体。 - 一个接收服务器 B,会将该非标准序列解释为 end‑of‑DATA,然后将其后续内容解析为新的 SMTP 命令(MAIL/RCPT/DATA...)。
- 出站必须实际使用
DATA发送(而不是BDAT)。如果 A 支持 CHUNKING/BDAT,走私只有在回退到 DATA 时才有效(例如 B 没有宣告 CHUNKING),否则基于长度的 BDAT 会防止歧义。 - PIPELINING 并非必需,但有助于将注入的命令隐藏在单次 TCP 写入中,从而使中间设备无法重新同步。
值得测试的常见 end‑of‑DATA 变体(取决于接收端):
\n.\n\n.\r\n\r.\r\n\r\n.\r(以裸 CR 结束)
注意:有效的情况是 “A 转发的内容” ∩ “B 接受的内容”。
Manual exploitation example (single session)
下面用一个原始的 STARTTLS SMTP 会话来说明这个思路。在第一个 DATA 块之后插入一个非标准的终止符,然后另起一个 SMTP 对话,接收服务器可能会将其视为一封新邮件。
手动 smuggling 会话 (STARTTLS)
``` $ openssl s_client -starttls smtp -crlf -connect smtp.example.com:587 EHLO a.example AUTH PLAINhello A \n.\r\nMAIL FROM:admin@target.com RCPT TO:victim@target.com DATA From: Admin admin@target.com To: victim victim@target.com Subject: smuggled
hello B \r\n.\r\n
If A forwards `\n.\r\n` and B accepts it as end‑of‑DATA, message “hello B” may be accepted as a second email from `admin@target.com` while passing SPF (aligned with A’s IPs).
</details>
Tip: When testing interactively, ensure `-crlf` is used so OpenSSL preserves CRLF in what you type.
---
## 自动化与扫描器
- hannob/smtpsmug:发送以多个畸形 end‑of‑DATA 序列结尾的消息,以查看接收方接受哪些序列。
- Example: `./smtpsmug -s mail.target.com -p 25 -t victim@target.com`
- The‑Login/SMTP‑Smuggling‑Tools:针对入站和出站两侧的扫描器,并包含一个分析 SMTP 服务器,用于精确查看哪些序列在发送端能存活。
- 入站快速检测:`python3 smtp_smuggling_scanner.py victim@target.com`
- 出站(通过中继):`python3 smtp_smuggling_scanner.py YOUR@ANALYSIS.DOMAIN --outbound-smtp-server smtp.relay.com --port 587 --starttls --sender-address you@relay.com --username you@relay.com --password '...'
`
这些工具可帮助你映射实际可用于 smuggling 的 A→B 对。
---
## CHUNKING/BDAT vs DATA
- DATA 使用哨兵终止符 `<CR><LF>.<CR><LF>`;任何关于 CR/LF 的归一化或 dot‑stuffing 的歧义都会导致不同步。
- CHUNKING (BDAT) 以精确字节长度框定消息体,从而防止经典的 smuggling。但如果发送方回退到 DATA(因为接收方未声明 CHUNKING),经典 smuggling 又有可能发生。
---
## 受影响软件和修复说明(用于定位目标)
- Postfix:在 3.9 之前默认容忍裸 LF;从 3.5.23/3.6.13/3.7.9/3.8.4 起,管理员可以启用 `smtpd_forbid_bare_newline`。当前建议为 `smtpd_forbid_bare_newline = normalize` (3.8.5+/3.7.10+/3.6.14+/3.5.24+) 或将其设为 `reject` 以严格执行 RFC。
- Exim:在 4.97.1(及之后版本)修复了当使用 DATA 时依赖混合 end‑of‑DATA 序列的变体。较旧的 4.97/4.96 可能在依赖 PIPELINING/CHUNKING 的情况下可被利用。
- Sendmail:在 8.18 中修复;较旧的 8.17.x 接受一些非标准的终止符。
- 各种库/服务器(例如 aiosmtpd 在 1.4.5 之前的版本、一些厂商网关和特定的 SaaS 中继)存在类似问题;现代版本倾向于仅接受严格格式的 `<CR><LF>.<CR><LF>` 作为 DATA。
使用上面的扫描器验证当前行为;许多厂商在 2024–2025 年初更改了默认配置。
---
## 红队实战提示
- 优先选择大型通用发送方作为 A(历史上常见的有 Exchange Online、共享主机等)。如果它们仍然转发某些非标准的 EOM 且在受害者的 SPF 中,你的 smuggled MAIL FROM 将继承它们的信誉。
- 枚举 B 的 SMTP 扩展:查看 `EHLO` 横幅中的 PIPELINING/CHUNKING;如果缺少 CHUNKING,那么从以 BDAT 为首的发送方发起攻击成功率更高。将其与畸形 EOM 结合以探测接收情况。
- 注意头部:smuggled 的消息通常会在 B 处产生一条单独的 Received 链。由于 MAIL FROM 与 A 的 IP 空间对齐,DMARC 常常会通过。
---
## **参考资料**
- [https://sec-consult.com/blog/detail/smtp-smuggling-spoofing-e-mails-worldwide/](https://sec-consult.com/blog/detail/smtp-smuggling-spoofing-e-mails-worldwide/)
- [https://www.postfix.org/smtp-smuggling.html](https://www.postfix.org/smtp-smuggling.html)
<div class="mdbook-alerts mdbook-alerts-tip">
<p class="mdbook-alerts-title">
<span class="mdbook-alerts-icon"></span>
tip
</p>
学习和实践 AWS 黑客技术:<img src="../../../../../images/arte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="../../../../../images/arte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">\
学习和实践 GCP 黑客技术:<img src="../../../../../images/grte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">[**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte)<img src="../../../../../images/grte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">
学习和实践 Azure 黑客技术:<img src="../../../../../images/azrte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">[**HackTricks Training Azure Red Team Expert (AzRTE)**](https://training.hacktricks.xyz/courses/azrte)<img src="../../../../../images/azrte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">
<details>
<summary>支持 HackTricks</summary>
- 查看 [**订阅计划**](https://github.com/sponsors/carlospolop)!
- **加入** 💬 [**Discord 群组**](https://discord.gg/hRep4RUj7f) 或 [**Telegram 群组**](https://t.me/peass) 或 **在** **Twitter** 🐦 **上关注我们** [**@hacktricks_live**](https://twitter.com/hacktricks_live)**.**
- **通过向** [**HackTricks**](https://github.com/carlospolop/hacktricks) 和 [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) GitHub 仓库提交 PR 来分享黑客技巧。
</details>
</div>
HackTricks