漏洞介绍

CVE-2020-1957 是 Apache Shiro 框架中存在的一处严重漏洞。Apache Shiro 是一个强大且易用的 Java 安全框架,用于处理身份验证和授权等安全相关任务。然而,该漏洞使得攻击者能够在受保护的系统上绕过身份验证和授权机制,从而执行未经授权的操作。

漏洞范围

Shiro < 1.5.2
SpringBoot 的版本 < 2.3

漏洞靶场

使用vulhub的靶场

使用环境为Shiro 1.5.1

vulhub-master/shiro/CVE-2020-1957

1
docker-compose up -d

漏洞原理

漏洞初始成因可以定位到 PathMatchingFilterChainResolver的getChain函数下,该函数作用根据URL路径匹配中配置的url路径表达式来匹配输入的URL,判断是否匹配拦截器,匹配成功将会返回响应的拦截器执行链,让ShiroFither执行权限操作的。

其对于URL路径表达式和输入URL的匹配主要通过pathMathches函数进行匹配。

6.png

src/main/java/org/apache/shiro/web/filter/mgt/PathMatchingFilterChainResolver.java#L97-L133,

pathMatches函数其最终会调用shiro.util.AntPathMatcher类中doMatch的对于ant格式的pathPattern和requestURI进行匹配。

1
2
3
4
5
//pathMatches:135, PathMatchingFilterChainResolver (org.apache.shiro.web.filter.mgt)
protected boolean pathMatches(String pattern, String path) {
PatternMatcher pathMatcher = this.getPathMatcher();
return pathMatcher.matches(pattern, path);
}

src/main/java/org/apache/shiro/web/filter/mgt/PathMatchingFilterChainResolver.java#L150-L153

doMatch:109, AntPathMatcher (org.apache.shiro.util),当Shiro 的Ant格式的pathPattern 中的的*通配符是不支持匹配路径的,所以/hello/*不能成功匹配/hello/1/,也就不会触发authc拦截器进行权限拦截。从而成功绕过了Shiro拦截器,而后再进入到spring拦截器中,/hello/1/与/hello/1能获取到相同的资源。

7.png

src/main/java/org/apache/shiro/util/AntPathMatcher.java#L108-L230

漏洞复现

访问http://127.0.0.1:8080/进入靶场页面

image-20250301163042970

访问http://127.0.0.1:8080/admin/会自动跳转到登录界面http://127.0.0.1:8080/login.html

image-20250301163329391

访问http://127.0.0.1:8080/xxx/..;/admin/

image-20250301162851378

成功绕过登录验证进入后台

参考

https://www.cnblogs.com/dhan/p/18423713

https://blog.csdn.net/weixin_68408599/article/details/131208075

Shiro权限绕过漏洞分析(CVE-2020-1957) - FreeBuf网络安全行业门户