vCenter 6.5-7.0 RCE 漏洞分析(CVE-2021-21972)
字数 1478 2025-08-06 08:35:22
VMware vCenter 6.5-7.0 RCE漏洞分析(CVE-2021-21972) 教学文档
0x01 漏洞概述
CVE-2021-21972是VMware vCenter Server中的一个高危远程代码执行漏洞,影响版本包括:
- 7.0 U1c之前的7.0版本
- 6.7 U3l之前的6.7版本
- 6.5 U3n之前的6.5版本
该漏洞允许未经身份验证的攻击者通过vCenter Server的vROPS插件API上传恶意文件,由于服务以System权限运行,可实现任意文件写入,进而导致远程代码执行。
0x02 漏洞原理分析
漏洞位置
漏洞存在于vCenter Server的vROPS插件API中,具体路径为:
/ui/vropspluginui/rest/services/uploadova
漏洞代码分析
API采用Spring框架编写,关键代码如下:
@RequestMapping(
value = {"/uploadova"},
method = {RequestMethod.POST}
)
public void uploadOvaFile(@RequestParam(value = "uploadFile",required = true) CommonsMultipartFile uploadFile, HttpServletResponse response) throws Exception {
// ...省略部分代码...
if (!uploadFile.isEmpty()) {
try {
InputStream inputStream = uploadFile.getInputStream();
File dir = new File("/tmp/unicorn_ova_dir");
// ...创建目录或清空现有目录...
TarArchiveInputStream in = new TarArchiveInputStream(inputStream);
TarArchiveEntry entry = in.getNextTarEntry();
while(entry != null) {
if (entry.isDirectory()) {
entry = in.getNextTarEntry();
} else {
File curfile = new File("/tmp/unicorn_ova_dir", entry.getName());
File parent = curfile.getParentFile();
if (!parent.exists()) {
parent.mkdirs();
}
// ...写入文件...
}
}
}
}
}
漏洞成因
- 未授权访问:该接口未进行身份验证,允许未经身份验证的用户访问
- 路径遍历:在解压上传的TAR文件时,直接将文件名与目标目录拼接,未对文件名中的路径遍历字符(
../)进行过滤 - 高权限运行:vCenter服务以System权限运行,可写入系统任意位置
0x03 漏洞利用方法
利用方式一:上传WebShell
- 构造包含JSP Webshell的TAR文件,文件名使用路径遍历字符,如:
../../usr/lib/vmware-vsphere-ui/server/pickup/shell.jsp - 通过
/ui/vropspluginui/rest/services/uploadova接口上传该TAR文件 - 访问上传的WebShell获取系统权限
利用方式二:SSH公钥注入(Linux环境)
- 生成SSH密钥对
- 构造包含公钥的TAR文件,文件名为:
../../home/vsphere-ui/.ssh/authorized_keys - 上传该TAR文件
- 使用私钥通过SSH登录:
ssh 10.211.55.4 -lvsphere-ui
自动化利用工具
可使用开源工具进行自动化利用:
- https://github.com/NS-Sp4ce/CVE-2021-21972
- https://github.com/conjojo/VMware_vCenter_UNAuthorized_RCE_CVE-2021-21972
0x04 漏洞检测方法
手动检测
检查目标是否存在/ui/vropspluginui/rest/services/uploadova接口,且返回状态码为405(表示接口存在但不允许GET方法)
自动化检测POC
#!/usr/bin/env python
from urllib.parse import urljoin
import requests
def check_vulnerability(url):
try:
vul_url = urljoin(url, "/ui/vropspluginui/rest/services/uploadova")
resp1 = requests.get(url, verify=False, timeout=5)
resp2 = requests.get(vul_url, verify=False, timeout=5)
if '/vsphere-client' in resp1.text and resp2.status_code == 405:
return True, f"{url} 可能存在CVE-2021-21972漏洞"
return False, f"{url} 未发现CVE-2021-21972漏洞"
except Exception as e:
return False, f"检测失败: {str(e)}"
0x05 修复建议
官方修复方案
VMware官方建议关闭受影响的插件,具体操作参考:
https://kb.vmware.com/s/article/82374
临时缓解措施
- 在防火墙或负载均衡设备上限制对
/ui/vropspluginui/路径的访问 - 升级到已修复版本:
- vCenter Server 7.0 U1c或更高版本
- vCenter Server 6.7 U3l或更高版本
- vCenter Server 6.5 U3n或更高版本
0x06 参考链接
- VMware安全公告:https://www.vmware.com/security/advisories/VMSA-2021-0002.html
- 漏洞分析文章:https://mp.weixin.qq.com/s/tg64Hy8KECjYPHt98vBLcQ
- 环境搭建指南:https://www.miensi.com/352.html
- 漏洞利用工具:
- https://github.com/NS-Sp4ce/CVE-2021-21972
- https://github.com/conjojo/VMware_vCenter_UNAuthorized_RCE_CVE-2021-21972