前言
光是审计框架肯定是不够的,用cms来练习代码审计,会对功能点的黑白盒测试有很大的帮助, 所以近期准备分析一下几个cms。
配置环境
首先官网下载一下EmpireCMS v7.5,在进入安装页面前,要记得在配置文件开启短标签。 同时,也可以得出这个cms如果有过滤php关键字,可以用短标签绕过。

cms常见问题
安装后,出于习惯再次访问安装页面,检测是否有重装漏洞, 发现这里有类似lock文件的install.off,所以要利用这个还需要搭配一个任意文件删除漏洞。

cve-2018-18086
这个漏洞利用条件的前提是先拿到后台管理员。 构造一个模型文件(*.mod),在里面写个shell。 (不加.php也可以,我只是直接加上.mod后缀,没有去掉而已)

按图片步骤上传模型文件导入,再从前端参数定位功能点的代码段。

来到e/admin/ecmsmod.php的elseif($enews=="LoadInMod")功能点, 可以看出这里将文件对象以及它的信息传入了LoadInMod($_POST,$file,$file_name,$file_type,$file_size,$logininid,$loginin)函数。

跟进一下该函数,首先CheckLevel()函数检验管理员权限, 接着用RepPostVar()函数对$tb_name进行强过滤,再检测后缀名是否为.mod, 最后以一个加密后的文件名上传文件,确保搞安全的同学利用不了这个文件。 但这里问题在于直接include了我们上传的模型文件,所以解析了里面php代码。

解析的php代码。

成功执行file_put_contents()函数写入文件。

shell成功执行命令。

关于cve-2018-18086的防御方案
不太清楚官方有没有给出什么补丁,只看到官方说在后台登录加入登录码, 以此来控制进入后台的前提条件。
此外,还有官方也指出可以删除不需要的功能并提供了方法,不过也有案例是开发人员偷懒只删除前端功能点, 搞安全的同学只需要访问相同路径即可使用对应的功能。
此功能点修复的话,个人倾向于在上传后与include前这段代码中增加对模型文件的内容检测。
CVE-2018-19462
同样的,这个漏洞也是基于拿到后台管理员账号,准备进一步getshell利用的。 先按图片步骤点击,接着常规操作绝对路径写shell,查看前端发送到后端的参数,定位一下功能点代码段。

根据$enews=$_POST['enews']找到这里,可以看到调用了DoExecSql($_POST,$logininid,$loginin)方法。

跟进一下该函数,这里调用了RepSqlTbpre($query)。

看一下RepSqlTbpre($query)的代码,发现只是对表名添加前缀操作。

return回来,可以看到调用了DoRunQuery($query)函数。

DoRunQuery($query)函数内对sql语句进行了处理, 如果有多条语句的话,用foreach遍历执行sql语句。 (看到这里我是比较意外的,真的什么过滤也没有,不过想了想这毕竟是人家对后台管理系统)

页面回显执行sql语句成功。

成功写入shell。

成功执行命令。

关于CVE-2018-19462的防御方案
个人偏向于给该角色分配好权限,控制写入shell的点。
There Is Nothing Below
