Signing certificates bypassing the certification authority

Time and again in discussions about the security of a certification authority, it comes up that abuse of the certification authority could be contained by its security settings.

However, the fact that the integrity of a certification authority is directly tied to its key material and can therefore also be compromised through it is not obvious at first glance.

One has to think of the certification authority software as a kind of management around the key material. For example, the software provides an online interface for certificate enrollment , takes care of the authentication of the enrollees, the automated execution of signature operations (issuing certificates and certificate revocation lists ) and their logging (certification authority database , audit log , event log ).

However, signature operations require nothing more than the private key of the certification authority. The following example shows how an attacker, given access to the certification authority's private key, can generate and issue certificates without the certification authority software and its security mechanisms noticing.

With such a certificate, it would in the worst case even be possible to take over the Active Directory forest undetected .

The following steps should never be performed in a production environment. The demonstration performed here is not a guide to breaking into computer systems; rather, it is intended to highlight the security risk so that countermeasures can be initiated.

For the demonstration, we use the PSCertificateEnrollment PowerShell module. It can be obtained via the PowerShell Gallery and then loaded.

Please note that the PSCertificateEnrollment module is not a hacking tool, but a completely legitimate piece of software designed to facilitate the use of a public key infrastructure in the Windows ecosystem. The attack shown here would also be possible with other tools in the same way. Furthermore, this example is not an exploit of a vulnerability in the certification authority product, but rather shows the conceptual relationships and how they can be abused if security hardening is not done.

Install-Module -Name PSCertificateEnrollment
Import-Module -Name PSCertificateEnrollment

To be able to sign the generated certificate, the certification authority certificate including its private key is required.

In the example, we assume one of the following two cases:

  • The attacker is in possession of a copy of the certification authority's private key (e.g., by stealing one of the backups) because it was not protected by a hardware security module (HSM). In this case, the attack works from any Windows system.
  • The attacker has obtained system rights on the certification authority and performs the operation directly on it. In this case, the attack works even if the private key was protected by a hardware security module.

The certification authority certificate must first be identified in a local certificate store.

Get-ChildItem -Path Cert:\LocalMachine\My

PowerShell: dir Cert:\LocalMachine\My lists the certificate of "ADCS Labor Issuing CA 1" with its thumbprint

Next, it is read into a variable.

$CaCert = Get-ChildItem -Path Cert:\LocalMachine\My\A40E27C70460D0CD0AF7DE4088105869AD90AF60

PowerShell: $CaCert = dir Cert:\LocalMachine\My with the thumbprint of the CA certificate

A certificate request can then be generated, which is signed directly with the certification authority certificate.

Do you know TameMyCerts? TameMyCerts is an add-on for the Microsoft certification authority (Active Directory Certificate Services). It extends the function of the certification authority and enables the application of rule sets to realize the secure automation of certificate issuance. TameMyCerts is unique in the Microsoft ecosystem, has already proven itself in countless companies around the world and is available under a free license. It can be downloaded via GitHub and used free of charge. Professional maintenance is also offered.

In the example...

  • the resulting certificate is generated in the user certificate store (default setting of the module).
  • the Microsoft Software Key Storage Provider is used (default setting of the module).
  • the private key is marked as exportable (so that it can afterwards be imported on another system or into a smart card ).
  • the resulting certificate contains the user principal name (UPN) of the administrator account of the forest.
  • the resulting certificate contains the Extended Key Usages for client authentication and smart card logon .
  • the resulting certificate contains a CRL distribution point that points to a valid CRL of the certification authority (a prerequisite for the certificate to be accepted by a domain controller).
  • the resulting certificate contains a serial number specified by the attacker.
New-CertificateRequest `
-Exportable `
-Upn "administrator@intra.adcslabor.de" `
-EnhancedKeyUsage ClientAuthentication,SmartcardLogon `
-Cdp "http://pki.adcslabor.de/CertData/ADCS Labor Issuing CA 1.crl" `
-SerialNumber "deadbeef1337" `
-SigningCert $CaCert

PowerShell: New-CertificateRequest with -SerialNumber "deadbeef1337" and -SigningCert $CaCert

After executing the command, there should be a corresponding certificate in the certificate store of the logged-on user.

certmgr: certificate for administrator@intra.adcslabor.de issued by "ADCS Labor Issuing CA 1" under "Personal", "Certificates"

A look at the properties of the certificate shows that the specified serial number has been taken over. This is meant to make clear that the attacker has complete control over the contents of the certificate - including the serial number. It is therefore practically impossible to revoke such a certificate, since the serial number is usually not known.

Certificate dialog, "Details" tab: serial number deadbeef1337, signature algorithm sha256RSA

The subject alternative name (SAN) contains the user principal name of the administrator account. The attacker can enter any identity here.

Certificate dialog, "Details" tab: Subject Alternative Name with Principal Name administrator@intra.adcslabor.de

The Extended Key Usage (EKU) contains the necessary entries for a smart card logon.

Certificate dialog, "Details" tab: Enhanced Key Usage Client Authentication and Smart Card Logon

Last but not least, it can be seen that the certificate was apparently issued by the certification authority - the certificate chain can be built successfully.

However, since the private key was addressed directly, no corresponding certificate will be found in the certification authority database. Likewise, no audit event was generated on the certification authority.

Certificate dialog, "Certification Path" tab: ADCS Labor Root CA, ADCS Labor Issuing CA 1 and the certificate, status "This certificate is OK."

If the attacker imports such a certificate into a smart card, he can use it to log on to the Active Directory forest with the identity contained in the certificate, provided that the prerequisites in the infrastructure are met. He then receives the permissions of the corresponding user - in the example, "Enterprise Administrator". A worst-case scenario for IT security.

In the meantime, with kekeo , there is also a tool that enables the direct request of a Ticket Granting Ticket (TGT) with a certificate - i.e., without a smart card and presence in the local network - which makes the attack even more dangerous.

Countermeasures

The following measures can help mitigate the threats posed by such an attack, or detect such an attack: