Apache Shiro
作为常用的 Java
安全框架,拥有执行身份验证、授权、密码和会话管理等功能,通常会和 Spring
等框架一起搭配使用来开发 Web
应用。
影响范围
- Apache Shiro < 1.5.3
- Spring 框架中只使用 Shiro 鉴权
漏洞复现
测试 Demo :
https://github.com/l3yx/springboot-shiro
权限配置如下,其中 /admin
下的路由需要登录才能访问
@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";
}
maven
打包项目为 test.war
,部署于 Tomcat
。该漏洞成功利用存在下面两个条件
1、应用不能部署在根目录,也就是需要 context-path
, server.servlet.context-path=/test
,如果为根目录则 context-path
为空,就会被 CVE-2020-1957
的 patch 将 URL 格式化,值得注意的是若 Shiro
版本小于 1.5.2 的话那么该条件就不需要
2、Spring
控制器中没有另外的权限校验代码
如果直接访问 /test/admin/page
,会返回302跳转要求登录
但是访问/;/test/admin/page
, 就能直接绕过 Shiro 权限验证,访问到 /admin 路由中的信息