taibeihacker
Moderator
Shiro 权限绕过漏洞复现(CVE-2020-11989)
影响范围
Apache Shiro 1.5.3Spring 框架中只使用Shiro 鑑權
环境搭建
1git clone https://github.com/l3yx/springboot-shiro.git
將項目導入IDEA 中,本地演示環境為Mac OS,配置Maven:
/usr/local/Cellar/maven/3.6.3_1/libexec/conf/settings.xml
添加本地鏡像:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
mirror
idalimaven/id
mirrorOfcentral/mirrorOf
namealiyun maven/name
urlhttp://maven.aliyun.com/nexus/content/repositories/central//url
/mirror
!-- 下面的兩個中央倉庫都是maven 軟件內置的,服務於整個互聯網,由Maven 團隊自己維護,裡面存儲了非常全的jar 包,包含了世界上大部分流行的開源項目構件--
!-- 中央倉庫1 --
mirror
idrepo1/id
mirrorOfcentral/mirrorOf
nameHuman Readable Name for this Mirror./name
urlhttp://repo1.maven.org/maven2//url
/mirror
!-- 中央倉庫2 --
mirror
idrepo2/id
mirrorOfcentral/mirrorOf
nameHuman Readable Name for this Mirror./name
urlhttp://repo2.maven.org/maven2//url
/mirror

更改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 下的路由需要登錄才能訪問:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
@Bean
ShiroFilterFactoryBean 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';
}
漏洞复现
如果直接訪問/shiro/admin/page ,會返回302 跳轉要求登錄
直接訪問/;/test/admin/page , 就能直接繞過Shiro 權限驗證,訪問到/admin 路由中的信息
