Skip to content

Back to the Category Index / Back to the Command Index

Retrieves users’ email addresses, password change times, last logon times, and other details from LDAP. By default, it targets active users.

ItemDetails
Implementationexamples/GetADUsers.py
CategoryActive Directory / LDAP / Account Management
Size195 lines
DistributionInstalled as a script through scripts=examples/*.py in setup.py

Check python examples/GetADUsers.py -h for the current option definitions.

ArgumentDescription
targetdomain[/username[:password]]
-userRequest data for a specific user.
-allReturn all users, including those without email addresses and disabled accounts. With -user, return that user even if the account is disabled.
-tsAdd timestamps to log output.
-debugEnable debug logging.
-hashesNTLM hashes in LMHASH:NTHASH format.
-no-passSkip the password prompt (useful with -k).
-kUse Kerberos authentication. Read credentials from the ccache (KRB5CCNAME) based on the target; fall back to command-line credentials if none are valid.
-aesKey128- or 256-bit AES key for Kerberos authentication.
-dc-ipDomain controller IP address. Defaults to the domain (FQDN) in target.
-dc-hostDomain controller hostname. Defaults to the domain (FQDN) in the account parameter.
-ldaps / -use-ldapsUse LDAPS instead of LDAP.

The command resolves the identity and authentication method, binds to LDAP, searches for users, converts the records, and prints a table. processRecord() handles FILETIME values and account-control flags.

This command is an LDAP reader that lists user objects; it does not read the SAM database directly. run() applies a user filter to the domain naming context. -user selects one sAMAccountName; without -all, the results are limited mainly to active accounts in regular use. Where the LDAP server’s size limit is exceeded, library search/paging behavior also affects the result count.

processRecord() converts raw LDAP attributes into table rows. For example, pwdLastSet and lastLogon are FILETIME values, userAccountControl is a bit field, and mail or description may have multiple values. A missing value is not the same as an empty string. When adding optional schema attributes, account for absent, NULL, and multivalued cases.

The displayed lastLogon value belongs to the queried DC and may differ from the replicated lastLogonTimestamp. Do not interpret this output as the exact last logon across the entire domain. When developing the command, keep the search filter’s meaning aligned with the AD attribute named by each display label.

SymbolLocationEntry Point for Tracing Behavior
GetADUsers38__init__(), getUnixTime(), processRecord(), run()
ModuleMain Names Used
impacketversion
impacket.dcerpc.v5.samrUF_ACCOUNTDISABLE
impacket.exampleslogger
impacket.examples.utilsldap_login, parse_identity
impacket.ldapldap, ldapasn1

Output, Side Effects, and Required Privileges

Section titled “Output, Side Effects, and Required Privileges”
  • Primarily queries and authentication attempts. Repeated runs can affect audit logs, account lockouts, and target load.
  • On failure, use protocol status to determine whether name resolution, connection, authentication, service state, or permissions stopped the operation.

This command uses impacket.ldap.ldap / ldapasn1, examples.utils.parse_identity / ldap_login, and SAMR constants. If you add retrieved attributes, also test for missing values in anonymous or restricted-permission environments.