pentesting, updated
ldapsearch
Command-line LDAP client for querying a directory server directly — binds, searches and filters.
What it’s for
Query an LDAP/Active Directory service manually: discover naming contexts, bind anonymously or with credentials, and run arbitrary search filters.
Install
# ships with openldap-clients / ldap-utils — apt install ldap-utils
Common commands
ldapsearch -x -H ldap://10.10.10.5 -s base namingcontexts # discover the base DN
ldapsearch -x -H ldap://10.10.10.5 -b "DC=corp,DC=local" # anonymous bind, dump everything
ldapsearch -x -H ldap://10.10.10.5 -D "user@corp.local" -w pass \
-b "DC=corp,DC=local" "(objectClass=user)" sAMAccountName description
ldapsearch -x -H ldap://10.10.10.5 -b "DC=corp,DC=local" \
"(&(objectClass=user)(adminCount=1))" sAMAccountName # find privileged accounts
Useful flags
| Flag | Effect |
|---|---|
-x | Simple auth (vs SASL) |
-D / -w | Bind DN / password |
-b | Search base DN |
-s base | Scope to the base object only |