Skip to content

Back to the Category Index / Back to the Command Index

Reads the owner from an LDAP object’s security descriptor and changes it to a specified SID.

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

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

ArgumentDescription
identitydomain.local/username[:password]
-ldaps / -use-ldapsUse LDAPS instead of LDAP.
-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 or Kerberos KDC IP address. Defaults to the domain (FQDN) in identity.
-dc-hostDomain controller or Kerberos KDC hostname. Uses -dc-ip if omitted.
-new-ownerNew owner’s sAMAccountName.
-new-owner-sidNew owner’s security identifier.
-new-owner-dnNew owner’s distinguished name.
-targetTarget sAMAccountName.
-target-sidTarget security identifier.
-target-dnTarget distinguished name.
-actionOperation on the owner attribute (choices: read, write; default: read).

The command resolves the target and new owner from a name, SID, or DN, then requests the descriptor’s owner security information. read displays the current owner; write changes only the owner field through LDAP modify.

The owner in a security descriptor is a separate field from the DACL’s ACEs. The command requests the owner portion through an LDAP security descriptor control and resolves both the target object and new owner principal from a name, SID, or DN. read converts the current owner SID to an account name if possible.

write replaces the owner field in the retrieved descriptor with a new SID and performs LDAP modify with an owner security information control mask. It does not rebuild the whole DACL, avoiding damage to unrelated ACEs, SACLs, and group data while signaling to the server that only the owner should change. Eligibility as a new owner and the caller’s right to change ownership are separate checks.

Distinguish SID resolution failures, zero or multiple object search results, and a lack of WRITE_OWNER permission. Ownership changes can affect later ACL editing rights, so on success record the target DN, old owner, and new owner without exposing secrets.

SymbolLocationEntry Point for Tracing Behavior
OwnerEdit111__init__(), read(), write(), search_target_principal_security_descriptor(), resolveSID()
parse_args()213Module function
main()250Module function
ModuleMain Names Used
impacketversion
impacket.exampleslogger, utils
impacket.ldapldaptypes
impacket.examples.utilsinit_ldap_session, parse_identity
Import NameDistribution PackageUsage / Declaration Status
ldap3ldap3Imported directly; declared dependency
ldapdomaindumpldapdomaindumpImported 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 uses ldap3, ldapdomaindump, ldaptypes, and the security descriptor control. OwnerEdit resembles dacledit, which handles DACLs, but changes only the owner. Preserve the control mask and unchanged portions of the descriptor.

  • Syntax: python -m py_compile examples/owneredit.py
  • CLI: python examples/owneredit.py -h
  • Related test: tests/SMB_RPC/test_ldap.py