Apache Shiro 身份驗證繞過漏洞復現 (CVE-2020-11989)
侵刪
原創 VllTomFord
來自於公眾號: Tide安全團隊
參考鏈接:https://mp.weixin.qq.com/s?__biz=Mzg2NTA4OTI5NA==&mid=2247488061&idx=1&sn=1d85c84949b11de0fd6319319929ecc7&chksm=ce5e305cf929b94aa87b94e1c0323b78d9e3782ff66f622ce5a9b01a99bdbd174f9fb92f19fd&mpshare=1&scene=23&srcid=0805vQIgw6kPbsyHFJFqbqky&sharer_sharetime=1596621227588&sharer_shareid=ff83fe2fe7db7fcd8a1fcbc183d841c4#rd
Apache Shiro是一個強大且易用的Java安全框架,它可以用來執行身份驗證、授權、密碼和會話管理。目前常見集成於各種應用中進行身份驗證、授權等。
本文僅對此漏洞進行了復現,關於此漏洞的分析可以參考以下鏈接:
https://xlab.tencent.com/cn/2020/06/30/xlab-20-002/
https://xz.aliyun.com/t/7964
https://www.secshi.com/41318.html
https://xz.aliyun.com/t/7218
一、漏洞詳情
在Apache Shiro 1.5.3之前的版本,將Apache Shiro與Spring控制器一起使用時,特制請求可能會導致身份驗證繞過。
二、風險等級
二、風險等級
高風險
三、影響版本
Apache Shiro 1.5.3之前的版本
Spring 框架中只使用 Shiro 鑒權
四、漏洞復現
4.1 環境搭建
4.2 環境部署
將springboot-shiro項目導入IntelliJ IDEA,配置 Maven:
添加本地鏡像:
注意:settings.xml的縮進問題,否則生成war包時會報錯。
更改 IDEA 中的 Maven home directory 和 User settings file 配置:
生成 war 包:
將打包好的 war 包部署於 Tomcat 。該漏洞成功利用存在下面兩個條件
漏洞環境的權限配置如下,其中 /admin 下的路由需要登錄才能訪問:
4.3 漏洞復現
1、直接訪問 http://192.168.31.68:8080/shiro/admin/page
會返回 302 跳轉要求登錄。
2、直接訪問/;/shiro/admin/page , 就能直接繞過 Shiro 權限驗證,訪問到/admin路由中的信息。
五、漏洞修復
Shiro 1.5.3修改了URL獲取的邏輯,不單獨處理context-path,具體代碼如下所示:org.apache.shiro.web.util.WebUtils#getPathWithinApplication
因此就無法再通過構造context-path的方式來進行繞過了。
三、影響版本
Apache Shiro 1.5.3之前的版本
Spring 框架中只使用 Shiro 鑒權
四、漏洞復現
4.1 環境搭建
- 源碼下載:git clone https://github.com/l3yx/springboot-shiro.git
- IntelliJ IDEA
- maven
- Java環境
- Tomcat環境
將springboot-shiro項目導入IntelliJ IDEA,配置 Maven:
/Users/Tide/Library/apache-maven-3.6.3/conf/settings.xml(本地演示環境:Mac OS)
添加本地鏡像:
<mirrors>
<mirror>
<id>alimaven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven.</name>
<url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
</mirror>
<mirror>
<id>repo1</id>
<mirrorOf>central</mirrorOf>
<name>HHuman Readable Name for this Mirror.</name>
<url>http://repo1.maven.org/maven2/</url>
</mirror>
<mirror>
<id>repo2</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://repo2.maven.org/maven2/</url>
</mirror>
</mirrors>
注意:settings.xml的縮進問題,否則生成war包時會報錯。
更改 IDEA 中的 Maven home directory 和 User settings file 配置:


生成 war 包:




將打包好的 war 包部署於 Tomcat 。該漏洞成功利用存在下面兩個條件
- 應用不能部署在根目錄,也就是需要 context-path , server.servlet.context-path=/shiro,如果為根目錄則context-path為空,就會被 CVE-2020-1957 的 patch 將 URL 格式化,值得注意的是若 Shiro 版本小於 1.5.2 的話那么該條件就不需要。
- Spring 控制器中沒有另外的權限校驗代碼




漏洞環境的權限配置如下,其中 /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";
}
4.3 漏洞復現
1、直接訪問 http://192.168.31.68:8080/shiro/admin/page


會返回 302 跳轉要求登錄。
2、直接訪問/;/shiro/admin/page , 就能直接繞過 Shiro 權限驗證,訪問到/admin路由中的信息。




五、漏洞修復
Shiro 1.5.3修改了URL獲取的邏輯,不單獨處理context-path,具體代碼如下所示:org.apache.shiro.web.util.WebUtils#getPathWithinApplication


因此就無法再通過構造context-path的方式來進行繞過了。