LDAPDomainDump

repository·master·Indexed 23 days ago

https://github.com/dirkjanm/ldapdomaindump

A tool for gathering Active Directory information via the LDAP protocol. It collects and parses domain data including users, groups, computers, policies, and trusts, outputting the results in HTML, JSON, and CSV/TSV formats. The package includes utilities like ldd2bloodhound for BloodHound 1.x compatibility and ldd2pretty for formatted output. It supports NTLM and SIMPLE authentication and provides a Python API via the domainDumper and domainDumpConfig classes.

Tokens
4.9K
Snippets
8
Records
21
Agent score
79%

What's inside ldapdomaindump

  1. Understand LDAPDomainDump output formats

    master

    The tool generates several files containing an overview of domain objects:

    Standard Files:

    • domain_groups: List of groups.
    • domain_users: List of users.
    • domain_computers: List of computer accounts.
    • domain_policy: Domain policies (password requirements, lockout policy).
    • domain_trusts: Incoming and outgoing domain trusts.

    Grouped Files:

    • domain_users_by_group: Users categorized by group membership.
    • domain_computers_by_os: Computers sorted by Operating System.

    Formats Supported:

    • HTML: Human-readable overview.
    • JSON: Machine-readable data. By default, JSON for grouped files is disabled to save space/memory.
    • Greppable (CSV/TSV): Tab-delimited output for easy parsing. Use -d to change the delimiter.
  2. Run LDAPDomainDump

    master

    Depending on how you installed the tool, you can execute it in one of three ways:

    1. From source: Run the script directly.
    2. After pip installation (module mode): Use the python module flag.
    3. After pip installation (CLI mode): Run the command directly from your shell.
    python ldapdomaindump.py
    python -m ldapdomaindump
    ldapdomaindump
  3. Install LDAPDomainDump

    master

    LDAPDomainDump requires Python 3.6 or greater and the ldap3 (> 2.0) and dnspython libraries.

    To install from the git source:

    python setup.py install

    To install the latest release via pip:

    pip install ldapdomaindump

    If you need to install dependencies manually:

    pip install ldap3 dnspython future
    pip install ldapdomaindump
  4. Use LDAPDomainDump via CLI

    master

    LDAPDomainDump is a tool to dump domain information (users, computers, groups, policies, and trusts) via LDAP. It supports outputting data in HTML, JSON, and greppable formats.

    Basic Usage

    To connect to a host, you must provide the hostname or an LDAP connection string. You can specify credentials for authentication.

    python ldapdomaindump.py <HOSTNAME> -u 'DOMAIN\username' -p 'PASSWORD'

    Authentication

    • Host: Use HOSTNAME or an ldap://host:port / ldaps://host:port connection string.
    • User: Must include the domain (e.g., DOMAIN\username).
    • Password: Can be a plain password or an LM:NTLM hash. If not provided via -p, the tool will prompt for it.
    • Auth Type: Use -at or --authtype to choose between NTLM (default) or SIMPLE.
    • Anonymous: If no user is provided, it attempts an anonymous connection (though this often fails in production environments).
  5. Convert LDAPDomainDump JSON to pretty output

    master

    To view the .json dump in a format similar to enum4linux, use the ldd2pretty utility.

    Execution methods:

    • If installed via pip: Run ldd2pretty directly.
    • Via module: python -m ldapdomaindump.pretty
    • From source: python ldapdomaindump/pretty.py
    python -m ldapdomaindump.pretty
  6. Convert LDAPDomainDump JSON to BloodHound CSV

    master

    You can convert the generated .json files into CSV files compatible with BloodHound 1.x using the ldd2bloodhound utility. This creates group_membership.csv and trust.csv files.

    Execution methods:

    • If installed via pip: Run ldd2bloodhound directly.
    • Via module: python -m ldapdomaindump.convert
    • From source: python ldapdomaindump/convert.py
    python -m ldapdomaindump.convert
  7. Configure the domainDumpConfig class

    master

    The domainDumpConfig class holds the default configuration settings for the LDAP domain dump process. You can instantiate this class to customize output file names, formats, and network behaviors.

    Key configuration attributes include:

    • basepath: The directory where output files are saved (default: .).
    • groupsfile, usersfile, computersfile, policyfile, trustsfile: Basenames for individual entity reports.
    • users_by_group, computers_by_os: Basenames for combined/sorted reports.
    • outputhtml, outputjson, outputgrep: Boolean flags to enable/disable specific output formats.
    • groupedjson: Boolean flag to enable grouped JSON output for computers by OS.
    • grepsplitchar: The delimiter used for greppable output (default: \t).
    • lookuphostnames: Boolean; if true, attempts to resolve computer DNS names to IP addresses.
    • dnsserver: The address of the DNS server to use for lookups.
    • minimal: Boolean; if true, only queries a minimal set of attributes to reduce network/memory usage.
    class domainDumpConfig():
        def __init__(self):
            #Base path
            self.basepath = '.'
    
        #Output files basenames
            self.groupsfile = 'domain_groups' #Groups
            self.usersfile = 'domain_users' #User accounts
            self.computersfile = 'domain_computers' #Computer accounts
            self.policyfile = 'domain_policy' #General domain attributes
            self.trustsfile = 'domain_trusts' #Domain trusts attributes
    
        #Combined files basenames
            self.users_by_group = 'domain_users_by_group' #Users sorted by group
            self.computers_by_os = 'domain_computers_by_os' #Computers sorted by OS
    
        #Output formats
            self.outputhtml = True
            self.outputjson = True
            self.outputgrep = True
    
        #Output json for groups
            self.groupedjson = False
    
        #Default field delimiter for greppable format is a tab
            self.grepsplitchar = '\t'
    
        #Other settings
            self.lookuphostnames = False #Look up hostnames of computers to get their IP address
            self.dnsserver = '' #Addres of the DNS server to use, if not specified default DNS will be used
            self.minimal = False #Only query minimal list of attributes
  8. Use LDAPDomainDump CLI options

    master

    The ldapdomaindump CLI allows you to dump Active Directory information via LDAP.

    Required Argument:

    • HOSTNAME: Hostname/IP or an ldap://host:port connection string (use ldaps:// for SSL).

    Authentication Options:

    • -u USERNAME, --user USERNAME: Domain\username. Leave empty for anonymous authentication.
    • -p PASSWORD, --password PASSWORD: Password or LM:NTLM hash. Will prompt if omitted.
    • -at {NTLM,SIMPLE}, --authtype {NTLM,SIMPLE}: Authentication type (default is NTLM).

    Output Options:

    • -o DIRECTORY, --outdir DIRECTORY: Directory to save the dump (default: current).
    • --no-html, --no-json, --no-grep: Disable specific output formats.
    • --grouped-json: Write JSON files for grouped files (default: disabled).
    • -d DELIMITER, --delimiter DELIMITER: Field delimiter for greppable output (default: tab).

    Miscellaneous Options:

    • -r, --resolve: Resolve computer hostnames to IPv4 addresses (may cause high traffic).
    • -n DNS_SERVER, --dns-server DNS_SERVER: Use a custom DNS resolver (e.g., a Domain Controller IP).
    • -m, --minimal: Only query a minimal set of attributes to limit memory usage.
    usage: ldapdomaindump.py [-h] [-u USERNAME] [-p PASSWORD] [-at {NTLM,SIMPLE}]
                             [-o DIRECTORY] [--no-html] [--no-json] [--no-grep]
                             [--grouped-json] [-d DELIMITER] [-r] [-n DNS_SERVER]
                             [-m]
                             HOSTNAME
  9. BloodHoundConverter Class

    master

    The BloodHoundConverter class is the core engine used to transform LDAP JSON data into BloodHound-compatible CSVs.

    Workflow

    1. parse_files(infiles): Maps provided filenames to internal lists (user_files, group_files, trust_files, computers_files) based on their base names.
    2. build_mappings(): Parses the group files to build an index of groups by both Distinguished Name (DN) and Security Identifier (SID).
    3. write_users(), write_groups(), write_computers(), and write_trusts(): Iterates through the loaded data to generate the membership and trust CSV files.

    Output Files

    • group_membership.csv: Contains mappings for users, computers, and groups.
    • trusts.csv: Contains domain trust information.
  10. Use the reportWriter class for output generation

    master

    The reportWriter class is responsible for transforming the raw LDAP entries collected by domainDumper into various output formats (HTML, JSON, and Greppable text).

    Key capabilities:

    • HTML Generation: Uses generateHtmlTable and generateGroupedHtmlTables to create formatted tables. It includes logic to escape HTML special characters and format complex attributes like group DNs as clickable links.
    • JSON Generation: Uses generateJsonList, generateJsonGroup, and generateJsonGroupedList to produce structured data. The grouped JSON format is particularly useful for the computers_by_os report.
    • Greppable Output: Uses generateGrepList to create tab-separated or custom-delimited text files suitable for command-line tools like grep, awk, or cut.
    • Attribute Formatting: The formatAttribute method handles the translation of raw LDAP values into human-readable strings, such as converting bitwise flags (UAC, Password Policy, Trust flags), SIDs, and time durations (converting nanoseconds to days or minutes).
  11. Use the PrettyOuput class for data visualization

    master

    The PrettyOuput class contains methods to format and print LDAP data. If you are integrating this into another tool, you can instantiate PrettyOuput() and call its methods with the appropriate data structures.

    Key methods include:

    • domain_info(data): Extracts and prints the Domain Name and SID.
    • password_complexity(data): Prints password policy details including complexity flags, age requirements, and lockout thresholds.
    • user_info(users, dc): Prints a list of users with their account names, display names, and descriptions.
    • groups_info(groups, dc): Prints group names and their members, resolving certain SIDs (like S-1-5-11) to friendly names (like NT AUTHORITY\Authenticated Users).