Skip to content

Commit

Permalink
Merge pull request vulhub#598 from vulhub/phpmailer-translate
Browse files Browse the repository at this point in the history
[translate] phpmailer CVE-2017-5223
  • Loading branch information
phith0n authored Feb 23, 2025
2 parents 7101474 + 00c54a4 commit 611c39d
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 17 deletions.
36 changes: 20 additions & 16 deletions phpmailer/CVE-2017-5223/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# PHPMailer 任意文件读取漏洞(CVE-2017-5223
# PHPMailer Arbitrary File Read (CVE-2017-5223)

## 漏洞原理
[中文版本(Chinese version)](README.zh-cn.md)

PHPMailer在发送邮件的过程中,会在邮件内容中寻找图片标签(`<img src="...">`),并将其src属性的值提取出来作为附件。所以,如果我们能控制部分邮件内容,可以利用`<img src="/etc/passwd">`将文件`/etc/passwd`作为附件读取出来,造成任意文件读取漏洞。
PHPMailer is a popular PHP library for sending emails.

- http://www.freebuf.com/vuls/124820.html
- https://www.exploit-db.com/exploits/43056/
Before the PHPMailer 5.2.18, during the email sending process, PHPMailer searches for image tags (`<img src="...">`) in the email content and extracts their src attribute values as attachments. Therefore, if we can control part of the email content, we can use `<img src="/etc/passwd">` to read the file `/etc/passwd` as an attachment, resulting in an arbitrary file read vulnerability.

## 漏洞环境
References:

在当前目录下创建文件`.env`,内容如下(将其中的配置值修改成你的smtp服务器、账户、密码):
- http://www.freebuf.com/vuls/124820.html
- https://www.exploit-db.com/exploits/43056/

## Environment Setup

First, create a `.env` file in the current directory with the following content (modify the configuration values to your SMTP server, account, and password):

```
SMTP_SERVER=smtp.example.com
Expand All @@ -19,31 +23,31 @@ SMTP_PASSWORD=secret
SMTP_SECURE=tls
```

其中,`SMTP_SECURE`是SMTP加密方式,可以填写none、ssl或tls。
Here, `SMTP_SECURE` is the SMTP encryption method, which can be set to none, ssl, or tls.

然后编译、运行测试环境:
Then compile and run the test environment:

```
docker compose build
docker compose up -d
```

环境启动后,访问`http://your-ip:8080/`,即可看到一个“意见反馈”页面。
After the server starts, visit `http://your-ip:8080/` to see a "Feedback" page.

## 漏洞复现
## Vulnerability Reproduction

“意见反馈”页面,正常用户填写昵称、邮箱、意见提交,这些信息将被后端储存,同时后端会发送一封邮件提示用户意见填写完成:
On the "Feedback" page, normal users fill in their nickname, email, and feedback for submission. This information will be stored by the backend, and the backend will send an email to notify users that their feedback has been submitted:

![](1.png)

> 该场景在实战中很常见,比如用户注册网站成功后,通常会收到一封包含自己昵称的通知邮件,那么,我们在昵称中插入恶意代码`<img src="/etc/passwd">`,目标服务器上的文件将以附件的形式被读取出来。
> This scenario is common in real-world applications. For example, when users successfully register on a website, they usually receive a notification email containing their nickname. Therefore, if we insert malicious code `<img src="/etc/passwd">` in the nickname field, files on the target server will be read as attachments.
同样,我们填写恶意代码在“意见”的位置:
Similarly, we can place the malicious code in the "Feedback" field:

![](2.png)

收到邮件,其中包含附件`/etc/passwd``/etc/hosts`
When receiving the email, it contains attachments `/etc/passwd` and `/etc/hosts`:

![](3.png)

下载读取即可。
Download and read the files.
51 changes: 51 additions & 0 deletions phpmailer/CVE-2017-5223/README.zh-cn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# PHPMailer 任意文件读取漏洞(CVE-2017-5223)

PHPMailer 是 PHP 中常用的邮件发送库。

在 PHPMailer 5.2.18 之前,在发送邮件的过程中,PHPMailer 会在邮件内容中寻找图片标签(`<img src="...">`),并将其 src 属性的值提取出来作为附件。因此,如果我们能控制部分邮件内容,可以利用`<img src="/etc/passwd">`将文件`/etc/passwd`作为附件读取出来,造成任意文件读取漏洞。

参考链接:

- http://www.freebuf.com/vuls/124820.html
- https://www.exploit-db.com/exploits/43056/

## 漏洞环境

在当前目录下创建文件`.env`,内容如下(将其中的配置值修改成你的smtp服务器、账户、密码):

```
SMTP_SERVER=smtp.example.com
SMTP_PORT=587
[email protected]
SMTP_PASSWORD=secret
SMTP_SECURE=tls
```

其中,`SMTP_SECURE`是SMTP加密方式,可以填写none、ssl或tls。

然后编译、运行测试环境:

```
docker compose build
docker compose up -d
```

环境启动后,访问`http://your-ip:8080/`,即可看到一个"意见反馈"页面。

## 漏洞复现

"意见反馈"页面,正常用户填写昵称、邮箱、意见提交,这些信息将被后端储存,同时后端会发送一封邮件提示用户意见填写完成:

![](1.png)

> 该场景在实战中很常见,比如用户注册网站成功后,通常会收到一封包含自己昵称的通知邮件,那么,我们在昵称中插入恶意代码`<img src="/etc/passwd">`,目标服务器上的文件将以附件的形式被读取出来。
同样,我们填写恶意代码在"意见"的位置:

![](2.png)

收到邮件,其中包含附件`/etc/passwd``/etc/hosts`

![](3.png)

下载读取即可。
1 change: 0 additions & 1 deletion phpmailer/CVE-2017-5223/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '2'
services:
web:
build: .
Expand Down

0 comments on commit 611c39d

Please sign in to comment.