> For the complete documentation index, see [llms.txt](https://hacktricks.xsx.tw/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacktricks.xsx.tw/pentesting-web/email-injections.md).

# Email Injections

<figure><img src="/files/se5N2OCbiHd0PbneketN" alt=""><figcaption></figcaption></figure>

\
使用[**Trickest**](https://trickest.com/?utm_campaign=hacktrics\&utm_medium=banner\&utm_source=hacktricks)轻松构建并由全球**最先进**的社区工具提供支持的**自动化工作流程**。\
立即获取访问权限：

{% embed url="<https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks>" %}

<details>

<summary><strong>从零开始学习AWS黑客技术，成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE（HackTricks AWS Red Team Expert）</strong></a><strong>！</strong></summary>

支持HackTricks的其他方式：

* 如果您想看到您的**公司在HackTricks中做广告**或**下载PDF格式的HackTricks**，请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
* 获取[**官方PEASS & HackTricks周边产品**](https://peass.creator-spring.com)
* 发现[**PEASS家族**](https://opensea.io/collection/the-peass-family)，我们的独家[**NFTs**](https://opensea.io/collection/the-peass-family)收藏品
* **加入** 💬 [**Discord群**](https://discord.gg/hRep4RUj7f) 或 [**电报群**](https://t.me/peass) 或在**Twitter**上关注我们 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**。**
* 通过向[**HackTricks**](https://github.com/carlospolop/hacktricks)和[**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github仓库提交PR来分享您的黑客技巧。

</details>

## 在发送的电子邮件中注入

### 在发送方参数后注入抄送和密送

```
From:sender@domain.com%0ACc:recipient@domain.co,%0ABcc:recipient1@domain.com
```

### 注入参数

```
From:sender@domain.com%0ATo:attacker@domain.com
```

### 注入主题参数

```
From:sender@domain.com%0ASubject:This is%20Fake%20Subject
```

### 更改消息正文

注入两行换行符，然后编写您的消息以更改消息正文。

```
From:sender@domain.com%0A%0AMy%20New%20%0Fake%20Message.
```

### PHP mail() 函数利用

```bash
# The function has the following definition:

php --rf mail

Function [ <internal:standard> function mail ] {
- Parameters [5] {
Parameter #0 [ <required> $to ]
Parameter #1 [ <required> $subject ]
Parameter #2 [ <required> $message ]
Parameter #3 [ <optional> $additional_headers ]
Parameter #4 [ <optional> $additional_parameters ]
}
}
```

#### 第5个参数（$additional\_parameters）

这一部分将基于**假设攻击者控制该参数时如何滥用**。

此参数将被添加到PHP用于调用二进制sendmail的命令行中。但是，它将通过函数`escapeshellcmd($additional_parameters)`进行消毒。

攻击者可以在这种情况下**注入提取sendmail的参数**。

#### /usr/sbin/sendmail实现的差异

**sendmail**接口由系统上安装的MTA邮件软件（Sendmail、Postfix、Exim等）提供。尽管出于兼容性原因，**基本功能**（如-t -i -f参数）保持**相同**，但**其他功能和参数**根据安装的MTA而有很大不同。

以下是sendmail命令/接口不同手册页的一些示例：

* Sendmail MTA: <http://www.sendmail.org/\\~ca/email/man/sendmail.html>
* Postfix MTA: <http://www.postfix.org/mailq.1.html>
* Exim MTA: <https://linux.die.net/man/8/eximReferences>

根据sendmail二进制文件的**来源**，已发现不同的选项可用于滥用它们并**泄露文件甚至执行任意命令**。查看详细信息：[**https://exploitbox.io/paper/Pwning-PHP-Mail-Function-For-Fun-And-RCE.html**](https://exploitbox.io/paper/Pwning-PHP-Mail-Function-For-Fun-And-RCE.html)

## 在电子邮件名称中注入

### 电子邮件中被忽略的部分

符号：**+、-** 和 **{}** 在极少数情况下可用于标记，并被大多数电子邮件服务器忽略

* 例如 <john.doe+intigriti@example.com> → <john.doe@example.com>

括号中的注释（）在开头或结尾也将被忽略

* 例如 john.doe(intigriti)@example.com → <john.doe@example.com>

### 白名单绕过

<figure><img src="/files/Xcrioz0c9jPwneX8ffQd" alt="https://www.youtube.com/watch?app=desktop&#x26;v=4ZsTKvfP1g0"><figcaption></figcaption></figure>

### 引号

<figure><img src="/files/aDqxUieuUrKL7cqnoBl6" alt="https://www.youtube.com/watch?app=desktop&#x26;v=4ZsTKvfP1g0"><figcaption></figcaption></figure>

### IP地址

您还可以在方括号之间使用IP地址作为域名：

* john.doe@\[127.0.0.1]
* john.doe@\[IPv6:2001:db8::1]

### 其他漏洞

![https://www.youtube.com/watch?app=desktop\&v=4ZsTKvfP1g0](/files/L1UYBiUXGHcLaOyQoUux)

## 第三方SSO

### XSS

一些服务如**github**或**salesforce允许**您创建带有**XSS负载的电子邮件地址**。如果您可以**使用这些提供商登录其他服务**，并且这些服务**未正确消毒**电子邮件，您可能会引发**XSS**。

### 账户接管

如果**SSO服务**允许您**创建帐户而无需验证提供的电子邮件地址**（如**salesforce**），然后您可以使用该帐户登录**信任**salesforce的不同服务，您可以访问任何帐户。\
请注意，salesforce指示给定的电子邮件是否已验证，因此应用程序应考虑此信息。

## 回复地址

您可以发送一封电子邮件，使用\_**发件人：company.com***和***回复地址：attacker.com**\_，如果由于电子邮件是从**内部地址**发送的而发送了**自动回复**，则**攻击者**可能能够**接收**该**响应**。

## 硬退信率

某些服务，如AWS，实施了一个称为**硬退信率**的阈值，通常设置为10%。这是一个关键指标，特别是对于电子邮件传递服务。当超过此比率时，例如AWS的电子邮件服务可能会被暂停或阻止。

**硬退信**指的是因为收件人地址无效或不存在而被退回给发件人的电子邮件。这可能是由于各种原因，例如将电子邮件发送到不存在的地址、不存在的域或收件人服务器拒绝接受**电子邮件**。

在AWS的情况下，如果您发送了1000封电子邮件，其中有100封由于原因如地址或域无效而导致硬退信，这意味着10%的硬退信率。达到或超过此比率可能会触发AWS SES（简单电子邮件服务）阻止或暂停您的电子邮件发送功能。

保持低硬退信率对于确保不间断的电子邮件服务和维护发件人声誉至关重要。监控和管理邮件列表中电子邮件地址的质量可以极大地帮助实现这一目标。

有关更详细信息，可以参考AWS关于处理退信和投诉的官方文档[AWS SES Bounce Handling](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/notification-contents.html#bounce-types)。

## 参考资料

* <https://resources.infosecinstitute.com/email-injection/>
* <https://exploitbox.io/paper/Pwning-PHP-Mail-Function-For-Fun-And-RCE.html>
* <https://drive.google.com/file/d/1iKL6wbp3yYwOmxEtAg1jEmuOf8RM8ty9/view>
* <https://www.youtube.com/watch?app=desktop&v=4ZsTKvfP1g0>

<details>

<summary><strong>从零开始学习AWS黑客技术，成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE（HackTricks AWS Red Team Expert）</strong></a><strong>！</strong></summary>

支持HackTricks的其他方式：

* 如果您想在HackTricks中看到您的**公司广告**或**下载PDF版HackTricks**，请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
* 获取[**官方PEASS & HackTricks周边产品**](https://peass.creator-spring.com)
* 发现[**PEASS家族**](https://opensea.io/collection/the-peass-family)，我们的独家[NFTs收藏](https://opensea.io/collection/the-peass-family)
* **加入** 💬 [**Discord群**](https://discord.gg/hRep4RUj7f) 或 [**电报群**](https://t.me/peass) 或在**Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**上关注**我们。
* 通过向[**HackTricks**](https://github.com/carlospolop/hacktricks)和[**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github仓库提交PR来分享您的黑客技巧。

</details>

<figure><img src="/files/PcmnOBrpXxCjYC5y3bif" alt=""><figcaption></figcaption></figure>

\
使用[**Trickest**](https://trickest.com/?utm_campaign=hacktrics\&utm_medium=banner\&utm_source=hacktricks)可以轻松构建和**自动化工作流程**，使用全球**最先进**的社区工具。\
立即获取访问权限：

{% embed url="<https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks>" %}
