AD^:Active Directory

LDAP Enumeration

Manual ldapsearch queries to enumerate AD: users, groups, computers, ACLs, SPNs and attributes.

intermediateupdated 2026-08-09ldapsearch

LDAP Enumeration

Manual ldapsearch reference against Active Directory. The worked examples below use the credentials from the HTB Support box:

Example credentials:

  • Username: ldap@support.htb
  • Password: nvEfEK16^1aM4$e7AclUf8x$tRWxPWO1%lmz
  • Domain: support.htb
  • Base DN: DC=support,DC=htb

Basic ldapsearch Syntax

Initial Reconnaissance

Get Naming Contexts (Anonymous)

ldapsearch -x -H ldap://support.htb -b "" -s base namingContexts

Test Authentication

ldapsearch -x -H ldap://support.htb \
  -D 'ldap@support.htb' \
  -w 'nvEfEK16^1aM4$e7AclUf8x$tRWxPWO1%lmz' \
  -b "DC=support,DC=htb" \
  -s base

Full Domain Dump

ldapsearch -x -H ldap://support.htb \
  -D 'ldap@support.htb' \
  -w 'nvEfEK16^1aM4$e7AclUf8x$tRWxPWO1%lmz' \
  -b "DC=support,DC=htb" | less
ldapsearch -LLL -x -H ldap://support.htb \
  -D 'ldap@support.htb' \
  -w 'nvEfEK16^1aM4$e7AclUf8x$tRWxPWO1%lmz' \
  -b "DC=support,DC=htb"

User Enumeration

All Users

ldapsearch -x -H ldap://support.htb \
  -D 'ldap@support.htb' \
  -w 'nvEfEK16^1aM4$e7AclUf8x$tRWxPWO1%lmz' \
  -b "DC=support,DC=htb" \
  "(objectClass=person)" cn mail

All AD User Objects

ldapsearch -x -H ldap://support.htb \
  -D 'ldap@support.htb' \
  -w 'nvEfEK16^1aM4$e7AclUf8x$tRWxPWO1%lmz' \
  -b "DC=support,DC=htb" \
  "(&(objectClass=user)(objectCategory=person))" \
  sAMAccountName mail displayName

Users with Extended Attributes

ldapsearch -x -H ldap://support.htb \
  -D 'ldap@support.htb' \
  -w 'nvEfEK16^1aM4$e7AclUf8x$tRWxPWO1%lmz' \
  -b "DC=support,DC=htb" \
  "(objectClass=user)" \
  sAMAccountName mail userAccountControl description info memberOf

Search for Passwords in Description/Info Fields

# Check description fields
ldapsearch -x -H ldap://support.htb \
  -D 'ldap@support.htb' \
  -w 'nvEfEK16^1aM4$e7AclUf8x$tRWxPWO1%lmz' \
  -b "DC=support,DC=htb" \
  "(description=*)" description cn | grep -i "pass\|pwd"

# Check info field (critical for this box!)
ldapsearch -x -H ldap://support.htb \
  -D 'ldap@support.htb' \
  -w 'nvEfEK16^1aM4$e7AclUf8x$tRWxPWO1%lmz' \
  -b "DC=support,DC=htb" \
  "(info=*)" info cn sAMAccountName

Find a Specific User

ldapsearch -x -H ldap://support.htb \
  -D 'ldap@support.htb' \
  -w 'nvEfEK16^1aM4$e7AclUf8x$tRWxPWO1%lmz' \
  -b "DC=support,DC=htb" \
  "(cn=support)" \
  cn info memberOf distinguishedName

Active Users Only (Exclude Disabled)

ldapsearch -x -H ldap://support.htb \
  -D 'ldap@support.htb' \
  -w 'nvEfEK16^1aM4$e7AclUf8x$tRWxPWO1%lmz' \
  -b "DC=support,DC=htb" \
  '(&(objectClass=user)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))' \
  sAMAccountName cn

Service Accounts (Kerberoastable)

ldapsearch -x -H ldap://support.htb \
  -D 'ldap@support.htb' \
  -w 'nvEfEK16^1aM4$e7AclUf8x$tRWxPWO1%lmz' \
  -b "DC=support,DC=htb" \
  "(&(objectClass=user)(servicePrincipalName=*))" \
  sAMAccountName servicePrincipalName

Group Enumeration

All Groups

ldapsearch -x -H ldap://support.htb \
  -D 'ldap@support.htb' \
  -w 'nvEfEK16^1aM4$e7AclUf8x$tRWxPWO1%lmz' \
  -b "DC=support,DC=htb" \
  "(objectClass=group)" cn description member

Groups with “Admin” in Name

ldapsearch -LLL -x -H ldap://support.htb \
  -D 'ldap@support.htb' \
  -w 'nvEfEK16^1aM4$e7AclUf8x$tRWxPWO1%lmz' \
  -b "DC=support,DC=htb" \
  "(&(objectClass=group)(name=*admin*))" name sAMAccountName member

A Named Group’s Members

ldapsearch -x -H ldap://support.htb \
  -D 'ldap@support.htb' \
  -w 'nvEfEK16^1aM4$e7AclUf8x$tRWxPWO1%lmz' \
  -b "DC=support,DC=htb" \
  "(cn=Remote Management Users)" member

Domain Admins

ldapsearch -x -H ldap://support.htb \
  -D 'ldap@support.htb' \
  -w 'nvEfEK16^1aM4$e7AclUf8x$tRWxPWO1%lmz' \
  -b "DC=support,DC=htb" \
  "(cn=Domain Admins)" member

A User’s Group Memberships

ldapsearch -x -H ldap://support.htb \
  -D 'ldap@support.htb' \
  -w 'nvEfEK16^1aM4$e7AclUf8x$tRWxPWO1%lmz' \
  -b "DC=support,DC=htb" \
  "(sAMAccountName=support)" memberOf

Computer Enumeration

All Computers

ldapsearch -x -H ldap://support.htb \
  -D 'ldap@support.htb' \
  -w 'nvEfEK16^1aM4$e7AclUf8x$tRWxPWO1%lmz' \
  -b "DC=support,DC=htb" \
  "(objectClass=computer)" cn operatingSystem dNSHostName

Domain Controllers Only

ldapsearch -x -H ldap://support.htb \
  -D 'ldap@support.htb' \
  -w 'nvEfEK16^1aM4$e7AclUf8x$tRWxPWO1%lmz' \
  -b "DC=support,DC=htb" \
  "(userAccountControl:1.2.840.113556.1.4.803:=8192)" cn dNSHostName

Computers with Unconstrained Delegation

ldapsearch -x -H ldap://support.htb \
  -D 'ldap@support.htb' \
  -w 'nvEfEK16^1aM4$e7AclUf8x$tRWxPWO1%lmz' \
  -b "DC=support,DC=htb" \
  "(userAccountControl:1.2.840.113556.1.4.803:=524288)" cn

Organizational Units

ldapsearch -x -LLL -H ldap://support.htb \
  -D 'ldap@support.htb' \
  -w 'nvEfEK16^1aM4$e7AclUf8x$tRWxPWO1%lmz' \
  -b "DC=support,DC=htb" \
  -s sub \
  "(|(objectClass=organizationalUnit)(objectClass=group))"

Operational Attributes

# Get all operational attributes
ldapsearch -x -H ldap://support.htb \
  -D 'ldap@support.htb' \
  -w 'nvEfEK16^1aM4$e7AclUf8x$tRWxPWO1%lmz' \
  -b "DC=support,DC=htb" \
  "(objectClass=*)" '+'

# Specific operational attributes
ldapsearch -x -H ldap://support.htb \
  -D 'ldap@support.htb' \
  -w 'nvEfEK16^1aM4$e7AclUf8x$tRWxPWO1%lmz' \
  -b "DC=support,DC=htb" \
  "(objectClass=*)" \
  creatorsName createTimestamp modifiersName modifyTimestamp

Modern Tools

ldapdomaindump

# Comprehensive domain dump
ldapdomaindump -u 'support.htb\ldap' \
  -p 'nvEfEK16^1aM4$e7AclUf8x$tRWxPWO1%lmz' \
  support.htb \
  -o ldap_output

# Output creates:
# - domain_users.json/html
# - domain_groups.json/html
# - domain_computers.json/html
# - domain_trusts.json/html
# - domain_policy.json/html

BloodHound Python

bloodhound-python -c All \
  -u ldap \
  -p 'nvEfEK16^1aM4$e7AclUf8x$tRWxPWO1%lmz' \
  -d support.htb \
  -ns 10.10.11.174

NetExec (formerly CrackMapExec)

# Verify credentials
nxc smb support.htb \
  -u ldap \
  -p 'nvEfEK16^1aM4$e7AclUf8x$tRWxPWO1%lmz'

# LDAP enumeration
nxc ldap support.htb \
  -u ldap \
  -p 'nvEfEK16^1aM4$e7AclUf8x$tRWxPWO1%lmz' \
  --users --groups --computers

Secure Alternative (Password Prompt)

Instead of putting the password in the command, use -W for a prompt:

ldapsearch -x -H ldap://support.htb \
  -D 'ldap@support.htb' \
  -W \
  -b "DC=support,DC=htb"

LDAPS (Secure LDAP)

ldapsearch -x -H ldaps://support.htb:636 \
  -D 'ldap@support.htb' \
  -w 'nvEfEK16^1aM4$e7AclUf8x$tRWxPWO1%lmz' \
  -b "DC=support,DC=htb"

Key Takeaways

  1. Always use -H ldap:// instead of the deprecated -h hostname flag
  2. Add -x for simple authentication in modern versions
  3. Use -LLL for cleaner output
  4. The info field contained the password for the support user in this box
  5. Check group memberships — Remote Management Users = WinRM access

Command-Line Flags Reference

FlagLong FormDescriptionExample
-H--uriLDAP URI to connect to (replaces deprecated -h)-H ldap://support.htb
-h--hostDEPRECATED hostname (use -H instead)-h support.htb
-p--portPort number (default: 389 for LDAP, 636 for LDAPS)-p 389
-D--binddnBind Distinguished Name for authentication-D 'ldap@support.htb'
-w--bindpwBind password (plaintext — visible in process list)-w 'password'
-W--bindpw-promptPrompt for bind password (more secure)-W
-y--bindpw-fileRead password from file-y /path/to/passfile
-b--basednBase Distinguished Name for search-b "DC=support,DC=htb"
-s--scopeSearch scope: base, one, sub, children-s sub
-x--simpleUse simple authentication instead of SASL-x
-Z--starttlsIssue StartTLS extended operation-Z
-LN/ALDIFv1 format (one -L)-L
-LLN/ADisable comments in output (two -L)-LL
-LLLN/ADisable comments and version (three -L, cleanest)-LLL
-v--verboseVerbose output-v
-d--debugDebug level (0-9, higher = more verbose)-d 1
-AN/ARetrieve attribute names only (no values)-A
-l--timelimitTime limit for search in seconds-l 30
-z--sizelimitSize limit for number of entries returned-z 100
-SN/ASort results by specified attribute-S cn
-E--extensionsLDAP extensions (e.g. paging)-E pr=1000/noprompt
-oN/ASet general options-o ldif-wrap=no
-nN/AShow what would be done (dry run)-n
-MN/AEnable Manage DSA IT control-M
-CN/AChase referrals-C
-cN/AContinuous operation mode (ignore errors)-c

Search Scope Values

ScopeDescription
baseSearch only the base DN itself
oneSearch immediate children of base DN only (one level)
subSearch base DN and all descendants (subtree — most common)
childrenSearch all descendants but not the base DN itself

Common Attribute Shortcuts

ShortcutMeaning
*All regular (non-operational) attributes
+All operational attributes
1.1No attributes (DN only)
* +All attributes (regular + operational)

LDAP URI Format

FormatDescription
ldap://hostStandard LDAP on port 389
ldap://host:portLDAP on custom port
ldaps://hostLDAP over SSL/TLS on port 636
ldaps://host:portLDAPS on custom port
ldapi://LDAP over Unix domain socket (local)

Common Exit Codes

CodeMeaning
0Success
1Operations error
2Protocol error
32No such object
49Invalid credentials
50Insufficient access rights

Pro Tips

  1. Always use -LLL for clean, parseable output
  2. Use -W instead of -w to avoid the password in shell history
  3. The info field in AD often contains sensitive data
  4. Check group memberships — Remote Management Users = WinRM access
  5. Operational attributes (+) reveal creation/modification metadata
  6. Use sub scope for comprehensive searches
  7. Combine filters with & (AND) and | (OR) for precise queries
  8. Save output to files for offline analysis with > output.txt
On this page

☧ CPTS · ordered posts

Locked

Unlock with your Main_Key through local GPG.

Start the local GPG helper

In your cheatsheet checkout, run:

npm run unlock:helper

Open the link it prints, or paste its pairing code below. Keep the terminal open until GPG finishes.

Import an index you already decrypted

Download the encrypted index, then decrypt with GPG:

gpg --output report-index.json --decrypt report-index.gpg

Your private key stays in GPG. The decrypted index is saved in this browser so you can reopen it after navigation, refreshes and restarts. Lock this browser or clear this site's browser data to remove the saved index. Nothing is uploaded.