Skip to content

LDAP / Active Directory Audit Executor

Category: Pentesting and Bug Bounty Script: ldap_audit.py Integration: Python SDK (ldap3) Faraday Plugin: Raw JSON Website: https://ldap3.readthedocs.io/

Description

Searches an LDAP or Active Directory tree and reports enabled user, group and computer accounts with weak userAccountControl flags: passwords that are not required or never expire. Each weak account becomes a host with one vulnerability in Faraday.

Prerequisites

  • Network access from the agent to the LDAP server (default ports 389, or 636 with TLS)
  • Read access to the directory. Use a bind user (LDAP_USER) or, if the server allows it, an anonymous bind.
  • The ldap3 Python package available to the agent

Configuration

Environment Variables (Setup)

Variable Required Description
LDAP_HOST Yes LDAP server as a hostname, IP, or URL, optionally with a port (e.g., dc01.corp.local, ldaps://dc01.corp.local:636)
LDAP_USER No Bind user (e.g., CORP\auditor or auditor@corp.local). If empty, the executor binds anonymously.
LDAP_PASSWORD No Password of the bind user
LDAP_USE_TLS No Set to true to connect over SSL/TLS (default: false). An ldaps:// host always uses TLS.

These variables are also accepted as execution arguments, so a single run can override them.

Execution Arguments

Parameter Type Mandatory Description
LDAP_BASE_DN string Yes Distinguished name where the search starts, for example DC=corp,DC=local or OU=Users,DC=corp,DC=local. The whole subtree is searched.
LDAP_FILTER string No LDAP search filter in parentheses (default: users, groups and computers). An invalid or unbalanced filter is ignored and the default is used.
LDAP_ATTRIBUTES string No Comma-separated LDAP attributes to retrieve (e.g., sAMAccountName,cn,memberOf). By default it retrieves a standard set of identity and host attributes. userAccountControl is always added.

YAML Configuration Example

executors:
  ldap_audit:
    repo_executor: ldap_audit.py
    max_size: 65536
    varenvs:
      LDAP_HOST: "ldaps://dc01.corp.local:636"
      LDAP_USER: "auditor@corp.local"
      LDAP_PASSWORD: "<ldap_password>"
      LDAP_USE_TLS: "true"
    params:
      LDAP_BASE_DN:
        mandatory: true
        type: string
        base: string
      LDAP_FILTER:
        mandatory: false
        type: string
        base: string
      LDAP_ATTRIBUTES:
        mandatory: false
        type: string
        base: string

How It Works

  1. Validates LDAP_HOST, LDAP_BASE_DN, the filter and the attribute list, then connects and binds with a simple bind (or anonymously when no user is set)
  2. Runs a paged subtree search under LDAP_BASE_DN with the filter and attributes
  3. Keeps only accounts that are enabled and have PASSWD_NOTREQD or DONT_EXPIRE_PASSWORD set in userAccountControl. Disabled accounts are skipped.
  4. Creates one host and one vulnerability per account:
    • Name: [IDENTITY] LDAP weak userAccountControl: <account> (<flags>)
    • Severity: critical if PASSWD_NOTREQD is set, otherwise medium (DONT_EXPIRE_PASSWORD)
    • Resolution: remediation steps to re-enable the password constraint and rotate the password

Notes

  • Computer accounts use their ipv4Address as the host IP when available, and their DNS name and OS as hostname and OS. Users, groups and computers without an address use the IP 0.0.0.0, with the account name as hostname.
  • The search returns at most 100,000 entries.
  • The run fails if LDAP_BASE_DN or LDAP_HOST is missing or invalid, or if the search fails. A failed bind produces no results.
  • The shared agent parameters (AGENT_CONFIG_* tags and severity filters) are not applied by this executor.