Active Directory Enumeration with LDAP
Stephen Bradshaw (Principal Security Consultant · SEEK)
BSides Canberra VII (2024) · Day 2 · Bradman Theatrette
Overview
In his BSides Canberra talk, "Active Directory Enumeration with LDAP," Stephen Bradshaw, a Principal Security Consultant in the offensive security team at SEEK, delves into the critical role of the Lightweight Directory Access Protocol (LDAP) in enumerating information from Active Directory (AD) environments. Bradshaw highlights that LDAP is the fundamental mechanism by which clients query network objects in AD, making it an invaluable, often overlooked, attack surface for adversaries.

Key moments
- 0:30 Talk overview: AD, LDAP, data types, security relevance, tools
- 2:15 LDAP data enables diverse Active Directory attacks and privilege escalation
- 10:00 Suggested combined approach for discovering domain controllers
- 18:00 Crafting complex LDAP queries: Kerberoastable users example
- 21:20 Introducing BloodHound: Visualizing Active Directory attack paths
- 31:00 Overcoming ACL parsing challenges with LDAP query controls
- 40:50 Speaker's tool: ad-ldap-dumper for restricted environments
- 43:20 Q&A: Why Microsoft removed LDAP query logging requirements
Active Directory Enumeration with LDAP
Speakers: Stephen Bradshaw, Principal Security Consultant, SEEK
Conference: BSides Canberra
YouTube: https://www.youtube.com/watch?v=lScLcUNnwvc
Overview
In his BSides Canberra talk, "Active Directory Enumeration with LDAP," Stephen Bradshaw, a Principal Security Consultant in the offensive security team at SEEK, delves into the critical role of the Lightweight Directory Access Protocol (LDAP) in enumerating information from Active Directory (AD) environments. Bradshaw highlights that LDAP is the fundamental mechanism by which clients query network objects in AD, making it an invaluable, often overlooked, attack surface for adversaries.
The presentation meticulously unpacks how attackers can leverage default AD configurations to gather a wealth of sensitive data, even with low-privileged user accounts. This information, spanning permission relationships, user and group details, computer memberships, trust relationships, and Active Directory Certificate Services (AD CS) configurations, directly facilitates common attack techniques like Kerberoasting, AS-REP Roasting, and Active Directory Access Control List (ACL) abuse. Bradshaw emphasizes that while specialized tools exist to automate this collection, a deep understanding of the underlying LDAP mechanics is crucial for troubleshooting, developing custom strategies, and effectively defending against these threats.
Background
▶ Watch: Talk overview: AD, LDAP, data types, security relevance, tools (0:30)
Active Directory, Microsoft's ubiquitous directory service, underpins authentication and authorization in countless enterprise networks. At its core, AD relies heavily on LDAP as a vendor-neutral standard for querying and modifying directory information. Every domain controller, by default, hosts an LDAP server, making it a primary interface for clients to discover and interact with network resources. This inherent design, coupled with default security settings, creates a significant vulnerability: any authenticated user, even one with minimal privileges, can query and extract a vast amount of information that can be weaponized for various offensive operations.
The problem stems from the fact that much of the information critical for identifying attack paths – such as group memberships, service principal names (SPNs), user account controls, and access control lists – is readable by default by virtually any authenticated user. This allows attackers to map out the network, identify high-value targets, and uncover misconfigurations that lead to privilege escalation or lateral movement. Specific attack types enabled by this enumeration include Kerberoasting and AS-REP Roasting (identifying users with weak SPN passwords or accounts that don't require Kerberos pre-authentication), Golden and Silver Ticket creation (requiring knowledge of domain SIDs and service accounts), Active Directory ACL abuse (finding misconfigured permissions that grant control over critical objects), DC Sync (simulating a domain controller to request replication data), Domain and Forest Trust abuse, constrained and unconstrained delegation, and Certificate Services attacks. In some cases, with appropriate permissions, LDAP can even be used to recover alternate password types like LAPS (Local Administrator Password Solution) passwords. Understanding the technical intricacies of this data collection is therefore paramount for both offensive and defensive security practitioners.
Key Findings
▶ Watch: Suggested combined approach for discovering domain controllers (10:00)
Bradshaw outlines a systematic four-step process for effective Active Directory enumeration via LDAP:
- Discovering Domain Controllers: Identifying the LDAP servers available for querying.
- Connecting and Authenticating: Establishing a session with a chosen domain controller.
- Querying and Parsing Data: Formulating LDAP queries and extracting relevant information.
- Interpreting and Presenting Data: Making sense of the collected data to identify attack opportunities.
A central finding is the importance of the Global Catalog (GC) server role. Domain controllers with the GC role can return information on any object within the entire Active Directory forest, making them the preferred target for comprehensive enumeration.
Discovery methods include:
- Port Scanning: Domain controllers expose a unique set of ports (TCP/UDP 53 for DNS, TCP 88 for Kerberos, TCP 389 for plain LDAP, TCP 445 for SMB, TCP 636 for secure LDAPS, and often management ports like TCP 3389 for RDP, TCP 5985/5986 for WinRM). Identifying this specific port combination strongly indicates a domain controller. A global catalog server can be identified by performing an anonymous LDAP bind and checking for the
isGlobalCatalogReadyproperty. - DNS Enumeration: If the DNS domain name is known (e.g.,
example.com),Arecord lookups for the domain name itself will list domain controllers, whilegc._msdcs.example.comwill list global catalog servers. - Inferring Domain Name: If the domain name is unknown, it can be inferred from certificates presented by services (LDAPS, RDP, HTTPS, WinRM), through an anonymous LDAP bind, or most effectively, using tools like NTLM Challenger against an open SMB port (445) on a domain-joined Windows machine.
Once a target is identified, connection requires communication over TCP 389 (LDAP) or TCP 636 (LDAPS). Authentication options range from anonymous binds (very limited information by default) to NTLM (plaintext or pass-the-hash), Simple authentication (username and unencrypted password, unique to LDAP), and Kerberos (requiring the server's DNS name and access to TCP 88). Bradshaw highlights that most valuable data requires valid credentials.
The LDAP query language is distinct, using a hierarchical, tree-like structure. Queries are filter-based, grouping conditions with brackets and logical operators (& for AND, | for OR, ! for NOT). Special comparators like bitwise AND (:1.2.840.113556.1.4.803:=) are critical for extracting flag-based properties, such as those within the userAccountControl attribute, which stores various security-related settings (e.g., 2 for disabled users).
Interpreting the raw data presents varying levels of difficulty. Simple strings or numbers are straightforward, but attributes requiring bitwise operations, binary parsing (e.g., the nTSecurityDescriptor for ACLs), or establishing complex relationships between objects demand specialized processing, often necessitating dedicated tools.
Technical Deep Dive
▶ Watch: Introducing BloodHound: Visualizing Active Directory attack paths (21:20)
The talk provides a granular look at the technical underpinnings of LDAP enumeration.
1. Discovering Domain Controllers:
Bradshaw advises a combined approach for discovery:
- First, determine the DNS domain name using techniques like NTLM Challenger against an open SMB port (TCP 445) on a domain-joined machine.
- Second, locate a DNS server (ideally a domain controller itself, identifiable by TCP 53).
- Third, use DNS enumeration (
Arecords forexample.comandgc._msdcs.example.com) to get IP addresses of domain controllers and global catalog servers. - Finally, port scan these IP addresses to confirm reachability, specifically for LDAP (TCP 389) or LDAPS (TCP 636).
2. Connecting and Authenticating:
Connecting to a chosen domain controller (preferably a global catalog server) requires access to either TCP 389 (plain LDAP) or TCP 636 (secure LDAPS). Authentication methods have specific nuances:
- Anonymous binds typically only provide information about the LDAP service itself, not directory objects, unless AD is misconfigured.
- NTLM (plaintext or pass-the-hash) and Simple authentication (username/unencrypted password) are common.
- Kerberos requires the DNS name of the server, not its IP, and access to TCP 88.
- LDAPS (TCP 636) requires a TLS negotiation. A critical caveat is that port 636 might appear open, but if no certificate is configured for the LDAP service, communication will fail. Furthermore, some authentication methods might be restricted to LDAPS only, requiring a secure connection.
3. Querying and Parsing Data:
LDAP's query language is highly specific. Queries are built from one or more conditions, grouped by parentheses. For instance, to find all group objects, the query is (objectClass=group). More complex queries involve:
- Wildcards:
(servicePrincipalName=*)to find objects with any SPN. - Logical Operators:
&(AND),|(OR),!(NOT). These operators must enclose the conditions they apply to, e.g.,(&(condition1)(condition2)). - Special Comparators: The bitwise AND comparator
1.2.840.113556.1.4.803:=is crucial for attributes likeuserAccountControl. This attribute stores an integer where individual bits represent different account properties (e.g.,2forACCOUNTDISABLE). To check if a specific property is set, a bitwise AND operation is performed. - An example query for Kerberoastable users (users with an SPN that are not the
krbtgtaccount and are not disabled) is:(&(objectClass=user)(servicePrincipalName=*)(!cn=krbtgt)(!userAccountControl:1.2.840.113556.1.4.803:=2)). This query demonstrates the combination of AND, NOT, and the bitwise AND comparator.
4. Interpreting and Presenting Data:
Raw LDAP attributes come in various types: integers, dates, strings, Booleans, and binary data. Interpreting this data can range from trivial (simple strings) to highly complex (binary attributes or those requiring bitwise operations). Establishing relationships between objects often depends on parsing these more challenging attributes. This complexity underscores the need for automated tools to translate raw LDAP data into actionable intelligence for attack path identification.
Demo / Proof of Concept
▶ Watch: Overcoming ACL parsing challenges with LDAP query controls (31:00)
While not a live demonstration, Stephen Bradshaw used BloodHound as the primary example to illustrate how the complex LDAP enumeration process is consolidated and visualized for attack path identification. BloodHound, developed by SpecterOps, is a widely adopted tool designed to uncover hidden attack paths and relationships within Active Directory and Azure environments using graph theory.
Bradshaw explained BloodHound's user interface, highlighting:
- A central object (e.g., a group) surrounded by related objects (e.g., members of that group), with labeled links indicating the nature of the relationship.
- A properties pane displaying detailed attributes of the selected object.
- A search field for finding specific objects.
- The "Path Finding" feature, which allows users to query for attack paths between a controlled object (e.g., a compromised user) and a target object (e.g., the Domain Admins group).
The core of BloodHound's data collection relies on its collectors, such as SharpHound (the C# reference collector). Bradshaw emphasized a critical point: the majority of the information collected by BloodHound, particularly for low-privileged users, is derived from LDAP queries and can be rapidly gathered from a single domain controller. While other collection methods exist (e.g., requiring more time, higher privileges, or connections to more systems), LDAP remains the most efficient and accessible source for foundational AD enumeration.
Bradshaw delved into the SharpHound source code, showcasing its collection categories. He highlighted the DCOnly category, which largely consists of LDAP-based collection methods, with one exception: GPO Local Group collection, which requires accessing the domain controller's file system to parse Group Policy Objects. LDAP-specific collection categories include:
Containers: Organizational Units and container objects.Groups: Group objects and their memberships.Trusts: Information about domain trust relationships.CertServices: Configuration details of Active Directory Certificate Services.ObjectProps: Gathers extended attributes for users and computers, such aslastLogonandpasswordLastSet.
The most intricate part of the demonstration focused on the ACL category, which uncovers object security relationships and forms the basis for identifying abusable permissions. This data is extracted from the nTSecurityDescriptor attribute, a complex binary field present on every securable object. This descriptor contains four main components: an owner user, an owner group (both referenced by Security IDs, or SIDs), a Discretionary Access Control List (DACL), and a System Access Control List (SACL).
A significant challenge arises because the SACL component often requires the Access System Security privilege to read, which most users lack. To overcome this, LDAP provides a query control: LDAP_SERVER_SD_FLAGS_OID. By setting a mask value of 7 on queries requesting nTSecurityDescriptor, collectors can instruct the LDAP server to return only the owner user, owner group, and DACL, effectively masking out the inaccessible SACL.
Parsing the DACL involves interpreting a list of Access Control Entries (ACEs), each linking a security principal (identified by a SID) to a set of permissions on the object. BloodHound primarily focuses on "allow" ACEs and simplifies their interpretation down to "abusable permission sets." Bradshaw detailed the structure of two main ACE types:
ACCESS_ALLOWED_ACE: A simpler type containing a permission mask (integer value) and a SID.ACCESS_ALLOWED_OBJECT_ACE: A more complex type including flags, an object type GUID, and an inherited object type GUID, which need to be resolved against the LDAP schema.
The speaker's conclusion regarding ACL parsing was unequivocal: "just use a tool." The complexity of resolving SIDs to friendly names, GUIDs to schema objects, performing bitwise operations on permission masks, and simplifying these into abusable permissions makes manual parsing impractical for most scenarios.
Defensive Implications
▶ Watch: Q&A: Why Microsoft removed LDAP query logging requirements (43:20)
Stephen Bradshaw also discussed the limitations of existing tools and presented an alternative, highlighting key considerations for defenders.
Limitations of SharpHound:
- Operational Premise: SharpHound is designed to run on a compromised Windows machine that is already part of the target Active Directory domain. This grants it inherent access to domain information, network connectivity, and an active authentication session. Running it in restricted environments (e.g., without direct network access, through C2 tunnels, or with specific credential formats) can be challenging.
- Detection Risk: SharpHound is well-known and heavily targeted by security tools like Endpoint Detection and Response (EDR) solutions and Microsoft Defender for Identity. Running it blindly significantly increases the risk of detection and blocking.
Alternative Tools:
Bradshaw introduced two alternatives for specific scenarios:
- Python BloodHound: A Python implementation of a BloodHound collector. It offers cross-platform compatibility and greater flexibility in specifying authentication methods. However, it can still be reliant on good network access and DNS resolution, and the current main fork may not support the latest BloodHound UI features or new collection types (e.g., AD CS).
- ad-ldap-dumper (Speaker's Tool): Bradshaw developed this tool specifically for highly restricted environments.
- LDAP-Only: Focuses solely on LDAP enumeration, making it lightweight and specific.
- Highly Configurable: Written in Python, runs on multiple platforms, and supports various authentication options (anonymous, user/password, NTLM pass-the-hash, Kerberos tickets from CCACHE files).
- Minimum Required Access: Designed to function with minimal network access, requiring only connectivity to TCP 389 or 636 and valid credentials.
- Detection Evasion: Includes options to avoid certain service-side detection methods. Bradshaw noted that some of these evasion techniques became less critical after Microsoft removed certain LDAP query logging requirements, which previously posed significant performance and storage implications for domain controllers.
- BloodHound Output: The tool now supports generating BloodHound-compatible JSON output files, making its collected data consumable by the BloodHound GUI.
Defensive Strategies:
Given the widespread reliance on LDAP for AD enumeration, defenders must:
- Monitor LDAP Activity: Implement robust logging and monitoring for LDAP queries, particularly from low-privileged accounts, unusual sources, or queries targeting sensitive attributes (e.g.,
servicePrincipalName,userAccountControl,nTSecurityDescriptor). Look for high volumes of queries or queries executed outside of normal operational hours. - Enforce Least Privilege: Strictly adhere to the principle of least privilege for all Active Directory users and service accounts. While much information is readable by default, restricting write access and certain extended rights can limit abuse.
- Harden ACLs: Regularly audit and harden Active Directory ACLs to prevent misconfigurations that grant excessive control over critical objects (e.g., domain controllers, high-privileged groups, sensitive service accounts). Tools like BloodHound can help identify these weaknesses.
- Network Segmentation: Implement network segmentation to restrict direct LDAP access to domain controllers from untrusted network segments or user workstations.
- Secure LDAPS: Ensure that LDAPS (TCP 636) is properly configured with valid, trusted certificates to encrypt LDAP traffic and enable stronger authentication methods where required.
- Awareness of Tools: Be aware of common enumeration tools like SharpHound and their detection signatures. Implement EDR and other security controls that can identify and block their execution or associated activities.
- Understand Microsoft's Trade-offs: Be cognizant of Microsoft's decisions regarding security logging (e.g., the removal of certain LDAP query logging requirements). While these may improve performance, they can reduce visibility for defenders, necessitating alternative detection strategies.
Key Takeaways
- LDAP is the primary attack surface for Active Directory enumeration: It's the core protocol clients use to query AD, making it an invaluable source of intelligence for attackers.
- Low-privileged users can gather vast amounts of critical data: Default AD settings allow authenticated users to query information vital for lateral movement and privilege escalation, including user details, group memberships, computer objects, trust relationships, and ACLs.
- Understanding raw LDAP mechanics is crucial: While tools automate collection, a deep understanding of LDAP queries, authentication methods, and data parsing is essential for troubleshooting, custom tool development, and advanced attack scenarios.
- Tools like BloodHound streamline attack path identification: BloodHound, via collectors like SharpHound, effectively processes complex LDAP data (especially ACLs from
nTSecurityDescriptor) and visualizes relationships, making attack paths easily identifiable. - Parsing Active Directory ACLs is highly complex: Extracting abusable permissions from the binary
nTSecurityDescriptorattribute requires specific LDAP query controls (LDAP_SERVER_SD_FLAGS_OID) and intricate parsing of SIDs, GUIDs, and bitwise permission masks. - Defenders must actively monitor and secure LDAP: Implementing robust LDAP query logging, enforcing least privilege, hardening ACLs, segmenting networks, and securing LDAPS are critical steps to mitigate enumeration risks.
About the Speaker(s)
Stephen Bradshaw is a Principal Security Consultant in the offensive security team at SEEK. His work primarily focuses on internal offensive security, encompassing a range of activities such as pentesting, vulnerability hunting, red teaming, purple teaming, and developing and maintaining systems used in offensive security operations. His expertise lies in understanding complex systems like Active Directory from an attacker's perspective to help organizations improve their security posture.