vSphere Development Guide 6 - vCenter SAML Certificates

Onedaysec
3 min read
0 views
vSphere Development Guide 6 - vCenter SAML Certificates — One Day Sec default thumbnail

0x00 Preface

---

A recent exploitation technique I learned: Using administrator privileges on vCenter to extract the IdP certificate from /storage/db/vmware-vmdir/data.mdb, create a SAML request for an administrator user, and finally authenticate using the vCenter server to obtain a valid administrator cookie.

Intuitive understanding: From local administrator privileges on vCenter to administrator access to the VCSA management panel.

Learning materials:

https://www.horizon3.ai/compromising-vcenter-via-saml-certificates/

https://github.com/horizon3ai/vcenter_saml_login

This article will improve the code based on the learning materials, enhance its versatility, and provide defense recommendations in conjunction with exploitation ideas.

0x01 Introduction

---

This article will cover the following:

  • Method reproduction
  • Script optimization
  • Exploitation ideas
  • Defense Recommendations

0x02 Method Reproduction

---

Testing on Kali System

Install Openssl:

apt install python3-openssl

1. Obtain Database File from vCenter

Path: /storage/db/vmware-vmdir/data.mdb

vCenter Administrator Privileges Required

2. Run the Script

Download URL:

https://github.com/horizon3ai/vcenter_saml_login/blob/main/vcenter_saml_login.py

Command Parameter Example:

python3 ./vcenter_saml_login.py -t 192.168.1.1 -p data.mdb

Command Line Return Result:

JSESSIONID=XX533CDFA344DE842517C943A1AC7611

3. Log in to the VCSA management panel

Access https://192.168.1.1/ui

Set Cookie: JSESSIONID=XX533CDFA344DE842517C943A1AC7611

Successfully logged into the management panel as administrator

0x03 Script Optimization

---

Typically, the size of data.mdb is at least 20MB

To reduce interaction traffic, choose to modify vcenter_saml_login.py to be usable directly under vCenter

Note:

Python is installed by default on vCenter

Specifically, the following issues need to be considered when modifying the script:

1. Remove the reference to the third-party package bitstring

The approach I adopted is to streamline the content of the third-party package bitstring and directly insert it into the Python script

2. Avoid using f-string formatting

Python 3.6 introduced a new f-string formatting feature

vCenter 6.7 uses Python 3.5.6, which does not support the 'f' prefix for formatted string literals

The approach I adopted was to use the format method for string formatting

For example:

cn = stream.read(f'bytes:{cn_len}').decode()

Replaced with:

cn = stream.read('bytes:{}'.format(cn_len)).decode()

The complete code has been uploaded to GitHub at the following address:

An open-source project

vCenter_ExtraCertFromMdb.py can be uploaded to vCenter and executed directly. After execution, the following four important parameters will be obtained:

  • domain, displayed in the command line
  • idp_cert, saved as idp_cert.txt
  • trusted_cert_1, saved as trusted_cert_1.txt
  • trusted_cert_2, saved as trusted_cert_2.txt

Next, a SAML request can be created for the administrator user on any host, using the vCenter server for authentication to obtain a valid administrator cookie. The complete code has been uploaded to GitHub at the following address:

An open-source project

Parameter description is as follows:

  • target: URL of the VCSA management panel
  • hostname: Corresponds to the CN in the certificate Subject attribute of the VCSA management panel
  • domain: Can be obtained from data.mdb using vCenter_ExtraCertFromMdb.py
  • idp_cert path: Can be obtained from data.mdb using vCenter_ExtraCertFromMdb.py
  • trusted_cert_1 path: Can be obtained from data.mdb using vCenter_ExtraCertFromMdb.py
  • trusted_cert_2 path: Can be obtained from data.mdb using vCenter_ExtraCertFromMdb.py

0x04 Exploitation Approach

---

1. From vCenter local administrator privileges to VCSA management panel administrator access

Prerequisite: Gained vCenter local administrator privileges through a vulnerability

Exploitation effect:

Obtain administrator access to the VCSA management panel, enabling interaction with virtual machines manageable by vCenter

Note:

At this point, administrator users can also be added via the LDAP database using the method described in 'vSphere Development Guide 5 - LDAP', enabling interaction with virtual machines manageable by vCenter.

2. Obtain data.mdb from vCenter backup files

Prerequisite: Need to obtain the correct data.mdb file

Exploitation effect:

Gain administrator access to the VCSA management panel, enabling interaction with virtual machines manageable by vCenter

0x05 Defense Recommendations

---

1. Apply patches to prevent attackers from obtaining vCenter local administrator privileges

2. Avoid leakage of vCenter backup files in use

0x06 Summary

---

This article introduces optimization ideas for vcenter_saml_login, enhances its generality, and provides defense recommendations based on exploitation approaches.

Related Questions & Answers

What are the main defense recommendations against this SAML certificate attack?

The primary defenses are applying patches to prevent attackers from obtaining vCenter local administrator privileges, and securing vCenter backup files to avoid leakage. By blocking access to the `data.mdb` file or the local admin account, the attack chain is effectively broken.

Besides gaining local admin on vCenter, what other path can lead to obtaining the data.mdb file?

An attacker can acquire the `data.mdb` file from vCenter backup files. If backups are leaked, the same technique can extract the IdP certificate, create a SAML request, and gain admin access to the VCSA management panel. This enables interaction with managed virtual machines and can be combined with methods like the one described in [vSphere Development Guide 5 - LDAP](/news/vsphere-development-guide-5-ldap) for adding administrator users.

What modifications were needed to make vcenter_saml_login.py run directly on vCenter?

The script had to remove the dependency on the third-party `bitstring` package by inlining its functionality, and replace f-string formatting with the `.format()` method because vCenter 6.7 uses Python 3.5.6, which doesn't support f-strings. This allows the script to be uploaded and executed directly on a vCenter server without additional dependencies.

How can an attacker with vCenter local admin privileges gain access to the VCSA management panel?

The attacker extracts the IdP certificate from `/storage/db/vmware-vmdir/data.mdb`, creates a SAML request for an administrator user, and authenticates against vCenter to obtain a valid JSESSIONID cookie. This cookie grants administrator access to the VCSA management panel, enabling control over virtual machines. For full details, see [vSphere Development Guide 6 - vCenter SAML Certificates](/news/vsphere-development-guide-6-vcenter-saml-certificates).

What key parameters are extracted by the vCenter_ExtraCertFromMdb.py script and how are they used in SAML authentication?

The script extracts the domain, idp_cert, trusted_cert_1, and trusted_cert_2. These parameters are used to forge a SAML request for an administrator user: the domain and certificates are employed by the SAML login tool (vcenter_saml_login.py) to authenticate against the vCenter server and obtain an administrator JSESSIONID cookie. --- **Related reading:** - [vSphere Development Guide 6 - vCenter SAML Certificates](/news/vsphere-development-guide-6-vcenter-saml-certificates) — original article - [Covenant Utilization Analysis](/news/covenant-utilization-analysis) - [ADAudit Plus Exploitation Analysis — Data Encryption Analysis](/news/adaudit-plus-exploitation-analysis-data-encryption-analysis) - [Domain Penetration - Executing Programs on Remote Systems Using DCOM](/news/domain-penetration-executing-programs-on-remote-systems-using-dcom)

What is one method to obtain the data.mdb file without direct local administrator access to a running vCenter?

An attacker can obtain the data.mdb file from vCenter backup files. If backup files are leaked or accessible, the same extraction technique can be used to retrieve the IdP certificate and SAML token, leading to administrator access to the VCSA management panel. --- **Related reading:** - [vSphere Development Guide 6 - vCenter SAML Certificates](/news/vsphere-development-guide-6-vcenter-saml-certificates) — original article - [Covenant Utilization Analysis](/news/covenant-utilization-analysis) - [ADAudit Plus Exploitation Analysis — Data Encryption Analysis](/news/adaudit-plus-exploitation-analysis-data-encryption-analysis) - [Domain Penetration - Executing Programs on Remote Systems Using DCOM](/news/domain-penetration-executing-programs-on-remote-systems-using-dcom)

What modifications were made to the vcenter_saml_login.py script to run directly on vCenter?

The script was modified to remove reliance on the third-party package bitstring by integrating its functionality directly. Additionally, f-string formatting was replaced with the .format() method because vCenter 6.7 uses Python 3.5.6, which does not support f-strings. The optimized script, vCenter_ExtraCertFromMdb.py, outputs the domain and certificate files needed for SAML authentication. --- **Related reading:** - [vSphere Development Guide 6 - vCenter SAML Certificates](/news/vsphere-development-guide-6-vcenter-saml-certificates) — original article - [Covenant Utilization Analysis](/news/covenant-utilization-analysis) - [ADAudit Plus Exploitation Analysis — Data Encryption Analysis](/news/adaudit-plus-exploitation-analysis-data-encryption-analysis) - [Domain Penetration - Executing Programs on Remote Systems Using DCOM](/news/domain-penetration-executing-programs-on-remote-systems-using-dcom)

How can an attacker with local administrator privileges on vCenter gain access to the VCSA management panel?

An attacker extracts the IdP certificate from the /storage/db/vmware-vmdir/data.mdb file, then creates a SAML request for an administrator user. Using the vCenter server to authenticate, they obtain a valid JSESSIONID cookie, which allows them to log into the VCSA management panel as an administrator. --- **Related reading:** - [vSphere Development Guide 6 - vCenter SAML Certificates](/news/vsphere-development-guide-6-vcenter-saml-certificates) — original article - [Covenant Utilization Analysis](/news/covenant-utilization-analysis) - [ADAudit Plus Exploitation Analysis — Data Encryption Analysis](/news/adaudit-plus-exploitation-analysis-data-encryption-analysis) - [Domain Penetration - Executing Programs on Remote Systems Using DCOM](/news/domain-penetration-executing-programs-on-remote-systems-using-dcom)

How does the attacker use the extracted SAML certificates to gain administrator access?

After extracting the IdP certificate and trusted certificates from data.mdb, the attacker creates a SAML authentication request for an administrator user on any host, then authenticates against the vCenter server. The server returns a valid JSESSIONID cookie that, when set in the browser, provides full administrator access to the VCSA management panel. --- **Related reading:** - [vSphere Development Guide 6 - vCenter SAML Certificates](/news/vsphere-development-guide-6-vcenter-saml-certificates) — original article - [Penetration Techniques - Deleting Single Windows Log Entries](/news/penetration-techniques-deleting-single-windows-log-entries) - [Penetration Technique: Remote Access to Exchange PowerShell](/news/penetration-technique-remote-access-to-exchange-powershell) - [Zimbra SOAP API Development Guide 2](/news/zimbra-soap-api-development-guide-2)

Continue Reading