Information Gathering
ldapsearch is a shell-accessible interface to the ldap_search_ext library function, designed to open active queries against corporate Active Directory database frameworks.
sudo apt install ldap-utils
ldapsearch [options]
LDAPsearch is a command-line tool from the OpenLDAP project for querying LDAP directories. It sends LDAP search requests to directory servers and returns matching entries, making it essential for Active Directory enumeration.
In Windows environments, Active Directory stores all domain information in an LDAP-accessible directory. LDAPsearch can query this directory to enumerate users, groups, computers, organizational units, group policies, and domain trusts.
The tool supports complex LDAP filters for precise queries, attribute selection for targeted data extraction, and various output formats. It is the foundation tool for AD enumeration in penetration testing.
ldapsearch -x -h 192.168.1.1 -b "dc=example,dc=com"Anonymous search - Query target LDAP directory schemas using simple authentication modelsldapsearch -x -H ldap://192.168.1.1 -s base namingcontextsGet base DNldapsearch -x -H ldap://192.168.1.1 -b "DC=domain,DC=com"Dump all objectsldapsearch -x -H ldap://192.168.1.1 -b "DC=domain,DC=com" "(objectClass=user)"List usersldapsearch -x -H ldap://192.168.1.1 -b "DC=domain,DC=com" "(objectClass=group)"List groupsldapsearch -x -H ldap://192.168.1.1 -D "user@domain.com" -W -b "DC=domain,DC=com"Authenticated queryldapsearch -x -h 192.168.1.100 -b 'DC=example,DC=com'Basic LDAP searchldapsearch -x -h 192.168.1.100 -b 'DC=example,DC=com' '(objectClass=user)'Search for user objectsldapsearch -x -h 192.168.1.100 -b 'DC=example,DC=com' '(objectClass=computer)'Search for computer objectsldapsearch -x -h 192.168.1.100 -b 'DC=example,DC=com' '(memberOf=CN=Admins)'Search by group membershipldapsearch -x -h 192.168.1.100 -b 'DC=example,DC=com' -D 'CN=admin,DC=example,DC=com' -WAuthenticated bindldapsearch -x -h 192.168.1.100 -b 'DC=example,DC=com' '(servicePrincipalName=*)' servicePrincipalNameKerberoastable accountsldapsearch -x -h 192.168.1.100 -b 'DC=example,DC=com' '(userAccountControl:1.2.840.113556.1.4.803:=8192)'Find domain controllersldapsearch -x -h 192.168.1.100 -b 'CN=Configuration,DC=example,DC=com' '(objectClass=domainDNS)'Query configuration partitionldapsearch -x -h 192.168.1.100 -b 'DC=example,DC=com' '(adminCount=1)'Find privileged accountsExtract all user accounts from Active Directory.
Enumerate security groups and their members.
Discover domain-joined computers and their details.
Query Group Policy Objects and configurations.
Discover domain trusts and forest relationships.
This tool is designed for authorized security testing, educational purposes, and legitimate network administration only. Unauthorized access to computer systems is illegal.