certipy-ad

repository·main·Indexed 25 days ago

https://github.com/ly4k/certipy

A specialized toolkit for the enumeration and abuse of Active Directory Certificate Services (AD CS), supporting the full ESC1-ESC17 attack spectrum. Key capabilities include discovering CAs and templates, requesting and forging certificates, performing certificate-based authentication (PKINIT, Schannel), and managing AD accounts and CA security descriptors. Version 5.1.0.

Tokens
18.5K
Snippets
5
Records
135
Agent score
86%

What's inside certipy

  1. Overview of Certipy AD CS Toolkit

    main

    Certipy is an offensive and defensive toolkit designed for enumerating and abusing Active Directory Certificate Services (AD CS). It is used by red teamers, penetration testers, and defenders to identify and exploit AD CS misconfigurations, specifically covering the full range of ESC1 through ESC17 attack paths.

    Key capabilities include:

    • Discovering Certificate Authorities and Templates.
    • Identifying misconfigurations.
    • Requesting and forging certificates.
    • Performing authentication using certificates.
    • Relaying NTLM authentication to AD CS HTTP(S)/RPC endpoints.
    • Supporting Shadow Credentials, Golden Certificates, and Certificate Mapping Attacks.
  2. Perform NTLM relay attacks to AD CS (ESC8 and ESC11)

    main

    Certipy provides a module to implement NTLM relay attacks against Active Directory Certificate Services (AD CS) to obtain certificates for other users. It supports two primary attack vectors:

    • ESC8: Relaying NTLM authentication to AD CS HTTP endpoints (Web Enrollment).
    • ESC11: Relaying NTLM authentication to AD CS RPC endpoints (MS-ICPR).

    These attacks allow for privilege escalation or persistence by obtaining certificates on behalf of relayed users.

  3. Authenticate using certificates with the auth command

    main

    The auth command provides certificate-based authentication workflows, including PKINIT for Kerberos and Schannel for LDAPS. It can be used to obtain Kerberos tickets (TGT), extract NT hashes via Kerberos User-to-User (U2U) authentication, or launch an interactive LDAP shell.

    Key Capabilities

    • PKINIT Authentication: Authenticate to Kerberos using a certificate to obtain a TGT.
    • NT Hash Extraction: Automatically attempts to extract the NT hash from the Kerberos ticket using U2U.
    • LDAP/LDAPS Authentication: Connect to LDAP servers using certificate-based authentication.
    • Interactive LDAP Shell: Launches an enhanced LDAP shell for manual administration after successful authentication.
  4. Forge certificates using a compromised CA

    main

    The forge module allows you to create forged certificates (Golden Certificates) by signing them with a compromised CA private key. This is used for privilege escalation and lateral movement in Active Directory environments.

    Key Capabilities

    • Custom Subject Alternative Names (SAN): Specify UPN (User Principal Name) or DNS names.
    • SID Extensions: Include Security Identifiers (SID) for domain authentication.
    • Template-based Forgery: Use an existing certificate as a template to inherit properties.
    • Customization: Set custom validity periods, serial numbers, issuer names, and CRL distribution points.
    • Application Policies: Add specific application policy OIDs.
    • S/MIME: Add S/MIME capability identifiers.
  5. Configure ESC1 Vulnerable Templates

    main

    You can use the write_default_configuration option to transform a template into an ESC1-vulnerable state. This requires providing a target SID.

    When write_default_configuration is used, the following attributes are configured:

    • Security Descriptor: Grants the provided sid full control.
    • Flags: Enables PUBLISH_TO_DS, EXPORTABLE_KEY, AUTO_ENROLLMENT, ADD_TEMPLATE_NAME, and IS_DEFAULT.
    • EKU: Sets client authentication for both pKIExtendedKeyUsage and msPKI-Certificate-Application-Policy.
    • Name Flags: Sets msPKI-Certificate-Name-Flag to ENROLLEE_SUPPLIES_SUBJECT.
    • Key Settings: Sets msPKI-Private-Key-Flag to EXPORTABLE_KEY and minimum key size to 2048 bits.
  6. Save certificates and private keys

    main

    Certipy provides helper functions to process successful certificate requests by saving the resulting certificate and private key to disk.

    • handle_request_response(...): Used after a successful request(). It extracts identities, determines an output filename, and saves the certificate and key as a .pfx file.
    • handle_retrieve(...): Used after a successful retrieve(). It attempts to find a matching private key (looking for a file named {request_id}.key) to create a .pfx. If no key is found, it saves the certificate as a .crt (PEM) file.
    • handle_pending_key_save(...): For pending requests, this function prompts the user to save the private key to a file (defaulting to {request_id}.key).
  7. Export Certipy find results to JSON or CSV

    main

    The find command supports exporting its findings into structured formats for further analysis.

    • JSON Output: When requested, Certipy generates a structured JSON file containing Certificate Authorities, Certificate Templates, and (if requested) Issuance Policies. The JSON structure includes detailed properties, permissions (Enrollment, Object Control, etc.), and detected vulnerabilities.
    • CSV Output: Certipy can export findings into multiple CSV files using a semicolon (;) delimiter and quoted fields. If CSV export is enabled, the following files are generated:
      • {prefix}_Templates_Certipy.csv: Contains flattened certificate template data including properties like Template Name, Enabled, Client Authentication, and [!] Vulnerabilities.
      • {prefix}_CAs_Certipy.csv: Contains flattened CA data including CA Name, DNS Name, Web Enrollment status, and [!] Vulnerabilities.
  8. Create a self-signed CA certificate

    main

    If no ca_pfx is provided, the module defaults to creating a new self-signed CA certificate. This is useful for testing or creating a local CA.

    • Default Subject: CN=Certipy CA (unless overridden by --subject).
    • Default Output: ca.pfx (unless overridden by --out).
  9. Forge a certificate from a template

    main

    To create a forged certificate that inherits properties from an existing certificate, use the --template flag. The module will copy extensions from the template while allowing you to override specific fields like Subject, SAN, and SID.

    Note: Certain extensions like AuthorityKeyIdentifier, SubjectAlternativeName, ExtendedKeyUsage, and NTDS_CA_SECURITY_EXT are skipped from the template to allow for the new forged identity.

  10. Enumerate AD CS certificate templates via HTTP

    main
    To discover available certificate templates through the AD CS Web Enrollment interface, use the enum_templates flag. This will parse the HTML from the /certsrv/certrqxt.asp endpoint to list the templates available to the relayed user.
  11. Perform Shadow Credentials (Key Credential) attacks

    main

    The Shadow Authentication module allows for manipulating msDS-KeyCredentialLink attributes in Active Directory. This can be used to add certificate-based credentials to a user account to facilitate authentication and NT hash retrieval.

    Available actions via the shadow command:

    • auto: The most common attack scenario. It automatically adds a temporary Key Credential, authenticates to retrieve the user's NT hash, and then restores the original state to clean up.
    • add: Adds a new Key Credential to the target user and saves the certificate and private key as a .pfx file.
    • list: Lists all existing Key Credentials for the target user, showing their Device ID and Creation Time.
    • clear: Removes all Key Credentials from the target user.
    • remove: Deletes a specific Key Credential using its unique Device ID.
    • info: Displays detailed information (Device ID and Creation Time) for a specific Key Credential.
  12. Use the `find` command to enumerate AD CS components

    main

    The find command is used to discover and analyze Active Directory Certificate Services (AD CS) components, including certificate templates, certificate authorities (CAs), and issuance policies (OIDs). It also detects vulnerabilities (ESC1-17) and analyzes security permissions/ACLs.

    Key capabilities:

    • Discovery: Enumerates templates, CAs, and issuance policies via LDAP.
    • Relationship Mapping: Links CAs to templates and templates to issuance policies.
    • Vulnerability Detection: Identifies misconfigurations and potential attack vectors.
    • Property Analysis: Extracts CA configuration (e.g., SAN usage, request disposition, web enrollment status) and template properties (e.g., EKU, enrollment flags, validity periods).