当前位置:首页 > 网络安全 > 正文内容

Apache Shiro权限绕过漏洞 (CVE

访客4年前 (2021-04-09)网络安全701

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



随后,在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 '+':

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

复现利用方法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

扫描二维码推送至手机访问。

版权声明:本文由黑客接单发布,如需转载请注明出处。

本文链接:https://therlest.com/106671.html

分享给朋友:

“Apache Shiro权限绕过漏洞 (CVE” 的相关文章

立秋是几月几日

说到立秋,大家可能还会觉得比较远,确实算一下也还有将近一个月的时间,大家知道今年的立秋是在什么时候吗,具体的时间是2020年8月7日09:06:03,星期五,农历六月十八,因此在这一天大家就可以吃很多的美食,那么接下来大家就随百思特小编一起了解看看~   立秋是几月...

创业板投资风险揭示书,创业板风险揭示书

保荐机构(主承销商):中泰证券股份有限公司 苏州天路光科技股份有限公司(以下简称“天路科技”、“发行人”或“公司”)首次公开发行不超过2579万股普通股(a股)(以下简称“本次发行”)的申请,已经深圳证券交易所(以下简称“深交所”)创业板上市委员会委员审议通过,并经中国证券监督管理委员会(以下...

【紧急+重要】勒索病毒解决方案!附:MS17-010补丁下载

  滚动更新:2017年5月13日16:57:22   游侠安全网(良心网站,站长先贴上注意事项和解决方法!防止你看本文的时候就被加密了!   1、本次共计是自动化攻击,利用了Windows的MS17-010。但苹果的MacOS用户不用得意,因为在昨晚之前,我这里得到的好几起勒索攻击案例都是针对...

干洗对衣物有害吗

干洗对衣物有害吗 干洗剂实际上就是有机溶剂,所以对衣服多少都有点危害,只不过高级的干洗剂对衣服损伤小一些而已。 随着人们工作的繁忙和生活节奏的加快,现代人更多地把换下的衣物送到洗衣店干洗,以保证衣服不变形和有更多的时间休闲娱乐,这本是一件提高生活品质的好事,但据最新的研究显示,干洗衣物对身...

Webshell安全检测篇(1)-根据流量的检测方法

一、概述 笔者一直在重视webshell的安全剖析,最近就这段时刻的心得体会和咱们做个共享。 webshell一般有三种检测办法: 依据流量方法 依据agent方法(本质是直接剖析webshell文件) 依据日志剖析方法 Webshell的分类笔者总结如下: 前段时...

ems邮政快递查询(ems快递附近网点查询)

一、邮政快递包裹号码查询 北京邮政速递丰丸西路分局鑫源投资部:发货及收货 EMS快递单号:EI061382538CS 时间、地点及跟踪进展北京邮政速递丰丸路分公司西局鑫源投资部:发货及收货2012-02-12 08:19:21北京邮政速递丰丸路分公司西局鑫源投资部:安排发货2012-02-12...

评论列表

笙沉氿雾
3年前 (2022-06-23)

,admin”,具体配置见源代码 (https://github.com/HYWZ36/HYWZ36-CVE-2020-11989-code/tree/main/springboot-shiro-master)。1.5.

竹祭瑰颈
3年前 (2022-06-23)

admin / page”】uri=getSanitizedPath(uri); 【=" / /test/ admin/ page”】return uri;org.springframework.web.uti

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。