taibeihacker
Moderator
0x00 漏洞简述
Apache Shiro 1.5.3之前的版本中,當將Apache Shiro與Spring動態控制器一起使用時,精心編制的請求可能會導致繞過身份驗證,如果直接訪問/shiro/admin/page ,會返回302跳轉要求登錄,訪問/;/shiro/admin/page , 就能直接繞過Shiro權限驗證,訪問到/admin路由中的信息0x01 漏洞影响
Apache Shiro 1.5.3之前的版本Spring 框架中只使用Shiro 鑑權0x02 环境搭建
1.下載項目到本地https://github.com/l3yx/springboot-...ithub.com/backlion/demo/blob/master/shiro.war0x03 漏洞复现
1.權限配置如下,其中/admin下的路由需要登錄才能訪問@BeanShiroFilterFactoryBean shiroFilterFactoryBean(){
ShiroFilterFactoryBean bean=new ShiroFilterFactoryBean();
bean.setSecurityManager(securityManager());
bean.setLoginUrl('/login');
bean.setSuccessUrl('/index');
bean.setUnauthorizedUrl('/unauthorizedurl');
MapString, 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';
}2.maven打包項目為shiro.war,部署於Tomcat。該漏洞成功利用存在下面兩個條件應用不能部署根目錄root目錄下,也就是需要context-path,server.servlet.context-path=/shiro,如果為根目錄則context-path為空,就會被CVE-2020-1957的patch將URL格式化,值得注意的是若Shiro版本小於1.5.2的話那麼該條件就不需要。 Spring控制器中沒有另外的權限校驗代碼3.如果直接訪問/shiro/admin/page,會返回302跳轉要求登錄


0x04 漏洞分析
由於Shiro的權限校驗是通過判斷url匹配來做的,如果能找到Shiro獲取的url與Web框架處理url不一致的情況就能造成權限繞過。 Shiro中對於URL的獲取及匹配在org.apache.shiro.web.filter.mgt.PathMatchingFilterChainResolver#getChain以訪問/;/shiro/admin/page舉例,通過getPathWithinApplication函數得到的路徑為/






0x05 漏洞修复
升級到最新版,官方已在新版本中修復了該漏洞0x06 参考文献

Apache Shiro权限绕过漏洞分析(CVE-2020-11989)
Apache Shiro作为常用的Java安全框架,拥有执行身份验证、授权、密码和会话管理等功能,通常会和Spring等框架一起搭配使用来开发Web应用。最近研究Shiro本来是为SCTF出题做准备,但在测试过程中却发现了一些新的缺陷能导致权限绕过,便报告给Apache Shiro官方。玄武实验室安全研究人员也单独发现了另外一种绕过方式。
