JAVA代码审计之某瀑布内容管理系统
瀑布内容管理系统 是一款基于Java技术栈开发的企业级内容管理平台。
一、项目介绍
瀑布内容管理系统,采用SpringBoot + Apache Shiro + Mybatis Plus + Thymeleaf 实现的内容管理系统(附带权限管理),是搭建博客、网站的不二之选。
下载地址 https://gitee.com/LinZhaoguan/pb-cms/tree/v1.0.0/
二、环境搭建
将项目导入 idea 创建mysqli 数据库 pb_cms_base 导入docs/db/pb_cms_base.sql 数据库文件 本地开启redis服务。 修改 application-dev.yml 数据库账号和密码 编译运行即可。
三、审计过程
漏洞1.shiro反序列化漏洞
查看pom.xml 发现存在
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-spring</artifactId>
<version>1.4.1</version>
</dependency>shiro721用到的加密方式是AES-CBC,而且其中的ase加密的key基本猜不到了,是系统随机生成的。
影响 Apache Shiro 1.2.5, 1.2.6, 1.3.0, 1.3.1, 1.3.2, 1.4.0-RC2, 1.4.0, 1.4.1版本。
在这套cms上默认提供硬编码 3AvVhmFLUs0KTA3Kprsdag==
文件 com/puboot/common/config/ShiroConfig.java
public CookieRememberMeManager rememberMeManager() {
CookieRememberMeManager cookieRememberMeManager = new CookieRememberMeManager();
cookieRememberMeManager.setCookie(rememberMeCookie());
//rememberMe cookie加密的密钥 建议每个项目都不一样 默认AES算法 密钥长度(128 256 512 位)
cookieRememberMeManager.setCipherKey(Base64.decode("3AvVhmFLUs0KTA3Kprsdag=="));
return cookieRememberMeManager;
}漏洞复现
漏洞2.shiro鉴权绕过
Apache Shiro 身份验证绕过漏洞 (CVE-2020-11989)
Apache Shiro是一个强大且易用的Java安全框架,它可以用来执行身份验证、授权、密码和会话管理。目前常见集成于各种应用中进行身份验证,授权等。在Apache Shiro 1.5.3之前的版本,将Apache Shiro与Spring控制器一起使用时,特制请求可能会导致身份验证绕过。
当前的shiro版本是1.4.1 又是使用springboot 符合条件
在url路径上加上 ;即可绕过后台访问到页面。
访问后台会302跳转
在url路径上加上/;/就能绕过鉴权访问到页面
跟踪调试,漏洞位置在: org/apache/shiro/web/filter/mgt/PathMatchingFilterChainResolver#getChain
跟进 getPathWithinApplication 位置 org/apache/shiro/web/filter/mgt/PathMatchingFilterChainResolver#getPathWithinApplication继续跟进 getPathWithinApplication
位置org/apache/shiro/web/util/WebUtils#getPathWithinApplication
继续跟进 getRequestUri位置 org/apache/shiro/web/util/WebUtils#getRequestUri
继续跟进 decodeAndCleanUriString 位置 org/apache/shiro/web/util/WebUtils#decodeAndCleanUriString
主要的作用是 查找字符串;找到就进行字符串截取 所以 传入的 /;/cms/attachment/config截取之后就是
/返回出去 所以 requestUril的值就是 /
接着就是 查找 / 是否存在/;/cms
接着返回 org/apache/shiro/web/filter/mgt/PathMatchingFilterChainResolver#getChain进行判断
filterChainManager.getChainNames() 是shiro允许放行的url
pathMatches 传入进来的第一个是/传入的也是 / 所以就会放行。并不会进行拦截。
anon 不需要认证就可以访问。
在这里下个断点 文件 org.springframework.web.util.UrlPathHelper#getPathWithinServletMapping
跟进 org/springframework/web/util/UrlPathHelper#getPathWithinApplication
继续跟进 getRequestUri
跟进 decodeAndCleanUriString 这个函数的作用是去掉url里面的;decodeRequestString对url进行解码
getSanitizedPath 这个函数的作用是去掉//变成/
所以传入的/;/cms/attachment/config变成/cms/attachment/config。
发现shiro对/;/cms/admin/处理后得到/绕过了权限认证
spring对/;/cms/admin/处理后得到/cms/admin/正常访问
漏洞3.Thymeleaf模板注入漏洞
位置 com/puboot/module/blog/controller/BlogWebController.java
@GetMapping("/")
public String index(Model model, ArticleConditionVo vo) {
model.addAttribute("pageUrl", "blog/index");
model.addAttribute("categoryId", "index");
model.addAttribute("sliderList", bizArticleService.sliderList());//轮播文章
loadMainPage(model, vo);
return THEME_PREFIX + bizThemeService.selectCurrent().getName() + "/index";
}在查找模板中,引用了用户输入的内容会造成 Thymeleaf模板注入漏洞
在后台添加主题加入加入表达式
__${T(Runtime).getRuntime().exec("calc")}__::.x接着启动
访问主页的 bizThemeService.selectCurrent().getName()payload 结合 Thymeleaf 触发漏洞
漏洞复现
漏洞4.SSRF漏洞
位置 com/puboot/common/util/PushArticleUtil#postBaidu
存在 conn = new URL(postUrl).openConnection(); 会对http进行请求
public class PushArticleUtil {
/*推送百度*/
public static String postBaidu(String postUrl, String[] parameters) {
if (null == postUrl || null == parameters || parameters.length == 0) {
return null;
}
StringBuilder result = new StringBuilder();
//建立URL之间的连接
URLConnection conn = null;
try {
conn = new URL(postUrl).openConnection();
} catch (IOException e) {
log.error("【推送百度】建立URL之间的连接失败:{}", e.getMessage(), e);
}
try (BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
PrintWriter out = new PrintWriter(conn.getOutputStream())) {
//设置通用的请求属性
conn.setRequestProperty("Host", "data.zz.baidu.com");
conn.setRequestProperty("User-Agent", "curl/7.12.1");
conn.setRequestProperty("Content-Length", "83");
conn.setRequestProperty("Content-Type", "text/plain");
//发送POST请求必须设置如下两行
conn.setDoInput(true);
conn.setDoOutput(true);
//发送请求参数
StringBuilder param = new StringBuilder();
for (String s : parameters) {
param.append(s).append('\n');
}
out.print(param.toString().trim());
//进行输出流的缓冲
out.flush();
//通过BufferedReader输入流来读取Url的响应
String line;
while ((line = in.readLine()) != null) {
result.append(line);
}
} catch (IOException e) {
log.error("推送百度出现异常:{}", e.getMessage(), e);
}
return result.toString();
}
}这个函数被 com/puboot/module/admin/controller/ArticleController#pushBatch调用
@PostMapping("/batch/push")
@ResponseBody
public ResponseVo pushBatch(@RequestParam("urls[]") String[] urls) {
try {
String url = configService.selectAll().get(SysConfigKey.BAIDU_PUSH_URL.getValue());
BaiduPushResVo baiduPushResVo = JSON.parseObject(PushArticleUtil.postBaidu(url, urls), BaiduPushResVo.class);
if (baiduPushResVo.getNotSameSite() == null && baiduPushResVo.getNotValid() == null) {
return ResultUtil.success("推送文章成功");
} else {
return ResultUtil.error("推送文章失败", baiduPushResVo);
}
} catch (Exception e) {
return ResultUtil.error("推送文章失败,请检查百度推送接口!");
}
}在这里无法回显 只能http请求
在yakit创建dnslog
在后台网百度推送地址天下 dnslog
后台的百度推送 还要更改一下数据库
在权限表与用户表的权限对不上将.去掉
就能访问百度推送
漏洞复现:
成功触发dnslog
漏洞5:文件上传漏洞
存在任意上传漏洞 但是在springboot中无法解析 影响不大
位置 com/puboot/common/util/FileUploadUtil
public class FileUploadUtil {
private final Pattern PATTERN = Pattern.compile("\\\\", Pattern.LITERAL);
public String uploadLocal(MultipartFile mf, String uploadPath) {
String res = "";
try {
String fileName = null;
String nowdayStr = new SimpleDateFormat("yyyyMMdd").format(new Date());
String uploadFullPath = uploadPath + File.separator + nowdayStr + File.separator;
File fileDir = new File(uploadFullPath);
// 创建文件根目录
if (!fileDir.exists() && !fileDir.mkdirs()) {
log.error("创建文件夹失败: {}", uploadFullPath);
return null;
}
// 获取文件名
String orgName = mf.getOriginalFilename();
fileName = orgName.substring(0, orgName.lastIndexOf('.')) + '_' + System.currentTimeMillis() + orgName.substring(orgName.indexOf('.'));
String savePath = fileDir.getPath() + File.separator + fileName;
File savefile = new File(savePath);
FileCopyUtils.copy(mf.getBytes(), savefile);
res = nowdayStr + File.separator + fileName;
if (res.contains("\\")) {
res = PATTERN.matcher(res).replaceAll(Matcher.quoteReplacement("/"));
}
} catch (IOException e) {
log.error(e.getMessage(), e);
}
return res;
}
}直接获取文件名 创建 File savefile = new File(savePath); 接着使用 FileCopyUtils.copy(mf.getBytes(), savefile); 将上传的内容复制进去。res = nowdayStr + File.separator + fileName;接着返回上传路径。
漏洞复现:
除了能直接上传外 也可以造成目录穿越上传
直接就能使用文件名 而且还能跳转目录。可以配合其他漏洞使用危害更大。
漏洞6.验证码复用
登录框存在验证码
源码分析
位置 com/puboot/module/admin/controller/SystemController#login
从seesion获取验证码值与提交的值对比之后 再进入账号和密码逻辑 密码和账号不对的情况下并没有销毁验证码。造成验证码复用。
报告披露PB-CMS存在SQL注入、文件上传、XSS、认证绕过及不安全反序列化五大漏洞,并提供对应修复措施。
由 AI 根据全文自动生成,仅供参考,以原文为准