id: ldap-metadata

info:
  name: LDAP Metadata - Enumeration
  author: pussycat0x
  severity: info
  description: |
    LDAP metadata refers to the data that describes the structure, schema, and attributes of the LDAP directory
  reference:
    - https://docs.projectdiscovery.io/templates/protocols/javascript/modules/ldap.Metadata
  metadata:
    max-request: 1
    shodan-query: ldap
  tags: js,network,ldap

javascript:
  - pre-condition: |
      isPortOpen(Host,Port);
    code: |
      const ldap = require('nuclei/ldap');
      const cfg = new ldap.Config();
      cfg.Upgrade = true;
      const client = new ldap.Client(LDAPUrl, Port, cfg);
      const metadata = client.CollectMetadata();
      Export(metadata)

    args:
      Host: "{{Host}}"
      LDAPUrl: "ldap://{{Host}}"
      Port: 389

    matchers:
      - type: dsl
        dsl:
          - "success == true"

    extractors:
      - type: json
        json:
          - '"BaseDN: " + .BaseDN'
          - '"DnsHostName: " + .DnsHostName '
          - '"DefaultNamingContext: "+ .DefaultNamingContext'
          - '"DomainFunctionality: "+ .DomainFunctionality'
          - '"ForestFunctionality: " + .ForestFunctionality'
          - '"DomainControllerFunctionality: "+ .DomainControllerFunctionality'
# digest: 4b0a00483046022100ffd4bc8b32f15db2d489bce66a8f815e9f72cc601692f1156a8fbfc05dd95490022100d1bcf2750ff39d6dbb0839d0dc40a7a26ec3b9649980008e958c044a2609674c:922c64590222798bb761d5b6d8e72950