关联漏洞
标题:
资产上传中存在的远程代码执行和文件删除漏洞
(CVE-2024-47051)
描述:本安全公告解决了Mautic版本5.2.3之前的两个关键安全漏洞。这些漏洞可能被认证用户利用。
- 通过资产上传实现的远程代码执行(RCE):在资产上传功能中发现了一个远程代码执行漏洞。由于对允许的文件扩展名的控制不足,攻击者可以绕过限制并上传可执行文件,如PHP脚本。
- 路径遍历文件删除:在上传验证过程中存在路径遍历漏洞。由于对路径组件的处理不当,认证用户可以操纵文件删除过程,删除主机系统上的任意文件。
描述
Mautic < 5.2.3 Authenticated RCE
介绍
## Summary
Bad sanitization of uploaded file's content, type and extension in the Asset Edition feature allows an authenticated attacker to write arbitrary PHP code inside the web directory and locate where said file is written. This results in Remote Code Execution.
A path traversal also allows to exploit this functionality to recursively delete any directory on the filesystem that the web-user has permission to modify.

## Details - RCE
When editing an Asset via the route `/assets/view/{assetID}`, possibility is given to change the file of the asset.
Uploading a new file ultimately calls the following function inside `app/Bundles/AssetBundle/Controller/AssetController.php`:
`public function editAction(Request $request, UploaderHelper $uploaderHelper, AssetModel $model, $objectId, $ignorePost = false)`
The upload logic can be found here:
```
if (!$ignorePost && 'POST' == $method) {
$valid = false;
if (!$cancelled = $this->isFormCancelled($form)) {
if ($valid = $this->isFormValid($form)) {
$entity->setUploadDir($this->coreParametersHelper->get('upload_dir'));
$entity->preUpload();
$entity->upload();
```
More particularly, we are interested in the `preUpload()` and `upload()` methods, as they handle the actual file write on disk.
The first defect lies in `preUpload()` in `app/Bundles/AssetBundle/Entity/Asset.php`, as the implementation allows us to specify an arbitray file extension (thus bypassing the protection normally provided by the allowed_extensions array):
```
$filename = sha1(uniqid(mt_rand(), true));
$extension = $this->getFile()->guessExtension();
if (empty($extension)) {
// get it from the original name
$extension = pathinfo($this->originalFileName, PATHINFO_EXTENSION);
}
$this->path = $filename.'.'.$extension;
```
The line `$extension = $this->getFile()->guessExtension();` will return NULL if we a provide a filename ending with `.php` and content starting with `<?php` tag.
The empty($extension) check will therefore evaluate to true, and file extension will then be extracted through `pathinfo()` call, thus allowing us to upload temporary files with arbitrary content and extension. We can't control the actual name of the file as it is generated with sha1().
Then, inside the subsequent upload() method, the file will actually be written to disk inside the web directory through the following call:
`$this->getFile()->move($this->getUploadDir(), $this->path);`
It is using our arbitrary extension (contained in $this->path var).
Name of the file can then be retrieved by refreshing the Asset details page (/assets/view/{assetId}), under the Local filename table entry.
NB : This also works by altering the requests sent when creating a new Asset. This will call the newAction() function, but the logic is identical, and defects still lie in preUpload() and upload() methods.
## PoC - RCE
The PoC will not published for another month or so.
This is to give time for the organisations that rely on this software to patch it without fearing script kiddies wrecking their stuff.
After that, this repo will be updated with the full exploitation script and proofs. There is already enough info on this page anyway.
## Details - Arbitrary File Delete
When validating a temporary upload (via /s/assets/new or /s/assets/edit/{assetId}), the directory storing the temporary file is recursively deleted at the end of the request.
The parameter responsible to hold the name of the temporary directory is susceptible to path traversal attacks, allowing an authenticated attacker to delete any directory on the system, provided that web user has permission to do so.
This can result in loss of data, or even destruction of the entire filesystem if server happens to be executed by the root user.
## PoC - Arbitrary File Delete
Specify any file that exists on the system through the endpoint used below. If the file exists, the server will attempt to delete the directory it is stored in.

## Impact
Server takeover
Denial of Service
Loss of Data
## Timeline
- Oct 14th 2024 : First reach out and advisory sent to Mautic team
- Nov 12th 2024 : Exploitation script and remediation suggestions sent to development team
- Dec 13th 2024 : Second reach out
- Jan 21st 2025 : Patch ready for deployment
- Feb 25th 2025 : CVE assigned and published
文件快照
[4.0K] /data/pocs/03200d68b56e5a62878618d111f131a480d9df6d
├── [4.4K] README.md
└── [4.0K] screens
├── [617K] mautic-6.png
└── [516K] poc.png
1 directory, 3 files
备注
1. 建议优先通过来源进行访问。
2. 如果因为来源失效或无法访问,请发送邮箱到 f.jinxu#gmail.com 索取本地快照(把 # 换成 @)。
3. 神龙已为您对POC代码进行快照,为了长期维护,请考虑为本地POC付费,感谢您的支持。