Skip to content

Back to the Category Index / Back to the Command Index

Changes a user’s own password or performs an administrator reset through Kerberos kpasswd, SAMR, or LDAP.

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

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

ArgumentDescription
target[[domain/]username[:password]@]<hostname or address>
-tsAdd timestamps to log output.
-debugEnable debug logging.
-newpassNew password.
-newhashesNew NTLM hashes in NTHASH or LMHASH:NTHASH format.
-hashesNTLM hashes in NTHASH or LMHASH:NTHASH format.
-no-passSkip the password prompt (useful with Kerberos -k).
-altuserAlternative username
-altpassAlternative password
-althash / -althashesAlternative NT hash in NTHASH or LMHASH:NTHASH format.
-protocol / -pProtocol for password change or reset. Choices: smb-samr, rpc-samr, kpasswd, ldap. Default: smb-samr.
-reset / -adminAttempt an administrator password reset (may bypass some password policies).
-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 for Kerberos. Defaults to the domain (FQDN) in the target parameter.

parse_args() validates the target credentials, new password/hash, and alternate administrator credentials. -protocol selects KPassword, SmbPassword, RpcPassword, or LdapPassword. The shared PasswordHandler interface separates change from set; each backend handles authentication, target resolution, and protocol-specific requests.

Changing a password and resetting it are separate operations. A change normally proves the target user’s old credentials before moving to a new value. A reset sets the target account’s value using the privileges of another principal, such as an administrator. PasswordHandler separates them into changePassword() and setPassword(), and each backend implements the corresponding wire operation.

The Kerberos backend sends a request with an AP-REQ to the kpasswd service. The SAMR backend chooses a user handle and password method over an SMB named pipe or TCP RPC. The LDAP backend finds the target DN and converts the action to a unicodePwd modify on a TLS-protected connection. Which backends accept a password or NT hash and whether old credentials are required vary by backend.

The -altuser options separate the actor from the target. Overwriting these as one credential set breaks the distinction between reset and self-change. Password policy violations, wrong old passwords, access denied, and missing secure channels call for different responses; preserve protocol-specific status upstream.

SymbolLocationEntry Point for Tracing Behavior
PasswordHandler137__init__(), changePassword(), setPassword()
KPassword251Structure and constant definitions
SamrPassword321rpctransport(), authenticate(), connect(), hSamrOpenUser(), hSamrUnicodeChangePasswordUser2(), hSamrChangePasswordUser(), hSamrSetInformationUser()
RpcPassword566rpctransport()
SmbPassword591rpctransport()
LdapPassword596connect(), encodeLdapPassword(), findTargetDN()
parse_args()743Module function
ModuleMain Names Used
impacketversion
impacket.dcerpc.v5epm, samr, transport
impacket.krb5kerberosv5, kpasswd
impacket.ldapldap, ldapasn1
impacket.exampleslogger
impacket.examples.utilsEMPTY_LM_HASH, parse_target
Import NameDistribution PackageUsage / Declaration Status
OpenSSLpyOpenSSLImported directly; declared dependency

Output, Side Effects, and Required Privileges

Section titled “Output, Side Effects, and Required Privileges”
  • Some operations change the target’s state. Confirm the target name, SID, and path before making changes.
  • On failure, use protocol status to determine whether name resolution, connection, authentication, service state, or permissions stopped the operation.

This command depends on krb5.kpasswd / kerberosv5, dcerpc.v5.samr, ldap / ldapasn1, and OpenSSL. Reset and change require different privileges and wire operations; do not conflate them in shared code.