Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vcenter offline mdb extract #16571

Merged

Conversation

npm-cesium137-io
Copy link
Contributor

Now that PR #16484 has landed (yay!) - this module might actually be useful. Not sure if this is overkill but it is designed to extract the vmdir / vmafd certificates from an offline copy of the service database (i.e. a vCenter backup) - very helpful now that vcenter_forge_saml_token is available. Right now it will only pull the IdP keypair, the VMCA root cert, and anything from vmafd that has a private key associated, but that is plenty. Very WYSIWYG.

Add new aux module vcenter_offline_mdb_extract for extracting IdP
credentials, certificates and keys from a vCenter backup file.

Added module documentation.
@h00die
Copy link
Contributor

h00die commented May 13, 2022

this would do well in a library like the juniper/cisco/arista offline config things, that way we can have some specs and such

@bwatters-r7
Copy link
Contributor

I mean.... this would have been totally useful landing that last PR.... 😆

@bwatters-r7
Copy link
Contributor

I used the same .mdb file I used to pull the certs from for #16484?

msf6 auxiliary(admin/vmware/vcenter_offline_mdb_extract) > show options

Module options (auxiliary/admin/vmware/vcenter_offline_mdb_extract):

   Name       Current Setting       Required  Description
   ----       ---------------       --------  -----------
   VC_IP                            no        (Optional) IPv4 address to attach to loot
   VMAFD_DB                         no        Path to the vmafd afd.db file
   VMDIR_MDB  /home/tmoose/data.md  no        Path to the vmdir data.mdb file


Auxiliary action:

   Name  Description
   ----  -----------
   Dump  Dump secrets from vCenter files


msf6 auxiliary(admin/vmware/vcenter_offline_mdb_extract) > run

[*] Extracting vmwSTSTenantCredential from /home/tmoose/data.md ...
[-] Auxiliary aborted due to failure: no-target: Failure during extract of PKCS#1 RSA private key
[*] Auxiliary module execution completed

@npm-cesium137-io
Copy link
Contributor Author

npm-cesium137-io commented May 17, 2022 via email

@bwatters-r7
Copy link
Contributor

No luck

msf6 payload(linux/aarch64/meterpreter/reverse_tcp) > use auxiliary/admin/vmware/vcenter_offline_mdb_extract 
msf6 auxiliary(admin/vmware/vcenter_offline_mdb_extract) > set VMDIR_MDB /home/tmoose/data.md
VMDIR_MDB => /home/tmoose/data.md
msf6 auxiliary(admin/vmware/vcenter_offline_mdb_extract) > set verbose true
verbose => true
msf6 auxiliary(admin/vmware/vcenter_offline_mdb_extract) > run

[*] Extracting vmwSTSTenantCredential from /home/tmoose/data.md ...
[-] Auxiliary aborted due to failure: no-target: Failure during extract of PKCS#1 RSA private key
[*] Auxiliary module execution completed
msf6 auxiliary(admin/vmware/vcenter_offline_mdb_extract) > set MDB_CHUNK_SIZE 8192
MDB_CHUNK_SIZE => 8192
msf6 auxiliary(admin/vmware/vcenter_offline_mdb_extract) > run

[*] Extracting vmwSTSTenantCredential from /home/tmoose/data.md ...
[-] Auxiliary aborted due to failure: no-target: Failure during extract of PKCS#1 RSA private key
[*] Auxiliary module execution completed
msf6 auxiliary(admin/vmware/vcenter_offline_mdb_extract) > set MDB_CHUNK_SIZE 16384
MDB_CHUNK_SIZE => 16384
msf6 auxiliary(admin/vmware/vcenter_offline_mdb_extract) > run

[*] Extracting vmwSTSTenantCredential from /home/tmoose/data.md ...
[-] Auxiliary aborted due to failure: no-target: Failure during extract of PKCS#1 RSA private key
[*] Auxiliary module execution completed
msf6 auxiliary(admin/vmware/vcenter_offline_mdb_extract) > 

I'm happy to provide the file to you if you'd like, as this is a mostly-offline test system.

@npm-cesium137-io
Copy link
Contributor Author

npm-cesium137-io commented May 18, 2022 via email

@bwatters-r7
Copy link
Contributor

Could you email msfdev[at]metasploit.com and I'll send it back to you?

@bwatters-r7
Copy link
Contributor

Sorry I was a bit slow on this, but I figure we should go back to the PR for discussions.
I sent the file, but it seems to work on his setup. THere was a question about SSL versions, so:

tmoose@ubuntu:~$ openssl version
OpenSSL 1.1.1f  31 Mar 2020
[ruby-2.7.2]tmoose@ubuntu:~$ sudo apt-get update
[sudo] password for tmoose: 
Hit:1 http://downloads.metasploit.com/data/releases/metasploit-framework/apt lucid InRelease
Hit:2 http://us.archive.ubuntu.com/ubuntu focal InRelease                                
Hit:3 http://us.archive.ubuntu.com/ubuntu focal-updates InRelease                        
Hit:4 http://us.archive.ubuntu.com/ubuntu focal-backports InRelease        
Hit:5 http://security.ubuntu.com/ubuntu focal-security InRelease
Reading package lists... Done
[ruby-2.7.2]tmoose@ubuntu:~$ sudo apt-get upgrade openssl
Reading package lists... Done
Building dependency tree       
Reading state information... Done
openssl is already the newest version (1.1.1f-1ubuntu2.13).

This was the version that I used before, but to verify:

msf6 > use auxiliary/admin/vmware/vcenter_offline_mdb_extract 
msf6 auxiliary(admin/vmware/vcenter_offline_mdb_extract) > set VMDIR_MDB /home/tmoose/data.md
VMDIR_MDB => /home/tmoose/data.md
msf6 auxiliary(admin/vmware/vcenter_offline_mdb_extract) > set verbose true
verbose => true
msf6 auxiliary(admin/vmware/vcenter_offline_mdb_extract) > run

[*] Extracting vmwSTSTenantCredential from /home/tmoose/data.md ...
[-] Auxiliary aborted due to failure: no-target: Failure during extract of PKCS#1 RSA private key
[*] Auxiliary module execution completed

If I remove the rescue and let the error come through OpenSSL:

msf6 auxiliary(admin/vmware/vcenter_offline_mdb_extract) > run

[*] Extracting vmwSTSTenantCredential from /home/tmoose/data.md ...
[-] Auxiliary failed: OpenSSL::PKey::RSAError Neither PUB key nor PRIV key: nested asn1 error
[-] Call stack:
[-]   /home/tmoose/rapid7/metasploit-framework/modules/auxiliary/admin/vmware/vcenter_offline_mdb_extract.rb:179:in `initialize'
[-]   /home/tmoose/rapid7/metasploit-framework/modules/auxiliary/admin/vmware/vcenter_offline_mdb_extract.rb:179:in `new'
[-]   /home/tmoose/rapid7/metasploit-framework/modules/auxiliary/admin/vmware/vcenter_offline_mdb_extract.rb:179:in `get_sts_key'
[-]   /home/tmoose/rapid7/metasploit-framework/modules/auxiliary/admin/vmware/vcenter_offline_mdb_extract.rb:128:in `extract_idp_cert'
[-]   /home/tmoose/rapid7/metasploit-framework/modules/auxiliary/admin/vmware/vcenter_offline_mdb_extract.rb:82:in `run'
[*] Auxiliary module execution completed

Added verbose output to the RSA and x509 extraction functions for
troubleshooting.

Changed error handling to just print an error message instead of
throwing an exception temporariliy.
@npm-cesium137-io
Copy link
Contributor Author

Interesting. Looks like Ruby's OpenSSL interface is having trouble parsing the DER/ASN1 when you run it. The only thing noteworthy (potentially) is that you're on Ruby 2.7.2 and I'm on Ruby 3.0.3 but still have no clear picture what is going on. I just pushed a commit that adds some verbose output to the key functions, could you please re-attempt your testing with set verbose true and email me the output? You can just post it here too, if you don't mind the private key material potentially being exposed. This should tell me at least what bytes it is trying to turn into a PKCS#1 key, from there it may be possible to pin down the issue.

@bwatters-r7
Copy link
Contributor

The Ruby looks old because I use rvm. When I switch into the metasploit directory, it changes to 3.0.2:

[ruby-2.7.2]tmoose@ubuntu:~/rapid7$ cd metasploit-framework
[ruby-3.0.2@metasploit-framework]((HEAD detached at upstream/pr/16571)) tmoose@ubuntu:~/rapid7/metasploit-framework$ ./msfconsole

That said, the latest update seems to work, now 🎉 ?

msf6 > use auxiliary/admin/vmware/vcenter_offline_mdb_extract 
msf6 auxiliary(admin/vmware/vcenter_offline_mdb_extract) > set VMDIR_MDB /home/tmoose/data.md
VMDIR_MDB => /home/tmoose/data.md
msf6 auxiliary(admin/vmware/vcenter_offline_mdb_extract) > set verbose true
verbose => true
msf6 auxiliary(admin/vmware/vcenter_offline_mdb_extract) > run

[*] Extracting vmwSTSTenantCredential from /home/tmoose/data.md ...
[*] key_pem:
-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC4g1ZtEqmblhBD
gjuNuS+LU6kGrkum0TMqu7w8bX2vGCA1a4DgDpxlC9dK7EJTXbw1Rl/60cd+fh7o
1WaG/iNAAwETqr4Fw9Vc8RS0ywdZZ84Hm6LV1ZrfhxeS2/L63cuj7QRB5pFxy/ha
btJ51dPofHyhYsjC2e9+k+DyQWj5yjAZbCiSJFLrPHmUdMB5w/Br6gqNVGgWI+pN
uyNww9d0Rc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----END CERTIFICATE-----
[+] SSO_STS_IDP key: /home/tmoose/.msf4/loot/20220526110014_default_127.0.0.1_idp_542734.key
[+] SSO_STS_IDP cert: /home/tmoose/.msf4/loot/20220526110014_default_127.0.0.1_idp_011009.pem
[+] VMCA_ROOT cert: /home/tmoose/.msf4/loot/20220526110014_default_127.0.0.1_vmca_736465.pem
[*] Auxiliary module execution completed
msf6 auxiliary(admin/vmware/vcenter_offline_mdb_extract) > set verbose false
verbose => false
msf6 auxiliary(admin/vmware/vcenter_offline_mdb_extract) > run

[*] Extracting vmwSTSTenantCredential from /home/tmoose/data.md ...
[+] SSO_STS_IDP key: /home/tmoose/.msf4/loot/20220526110054_default_127.0.0.1_idp_128462.key
[+] SSO_STS_IDP cert: /home/tmoose/.msf4/loot/20220526110054_default_127.0.0.1_idp_369241.pem
[+] VMCA_ROOT cert: /home/tmoose/.msf4/loot/20220526110054_default_127.0.0.1_vmca_818909.pem
[*] Auxiliary module execution completed

@npm-cesium137-io
Copy link
Contributor Author

The only change was converting the key data to Base64/PEM before passing it to OpenSSL::PKey::RSA.new() - so I guess we can say that method insists on PEM-formatted input in your case. I am going to try running on a few different distros / builds to see if I can pin down the root cause but for now I guess we resolved this?

@bwatters-r7 bwatters-r7 self-assigned this Jun 6, 2022
@bwatters-r7
Copy link
Contributor

I apologize; I guess I never assigned myself to this, so I completely forgot about it. I assigned myself to it so I won't get too distracted again. Were you able to verify the root cause of the error? I'm thinking that we've documented the occurrence here, and seemingly found a fix to the discovered error, so I'm game to go ahead with this PR and land it if you are OK with that. We can keep an eye open and see if anyone else runs into this issue again.

@bwatters-r7
Copy link
Contributor

Pinging @npm-cesium137-io; are we OK landing this?

@npm-cesium137-io
Copy link
Contributor Author

@bwatters-r7 I should think it should be ready to go, so long as it functions. I was able to reproduce the issue, Ruby 2.x OpenSSL module seems not to like DER format, 3.x appears to be fine with either. My rig is on 3.x so I didn't notice this. Looking at some of my other stuff uncovered the same bug in modules that do DER/PEM vs. just DER so def. in the future I'll just make sure to explicitly convert to PEM just to be backwards compatible. I'm good w/ landing this. Thanks!

@bwatters-r7 bwatters-r7 merged commit f6bd8fd into rapid7:master Jun 13, 2022
@bwatters-r7
Copy link
Contributor

Release Notes

This module extracts the vmdir / vmafd certificates from an offline copy of the service database (i.e. a vCenter backup). Right now it will pull the IdP keypair, the VMCA root cert, and anything from vmafd that has a private key associated.

@bwatters-r7 bwatters-r7 added module rn-modules release notes for new or majorly enhanced modules labels Jun 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module rn-modules release notes for new or majorly enhanced modules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants