Skip to content

Back to the Category Index / Back to the Command Index

Creates, modifies, and deletes delegated Managed Service Accounts (dMSAs), and examines related AD attributes.

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

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

ArgumentDescription
accountAccount used to authenticate to the DC.
-dmsa-nameName of the dMSA to add. Defaults to a random dMSA-[A-Z0-9]{8} name.
-actionAction to perform: add (requires -target-ou), delete (requires -dmsa-name and -target-ou), modify (requires -dmsa-name, -target-ou, and -target-account), or search a dMSA. Choices: add, delete, modify, search. Default: search.
-target-ouOU to check for dMSA creation permissions, such as OU=weakOU,DC=domain,DC=local.
-principals-allowedUser allowed to retrieve the managed password. Defaults to the current user.
-target-accountTarget user or computer account DN for msDS-ManagedAccountPrecededByLink (can target Domain Controllers, Domain Admins, Protected Users, etc.). Default: Administrator.
-dns-hostnameDNS hostname for the dMSA. Defaults to dmsaname.domain.
-tsAdd timestamps to log output.
-debugEnable debug logging.
-methodMethod of adding the computer. LDAPS has certificate requirements and is not always available. Choices: LDAP, LDAPS. Default: LDAPS.
-portDestination port. LDAP defaults to 389; LDAPS to 636. Choices: 389, 636.
-baseDNLDAP base DN. Defaults to the domain (FQDN) in the account parameter.
-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 account; fall back to command-line credentials if none are valid.
-aesKey128- or 256-bit AES key for Kerberos authentication.
-dc-hostHostname of the domain controller. Defaults to the domain (FQDN) in the account parameter.
-dc-ipIP address of the domain controller. Useful when the FQDN cannot be resolved.

After creating an LDAP session, the command searches OUs, checks account existence, builds a security descriptor, and adds or changes a dMSA object according to the action. It resolves SIDs to names and validates allowed principals and the target account before writing.

Rather than adding a dMSA object in the same way as a normal user or computer, the command sets dMSA-specific schema attributes and links to the account being migrated. search_ous() and check_account_exists() first validate the destination and referenced account. build_security_descriptor() converts the SIDs of principals permitted to use the dMSA into an access control structure.

add_dmsa() creates the object with its objectClass, account name, DNS hostname, and attributes required for a managed account. modify_dmsa() updates the target account or allowed principals on an existing object. Add and modify are separate because LDAP add and modify have different failure units and to avoid removing unexpected attributes from an existing object.

SID exclusions, OU selection, and generated names are safeguards, not merely display aids: they prevent targeting the wrong privileged principal or a protected container. Because behavior depends on the Windows Server schema and functional level, do not treat noSuchAttribute or objectClassViolation as a generic authentication error. Determine whether the target DC understands dMSAs.

SymbolLocationEntry Point for Tracing Behavior
BADSUCCESSOR34__init__(), run(), delete_dmsa(), check_account_exists(), search_ous(), is_excluded_sid(), resolve_sid_to_name(), generate_dmsa_name(), convert_sid_to_string(), build_security_descriptor(), add_dmsa(), modify_dmsa()
ModuleMain Names Used
impacketversion
impacket.exampleslogger
impacket.examples.utilsinit_ldap_session, parse_identity, parse_target
impacket.ldapldaptypes
Import NameDistribution PackageUsage / Declaration Status
ldap3ldap3Imported 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.

The command uses ldap3, impacket.ldap.ldaptypes, and init_ldap_session; BADSUCCESSOR owns the processing. Because it depends heavily on schema and functional level, check changes to attribute names, objectClass, and SID exclusion rules against the corresponding Windows Server generation.

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