您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
# Apache Shiro 权限绕过漏洞CVE-2020-13933的示例分析
## 漏洞概述
Apache Shiro是一个强大且易用的Java安全框架,提供身份验证、授权、加密和会话管理等功能。2020年披露的CVE-2020-13933是一个权限绕过漏洞,影响Shiro 1.6.0及以下版本。该漏洞源于URL路径处理时的标准化差异,攻击者可构造特殊路径绕过权限控制。
## 漏洞原理
### 关键问题:路径标准化不一致
Shiro使用`PathMatchingFilterChainResolver`进行URL路径匹配时,与Web容器(如Tomcat)的路径处理存在差异:
1. **Shiro处理逻辑**:直接对原始URI进行权限规则匹配
2. **容器处理逻辑**:先对URI进行标准化(如`/./`、`/../`处理)
当请求路径包含标准化序列时(如`/admin/./`),Shiro可能错误地认为该路径不受保护,而容器最终仍会路由到受保护路径。
### 技术细节
```java
// Shiro的路径匹配逻辑(简化版)
public class PathMatchingFilterChainResolver {
public FilterChain getChain(ServletRequest request, ServletResponse response) {
String requestURI = getPathWithinApplication(request); // 未充分标准化
for (String pathPattern : filterChainManager.getChainNames()) {
if (pathMatches(pathPattern, requestURI)) { // 直接匹配
return filterChainManager.getChain(pathPattern);
}
}
return null;
}
}
@Bean
public ShiroFilterFactoryBean shiroFilter() {
ShiroFilterFactoryBean factory = new ShiroFilterFactoryBean();
Map<String, String> filterChain = new LinkedHashMap<>();
filterChain.put("/admin/**", "authc"); // 需要认证
filterChain.put("/**", "anon"); // 允许匿名
factory.setFilterChainDefinitionMap(filterChain);
return factory;
}
/admin/dashboard
→ 302跳转到登录页(符合预期)/public/page
→ 正常访问(符合预期)
GET /admin/./dashboard HTTP/1.1
Host: vulnerable-app.com
/admin/./dashboard
(不匹配/admin/**
规则)/admin/dashboard
1. PathMatchingFilterChainResolver#getChain()
- 获取原始URI: /admin/./dashboard
2. PathMatchingFilter#preHandle()
- 匹配失败(因配置规则为`/admin/**`)
3. Tomcat的RequestUtil#normalize()
- 标准化路径为/admin/dashboard
4. 最终路由到受保护的Controller
官方修复方案(Shiro 1.7.0):
// 新增路径标准化处理
public class PathMatchingFilterChainResolver {
private String getPathWithinApplication(ServletRequest request) {
String requestURI = WebUtils.getRequestUri(request);
return normalizePath(requestURI); // 新增标准化步骤
}
private String normalizePath(String path) {
return PathUtils.normalize(path);
}
}
// 自定义Filter强制标准化
public class NormalizedPathFilter extends AccessControlFilter {
protected boolean isAccessAllowed(ServletRequest request,
ServletResponse response, Object mappedValue) {
String path = getPathWithinApplication(request);
String normalized = PathUtils.normalize(path);
request.setAttribute("normalized_path", normalized);
return true;
}
}
@RequiresRoles
)CVE-2020-13933暴露了安全框架与Web容器交互时的常见问题。通过此漏洞分析,我们得到以下启示: 1. 路径处理必须与容器保持严格一致 2. 安全防护需要多层防御(Defense in Depth) 3. 开源组件需持续跟踪安全更新
漏洞影响评级: - CVSS 3.1评分:7.5(High) - 影响范围:所有使用Shiro权限控制且未规范路径处理的Web应用
建议所有Shiro用户立即检查版本并及时升级,避免因此类”看似简单”的路径处理问题导致系统权限体系被突破。 “`
注:实际字数约1250字(含代码示例),可根据需要调整技术细节的深度或补充更多攻击变种示例。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。