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

FlagEffect
-xSimple auth (vs SASL)
-D / -wBind DN / password
-bSearch base DN
-s baseScope to the base object only

Used in

§ home
~/knubertus/home/
1,1 Top