Browse CTFs New CTF Sign in

LDAP Anonymous Reconnaissance: Unauthenticated Directory Traversal and User Attribute Harvesting

web_auth_sessions Difficulty 1–5 30 min certifiable

Theory

Why This Matters

LDAP anonymous enumeration has been documented in numerous enterprise penetration tests and red team engagements as one of the most information-dense reconnaissance techniques available when targeting organizations running Active Directory or OpenLDAP. A single anonymous LDAP query against a misconfigured domain controller can yield the complete organizational user list, group memberships, department structure, phone numbers, email addresses, and manager relationships — an intelligence windfall that would take days to reconstruct from public sources alone. Threat actors targeting corporate espionage and credential-stuffing campaigns use LDAP enumeration to build precise employee targeting lists. Security analysts and threat intelligence professionals use the same technique in authorized internal assessments to quantify data exposure risk from misconfigured directory services.

Core Concept

LDAP (Lightweight Directory Access Protocol) is a hierarchical directory service protocol operating on TCP port 389 (plaintext) and TCP port 636 (LDAP over SSL/TLS, also called LDAPS). Directories are organized as a tree of Distinguished Names (DNs), with the root called the base DN (e.g., dc=company,dc=com). Each node in the tree is an entry containing attributes (key-value pairs). User accounts are typically stored as entries with the objectClass user (Active Directory) or inetOrgPerson (OpenLDAP).

Anonymous bind is an LDAP authentication mode where a client sends an empty username and password. RFC 4513 permits directory servers to allow anonymous access, and many organizations enable it for compatibility with legacy applications or fail to disable it on domain controllers. An anonymous bind grants read access to whatever the server's access control lists (ACLs) permit for unauthenticated clients — which on misconfigured systems includes the entire directory.

Active Directory (Microsoft's LDAP implementation) exposes particularly rich attributes by default when anonymous access is permitted: sAMAccountName (Windows login name), userPrincipalName (email-format login), mail (email address), telephoneNumber, department, manager (DN of the user's manager — revealing org hierarchy), memberOf (group memberships), lastLogon (last logon timestamp), pwdLastSet (last password change), and userAccountControl (bitfield encoding account status including disabled, locked, password-never-expires flags).

OpenLDAP anonymous access is controlled by the olcAccess directive. The default configuration in many distributions grants read access to all attributes for anonymous users on the cn=config subtree. LDAP null base enumeration sends an empty base DN (-b "") to query the Root DSE — a special entry that all LDAP servers expose describing the server's capabilities, supported LDAP versions, naming contexts (the list of base DNs hosted), and schema information. This works even when the directory content is restricted, because the Root DSE is defined by RFC 4512 as always accessible.

Shodan indexes exposed LDAP servers (typically internet-facing misconfigured systems) via the port:389 filter. Combining with org: or ssl.cert.subject.cn: filters narrows results to the target organization. Censys provides similar LDAP port data with richer certificate information for LDAPS on port 636.

ldapsearch is the standard CLI tool for LDAP queries. The -x flag specifies simple authentication (instead of SASL), -H specifies the server URI, -b specifies the base DN, and an empty -D and -w perform the anonymous bind. The filter syntax (objectClass=user) retrieves all user objects; (memberOf=CN=Domain Admins,CN=Users,DC=company,DC=com) retrieves domain administrator members.

Technical Deep-Dive

# 1. Root DSE enumeration (works on all LDAP servers, even restricted ones)
ldapsearch -x -H ldap://target.company.com -b "" -s base 
  "(objectClass=*)" namingContexts supportedLDAPVersion
# Returns: namingContexts: dc=company,dc=com
#          supportedLDAPVersion: 3

# 2. Anonymous bind — enumerate all user objects
ldapsearch -x -H ldap://target.company.com 
  -b "dc=company,dc=com" 
  "(objectClass=user)" 
  cn mail sAMAccountName userPrincipalName department telephoneNumber manager
# Returns all user entries with the specified attributes

# 3. Enumerate group memberships (reveal org chart and privileged accounts)
ldapsearch -x -H ldap://target.company.com 
  -b "dc=company,dc=com" 
  "(objectClass=group)" 
  cn member description
# Look for: Domain Admins, IT, Finance, VPN-Users, etc.

# 4. Find members of Domain Admins specifically
ldapsearch -x -H ldap://target.company.com 
  -b "dc=company,dc=com" 
  "(memberOf=CN=Domain Admins,CN=Users,DC=company,DC=com)" 
  cn sAMAccountName mail

# 5. Enumerate Organizational Units (OU structure)
ldapsearch -x -H ldap://target.company.com 
  -b "dc=company,dc=com" 
  "(objectClass=organizationalUnit)" 
  ou description

# 6. LDAPS (port 636) — skip certificate validation for recon
ldapsearch -x -H ldaps://target.company.com:636 
  -b "dc=company,dc=com" 
  "(objectClass=user)" cn mail 
  -o "TLS_REQCERT=never"

# 7. Shodan discovery of exposed LDAP
shodan search 'port:389 org:"Company Name"' --fields ip_str,port,org,data
# Also: Censys for LDAPS with certificate fingerprinting

Intelligence Collection Methodology

  1. Discover LDAP endpoints using Shodan (port:389 org:"target") and Censys (services.port=389 with organization filter). Note both port 389 and port 636 endpoints. Correlate IP addresses with the target's known IP ranges from BGP.he.net ASN lookups.
  2. Query the Root DSE (ldapsearch -x -H ldap://target -b "" -s base "(objectClass=*)" namingContexts) to identify the base DN and supported LDAP version without attempting a full directory query. This is low-risk and works on restricted servers.
  3. Attempt an anonymous bind (ldapsearch -x -H ldap://target -b "dc=target,dc=com" "(objectClass=user)") to test whether anonymous access is permitted. A successful response containing user entries confirms the misconfiguration.
  4. If anonymous access is confirmed, systematically enumerate user objects (filter (objectClass=user)) requesting all high-value attributes: cn, mail, sAMAccountName, userPrincipalName, department, telephoneNumber, manager, memberOf, userAccountControl.
  5. Enumerate group objects ((objectClass=group)) to identify privileged groups (Domain Admins, Enterprise Admins, IT, VPN-Users). List members of high-value groups using the memberOf attribute filter.
  6. Enumerate Organizational Units ((objectClass=organizationalUnit)) to reconstruct the directory tree structure and identify department names.
  7. Cross-reference discovered user attributes with LinkedIn (verify employee names and departments), hunter.io (email format confirmation), and HaveIBeenPwned API (breach exposure of discovered email addresses).
  8. Compile a structured report mapping: base DN → OUs → groups → users with attributes. Flag accounts with userAccountControl flags indicating password-never-expires or account-not-required for immediate risk prioritization.

Common Intelligence Collection Errors

  • Querying with an overly broad filter without pagination: A single ldapsearch against a directory with 50,000 user objects may be truncated by the server's sizelimit (often 1,000 entries). Use the -z 0 flag to request unlimited results and the paged results control (-E pr=1000/noprompt) to retrieve results in pages.
  • Confusing LDAP filter syntax: LDAP uses prefix (Polish) notation for logical operators: (&(objectClass=user)(department=IT)) is the AND of two conditions. A common error is using && or writing filters in infix style, which returns an error rather than results.
  • Missing the userAccountControl attribute analysis: This integer bitfield contains critical account status flags. Bit 2 (0x0002) indicates a disabled account; bit 17 (0x10000) indicates DONT_EXPIRE_PASSWORD. Analysts who skip this attribute miss high-value targets like service accounts with non-expiring passwords.
  • Assuming port 389 equals plaintext and port 636 equals encrypted: Some Active Directory configurations use StartTLS on port 389 (upgrading to TLS after the initial plaintext connection). The ldapsearch -Z flag requests StartTLS. Treating port 389 as always plaintext may cause false assumptions about interception risk.
  • Overlooking the manager attribute as an org-chart source: The manager attribute contains the full DN of the user's manager. Iteratively resolving this attribute traces the management chain up to C-suite, constructing a complete org chart that may not be publicly available on the company website.
  • Not testing OpenLDAP vs Active Directory behavior differences: OpenLDAP defaults to denying anonymous access in recent versions; Active Directory may permit it via legacy settings. The same ldapsearch command may succeed against one and fail against the other. Always test both ports and confirm the directory implementation from banner data.

NICE Framework Alignment

Code Knowledge/Skill/Task Statement How This Card Develops It
K0058 Knowledge of network protocols Applying LDAP protocol mechanics: bind operations, search requests, filter syntax, and response handling on ports 389/636
K0145 Knowledge of security assessment approaches Conducting systematic directory enumeration from anonymous bind testing through full attribute extraction and org-chart reconstruction
K0272 Knowledge of network security architecture Understanding Active Directory and OpenLDAP architecture, the role of domain controllers, and LDAP ACL policy models
K0427 Knowledge of encryption algorithms Distinguishing LDAP, LDAPS, and StartTLS; assessing certificate validity on port 636 during LDAPS reconnaissance
S0040 Skill in identifying and extracting data of interest Extracting user accounts, group memberships, org structure, and privileged identities from exposed directory services
T0569 Apply and utilize authorized cyber capabilities to achieve objectives Using ldapsearch, Shodan, and Censys to enumerate LDAP directory exposure within authorized assessment scope

Further Reading

  • The Active Directory Security Reference — Sean Metcalf (adsecurity.org — search "Active Directory Security")
  • Penetration Testing Active Directory — Chapter 3: Enumeration Techniques (Offensive Security Training Materials)
  • LDAP System Administration — Gerald Carter, Chapter 5: Searching the Directory (O'Reilly Media)

Challenge Lab

Reinforce your learning with a hands-on generated challenge based on this card's competency.