0x00 Vmware vcenter信息
vSphere
是VMware
推出的虛擬化平台套件,包含ESXi
、vCenter Server
等一系列的軟件。其中vCenter Server
為 ESXi
的控制中心,可從單一控制點統一管理數據中心的所有vSphere
主機和虛擬機,使得IT
管理員能夠提高控制能力,簡化入場任務,並降低IT
環境的管理復雜性與成本。
vSphere Client(HTML5)
在vCenter Server
插件中存在一個遠程執行代碼漏洞。未授權的攻擊者可以通過開放443
端口的服務器向vCenter Server
發送精心構造的請求,從而在服務器上寫入webshell
,最終造成遠程任意代碼執行。
fofa查詢
語法:
title="+ ID_VC_Welcome +"
app=”vmware-ESX”||app=”vmware-VirtualCenter”||app=”vmware-vCenter”
0x01 影響版本
- 7.0 U1c 之前的 7.0 版本
- 6.7 U3l 之前的 6.7 版本
- 6.5 U3n 之前的 6.5 版本
0x02 代碼分析
vCenter Server
的vROPS
插件的API
未經過鑒權,存在一些敏感接口。其中 uploadova
接口存在一個上傳 OVA 文件的功能:
@RequestMapping(
value = {"/uploadova"},
method = {RequestMethod.POST}
)
public void uploadOvaFile(@RequestParam(value = "uploadFile",required = true) CommonsMultipartFile uploadFile, HttpServletResponse response) throws Exception {
logger.info("Entering uploadOvaFile api");
int code = uploadFile.isEmpty() ? 400 : 200;
PrintWriter wr = null;
try {
if (code != 200) {
response.sendError(code, "Arguments Missing");
return;
}
wr = response.getWriter();
} catch (IOException var14) {
var14.printStackTrace();
logger.info("upload Ova Controller Ended With Error");
}
response.setStatus(code);
String returnStatus = "SUCCESS";
if (!uploadFile.isEmpty()) {
try {
logger.info("Downloading OVA file has been started");
logger.info("Size of the file received : " + uploadFile.getSize());
InputStream inputStream = uploadFile.getInputStream();
File dir = new File("/tmp/unicorn_ova_dir");
if (!dir.exists()) {
dir.mkdirs();
} else {
String[] entries = dir.list();
String[] var9 = entries;
int var10 = entries.length;
for(int var11 = 0; var11 < var10; ++var11) {
String entry = var9[var11];
File currentFile = new File(dir.getPath(), entry);
currentFile.delete();
}
logger.info("Successfully cleaned : /tmp/unicorn_ova_dir");
}
TarArchiveInputStream in = new TarArchiveInputStream(inputStream);
TarArchiveEntry entry = in.getNextTarEntry();
ArrayList result = new ArrayList();
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();
}
OutputStream out = new FileOutputStream(curfile);
IOUtils.copy(in, out);
out.close();
result.add(entry.getName());
entry = in.getNextTarEntry();
}
}
in.close();
logger.info("Successfully deployed File at Location :/tmp/unicorn_ova_dir");
} catch (Exception var15) {
logger.error("Unable to upload OVA file :" + var15);
returnStatus = "FAILED";
}
}
wr.write(returnStatus);
wr.flush();
wr.close();
}
代碼邏輯是將TAR
文件解壓后上傳到 /tmp/unicorn_ova_dir
目錄。注意到如下代碼:
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
的文件名與 /tmp/unicorn_ova_dir
拼接並寫入文件。如果文件名內存在 ../
即可實現目錄遍歷。
0x03 漏洞復現
利用代碼(Sp4ce ):https://github.com/NS-Sp4ce/CVE-2021-21972
0x04 修復建議
- vCenter Server7.0版本升級到7.0.U1c
- vCenter Server6.7版本升級到6.7.U3l
- vCenter Server6.5版本升級到6.5 U3n