写在前面:这次搭建环境比较顺利,没有遇到什么坑点,于是将前面学的应用到实际的框架审计中
1、环境搭建
-
获取源码
-
配置maven,重新编译(一般idea自带的maven直接重新加载就可以)
-
配置tomcat,包括war包和应用程序上下文(网站根目录),这两个尽量一样
-
配置数据库(有个坑点:需要将
dev/config
目录下db-config.properties
改为db.properties
)
2、审计漏洞
2.1 SQL注入漏洞
漏洞点在:后台 => 代码生成 => 增加
对应的网站路由为com/ofsoft/cms/admin/controller/system/SystemGenerateController#create方法
/**
* 创建表
*/
public void create() {
try {
String sql = getPara("sql");
Db.update(sql); // 执行SQL语句
rendSuccessJson();
} catch (Exception e) {
e.printStackTrace();
rendFailedJson(ErrorCode.get("9999"), e.getMessage());
}
}
下断点调试,进行跟进
getPara函数
获取参数
进入update语句
来到执行SQL语句的地方
这里用到了PreparedStatement预编译
,但是由于整个sql语句可控,所以并没有起到预编译的作用,因此可以使用报错注入
2.2 FreeMarker模板注入
漏洞位置:后台 => 模板文件 => 修改文件
在pom.xml中存在 FreeMarker依赖,该模板引擎存在模板注入
后台有修改模板的功能,找到对应的路由中对应的方法
com/ofsoft/cms/admin/controller/cms/TemplateController#save方法
/**
* 保存模板
*/
public void save() {
String resPath = getPara("res_path");
File pathFile = null;
if("res".equals(resPath)){
pathFile = new File(SystemUtile.getSiteTemplateResourcePath());
}else {
pathFile = new File(SystemUtile.getSiteTemplatePath());
}
String dirName = getPara("dirs");
if (dirName != null) {
pathFile = new File(pathFile, dirName);
}
String fileName = getPara("file_name");
// 没有用getPara原因是,getPara因为安全问题会过滤某些html元素。
String fileContent = getRequest().getParameter("file_content");
fileContent = fileContent.replace("<", "<").replace(">", ">");
File file = new File(pathFile, fileName);
FileUtils.writeString(file, fileContent);
rendSuccessJson();
}
可以看到该方法会获取文件内容,执行完一个替换操作后将内容写入新的文件,这个过程中没有对文件内容进行检查,因此可以往模板文件中写入payload来进行命令执行
<#assign value="freemarker.template.utility.Execute"?new()>${value("calc.exe")}
访问首页即可执行命令