Apache Shiro权限绕过漏洞分析(CVE-2020-11989)
字数 1188 2025-08-25 22:59:03
Apache Shiro权限绕过漏洞分析(CVE-2020-11989)教学文档
1. 漏洞概述
Apache Shiro是一个常用的Java安全框架,提供身份验证、授权、密码和会话管理等功能。CVE-2020-11989是一个权限绕过漏洞,攻击者可以通过构造特殊URL绕过Shiro的权限控制机制。
2. 影响范围
- Apache Shiro版本 < 1.5.3
- 在Spring框架中仅使用Shiro进行鉴权的应用
3. 漏洞复现
3.1 测试环境搭建
- 使用提供的测试Demo: https://github.com/l3yx/springboot-shiro
- 权限配置示例:
@Bean
ShiroFilterFactoryBean shiroFilterFactoryBean(){
ShiroFilterFactoryBean bean = new ShiroFilterFactoryBean();
bean.setSecurityManager(securityManager());
bean.setLoginUrl("/login");
bean.setSuccessUrl("/index");
bean.setUnauthorizedUrl("/unauthorizedurl");
Map<String, String> map = new LinkedHashMap<>();
map.put("/doLogin", "anon");
map.put("/admin/*", "authc");
bean.setFilterChainDefinitionMap(map);
return bean;
}
- 控制器示例:
@GetMapping("/admin/page")
public String admin() {
return "admin page";
}
3.2 漏洞利用条件
- 应用不能部署在根目录,需要有context-path(如
server.servlet.context-path=/test)- 如果Shiro版本 < 1.5.2,此条件不需要
- Spring控制器中没有额外的权限校验代码
3.3 漏洞验证
- 正常访问:
/test/admin/page→ 302跳转要求登录 - 绕过访问:
/;/test/admin/page→ 直接访问到admin页面
4. 漏洞原理分析
4.1 URL处理流程差异
漏洞本质在于Shiro和Web框架对URL处理的差异:
- Tomcat处理:将
/;test/admin/page识别为test应用下的/admin/page路由 - Shiro处理:由于分号(;)截断,将URL识别为
/ - Spring处理:正确处理为test应用下的
/admin/page路由
4.2 关键代码分析
Shiro处理流程
PathMatchingFilterChainResolver#getChain获取URL路径WebUtils#getPathWithinApplication处理路径WebUtils#getRequestUri获取请求URI:
// 获取结果为/;/test//admin/page
String uri = getContextPath() + getServletPath() + getPathInfo();
WebUtils#decodeAndCleanUriString处理URI:
// 根据ASCII 59(;)截断URL,返回/
Spring处理流程
UrlPathHelper#getPathWithinServletMapping正确获取路径- 最终得到
/admin/page路径
5. 漏洞修复
Shiro 1.5.3修改了URL获取逻辑:
- 不再单独处理context-path
- 关键修复代码在
WebUtils#getPathWithinApplication
6. 防护建议
- 升级Apache Shiro到1.5.3或更高版本
- 在Spring控制器中添加额外的权限校验
- 避免将应用部署在非根目录(如果可能)
7. 相关参考
- 官方修复:Apache Shiro 1.5.3 Release Notes
- 类似漏洞:CVE-2020-1957(需要对比说明差异)