Apache Shiro权限绕过漏洞 (CVE

访客4年前黑客工具386

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;设置“https://www.freebuf.com/articles/network/admin/*”路径需要认证访问,成功则显示“hello, admin page”,具体配置见源代码 (https://github.com/HYWZ36/HYWZ36-CVE-2020-11989-code/tree/main/springboot-shiro-master0)。

1.4.2 目标

绕过认证访问“https://www.freebuf.com/articles/network/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(';');

1605173147_5facff9b86afefe5fb684.png!small?1605173147735

随后,在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); 【="http://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;设置“https://www.freebuf.com/articles/network/admin/*”路径需要认证访问,成功则显示“hello,admin”,具体配置见源代码 (https://github.com/HYWZ36/HYWZ36-CVE-2020-11989-code/tree/main/springboot-shiro-master)。

1.5.2 目标

绕过认证访问“https://www.freebuf.com/articles/network/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 '+':

*** .append(' ');

i++;

needToChange=true;

break;

case '%':…………

return (needToChange? *** .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”安全缺陷。

1605173228_5facffec7f0805df89b68.png!small?1605173228752

1.7 docker复现

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

cat https://www.freebuf.com/articles/network/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】,成功访问表明复现成功,如下图。

1605173275_5fad001b417761e3c6a1b.png!small?1605173275543

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

1605173283_5fad00235d0519c5a8ac8.png!small?1605173283576

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

相关文章

什么消费品能快速回本(跟着大神来学习)

什么消费品能快速回本(跟着大神来学习)

快速消费品行业订货的特点是流通快,订货频次高,分销层级多。在竞争日益激烈的情况下,如何快人一步,在订货效率上面入手,节省成本,提升利润,成为快速消费品行业一个重要的课题。(文末有福利,可免费开通账户,...

微伴游-抵达个人工作室量大从优

微伴游-抵达个人工作室量大从优 伴游叙述:近期有很多盆友在商务接待模特预约网后台管理留言板留言,想掌握有关微伴游信息内容。因此我根据百度搜索、知乎问答、百度文库等方式,汇总了下列有关微伴游的所有内容。...

女子买关键词上当受骗103万 女子被忽悠买关键词等升值被骗103万

  女人买关键字受骗上当103万 女子被坑骗买关键字等增值上当受骗103万。近日,有做买卖的某女性坚信项目投资互联网关键字能够赚钱发财,因此花了100来万去项目投资,想不到結果是个骗术,下边大家来掌握...

百度网站优化公司,南京网站优化公司南京百度

南京网站优化公司南京百度 应该是 奈何把网站的要害词优化到百度底层 应该是百度首页第一把。假如是底层,直接可以把网站标题改了可能删除网站都可以。 1.在优化一个网站之前,先阐明一下你的网站关于在这行业...

俄敦促外国外交人员不把玩核桃应就纳瓦利内一案向法庭

  中新网莫斯科2月2日电 (记者 王修君)2日俄罗斯总统新闻秘书佩斯科夫在莫斯科表示,外国外交人员不应就纳瓦利内一案向俄法庭施压。   2日莫斯科法院以巡回模式开庭审理用监禁实刑替代俄反对派人士纳...

失意是什么意思(人生最大的失意是什么呢)

失意是什么意思(人生最大的失意是什么呢)

周末在KTV小聚,酒兴正浓之际,朋友放了一首迟志强的《铁窗泪》,借着酒精催开的情绪,大家不由自主的跟着乱哼哼。这首当年传红大江南北的歌曲曾让很多人痴迷过一阵,特别是开场那两句告白更是让许多人认可:人生...