AD Сертифікати
Reading time: 7 minutes
tip
Вивчайте та практикуйте AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Вивчайте та практикуйте GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
Вивчайте та практикуйте Azure Hacking:
HackTricks Training Azure Red Team Expert (AzRTE)
Підтримайте HackTricks
- Перевірте плани підписки!
- Приєднуйтесь до 💬 групи Discord або групи telegram або слідкуйте за нами в Twitter 🐦 @hacktricks_live.
- Діліться хакерськими трюками, надсилаючи PR до HackTricks та HackTricks Cloud репозиторіїв на github.
Вступ
Компоненти сертифіката
- The Subject of the certificate denotes its owner.
- A Public Key is paired with a privately held key to link the certificate to its rightful owner.
- The Validity Period, defined by NotBefore and NotAfter dates, marks the certificate's effective duration.
- A unique Serial Number, provided by the Certificate Authority (CA), identifies each certificate.
- The Issuer refers to the CA that has issued the certificate.
- SubjectAlternativeName allows for additional names for the subject, enhancing identification flexibility.
- Basic Constraints identify if the certificate is for a CA or an end entity and define usage restrictions.
- Extended Key Usages (EKUs) delineate the certificate's specific purposes, like code signing or email encryption, through Object Identifiers (OIDs).
- The Signature Algorithm specifies the method for signing the certificate.
- The Signature, created with the issuer's private key, guarantees the certificate's authenticity.
Особливі зауваги
- Subject Alternative Names (SANs) expand a certificate's applicability to multiple identities, crucial for servers with multiple domains. Secure issuance processes are vital to avoid impersonation risks by attackers manipulating the SAN specification.
Certificate Authorities (CAs) in Active Directory (AD)
AD CS acknowledges CA certificates in an AD forest through designated containers, each serving unique roles:
- Certification Authorities container holds trusted root CA certificates.
- Enrolment Services container details Enterprise CAs and their certificate templates.
- NTAuthCertificates object includes CA certificates authorized for AD authentication.
- AIA (Authority Information Access) container facilitates certificate chain validation with intermediate and cross CA certificates.
Отримання сертифіката: потік запиту клієнта
- Процес запиту починається з того, що клієнти знаходять Enterprise CA.
- Створюється CSR, який містить public key та інші деталі, після генерації пари public-private ключів.
- CA оцінює CSR згідно з доступними certificate templates і видає сертифікат на основі дозволів шаблону.
- Після погодження CA підписує сертифікат своїм приватним ключем і повертає його клієнту.
Certificate Templates
Визначені в AD, ці шаблони описують налаштування та права для видачі сертифікатів, включно з допустимими EKU та правами на enrolment або модифікацію, що є критично важливим для керування доступом до сервісів сертифікації.
Certificate Enrollment
The enrollment process for certificates is initiated by an administrator who creates a certificate template, which is then published by an Enterprise Certificate Authority (CA). This makes the template available for client enrollment, a step achieved by adding the template's name to the certificatetemplates
field of an Active Directory object.
For a client to request a certificate, enrollment rights must be granted. These rights are defined by security descriptors on the certificate template and the Enterprise CA itself. Permissions must be granted in both locations for a request to be successful.
Template Enrollment Rights
These rights are specified through Access Control Entries (ACEs), detailing permissions like:
- Certificate-Enrollment and Certificate-AutoEnrollment rights, each associated with specific GUIDs.
- ExtendedRights, allowing all extended permissions.
- FullControl/GenericAll, providing complete control over the template.
Enterprise CA Enrollment Rights
The CA's rights are outlined in its security descriptor, accessible via the Certificate Authority management console. Some settings even allow low-privileged users remote access, which could be a security concern.
Additional Issuance Controls
Certain controls may apply, such as:
- Manager Approval: Places requests in a pending state until approved by a certificate manager.
- Enrolment Agents and Authorized Signatures: Specify the number of required signatures on a CSR and the necessary Application Policy OIDs.
Methods to Request Certificates
Certificates can be requested through:
- Windows Client Certificate Enrollment Protocol (MS-WCCE), using DCOM interfaces.
- ICertPassage Remote Protocol (MS-ICPR), through named pipes or TCP/IP.
- The certificate enrollment web interface, with the Certificate Authority Web Enrollment role installed.
- The Certificate Enrollment Service (CES), in conjunction with the Certificate Enrollment Policy (CEP) service.
- The Network Device Enrollment Service (NDES) for network devices, using the Simple Certificate Enrollment Protocol (SCEP).
Windows users can also request certificates via the GUI (certmgr.msc
or certlm.msc
) or command-line tools (certreq.exe
or PowerShell's Get-Certificate
command).
# Example of requesting a certificate using PowerShell
Get-Certificate -Template "User" -CertStoreLocation "cert:\\CurrentUser\\My"
Аутентифікація за сертифікатами
Active Directory (AD) підтримує аутентифікацію за сертифікатами, переважно з використанням протоколів Kerberos та Secure Channel (Schannel).
Процес аутентифікації Kerberos
У процесі аутентифікації Kerberos запит користувача на Ticket Granting Ticket (TGT) підписується з використанням приватного ключа сертифіката користувача. Цей запит проходить кілька перевірок на контролері домену, включно з перевіркою дійсності, шляху та стану відкликання сертифіката. Перевірки також включають підтвердження, що сертифікат походить із довіреного джерела, і підтвердження присутності видавця в NTAUTH certificate store. У разі успішних перевірок видається TGT. Об'єкт NTAuthCertificates
в AD, який знаходиться за адресою:
CN=NTAuthCertificates,CN=Public Key Services,CN=Services,CN=Configuration,DC=<domain>,DC=<com>
є ключовим для встановлення довіри при автентифікації за допомогою сертифікатів.
Secure Channel (Schannel) Authentication
Schannel забезпечує захищені TLS/SSL-з’єднання, де під час handshake клієнт пред’являє сертифікат, який, якщо успішно перевірений, авторизує доступ. Відображення сертифіката на обліковий запис AD може включати функцію Kerberos’s S4U2Self або Subject Alternative Name (SAN) сертифіката, серед інших методів.
AD Certificate Services Enumeration
Служби сертифікації AD можна перелічити за допомогою LDAP-запитів, що розкривають інформацію про Enterprise Certificate Authorities (CAs) та їхні конфігурації. Це доступно будь-якому автентифікованому в домені користувачу без спеціальних привілеїв. Інструменти на кшталт Certify та Certipy використовуються для перелічення та оцінки вразливостей у середовищах AD CS.
Команди для використання цих інструментів включають:
# Enumerate trusted root CA certificates, Enterprise CAs and HTTP enrollment endpoints
# Useful flags: /domain, /path, /hideAdmins, /showAllPermissions, /skipWebServiceChecks
Certify.exe cas [/ca:SERVER\ca-name | /domain:domain.local | /path:CN=Configuration,DC=domain,DC=local] [/hideAdmins] [/showAllPermissions] [/skipWebServiceChecks]
# Identify vulnerable certificate templates and filter for common abuse cases
Certify.exe find
Certify.exe find /vulnerable [/currentuser]
Certify.exe find /enrolleeSuppliesSubject # ESC1 candidates (CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT)
Certify.exe find /clientauth # templates with client-auth EKU
Certify.exe find /showAllPermissions # include template ACLs in output
Certify.exe find /json /outfile:C:\Temp\adcs.json
# Enumerate PKI object ACLs (Enterprise PKI container, templates, OIDs) – useful for ESC4/ESC7 discovery
Certify.exe pkiobjects [/domain:domain.local] [/showAdmins]
# Use Certipy for enumeration and identifying vulnerable templates
certipy find -vulnerable -u john@corp.local -p Passw0rd -dc-ip 172.16.126.128
# Enumerate Enterprise CAs and certificate templates with certutil
certutil.exe -TCAInfo
certutil -v -dstemplate
Посилання
- https://www.specterops.io/assets/resources/Certified_Pre-Owned.pdf
- https://comodosslstore.com/blog/what-is-ssl-tls-client-authentication-how-does-it-work.html
- GhostPack/Certify
- GhostPack/Rubeus
tip
Вивчайте та практикуйте AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Вивчайте та практикуйте GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
Вивчайте та практикуйте Azure Hacking:
HackTricks Training Azure Red Team Expert (AzRTE)
Підтримайте HackTricks
- Перевірте плани підписки!
- Приєднуйтесь до 💬 групи Discord або групи telegram або слідкуйте за нами в Twitter 🐦 @hacktricks_live.
- Діліться хакерськими трюками, надсилаючи PR до HackTricks та HackTricks Cloud репозиторіїв на github.