Skip to content

Back to the Category Index / Back to the Command Index

Uses SAMR to query and change users and groups, much like Windows net user and net group.

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

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

Subcommands: user, computer, localgroup, group

ArgumentDescription
target[[domain/]username[:password]@]<targetName or address>
-debugEnable debug logging.
-tsAdd timestamps to log output.
-nameDisplay information about one user.
-createAdd a user account to the domain or computer.
-removeRemove a user account from the domain or computer.
-newPasswdPassword to set when creating an account.
-enableEnable the account.
-disableDisable the account.
-joinAdd a user account to a specified group.
-unjoinRemove a user account from a specified group.
-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.
-target-ipTarget machine IP address. Defaults to target; useful when the target is a NetBIOS name that cannot be resolved.
-portDestination SMB server port (choices: 139, 445; default: 445).

The command connects to SAMR/LSA over SMB transport and selects User, Computer, Group, or Localgroup from the subcommand. After resolving object RIDs/SIDs and handles, it enumerates, creates, deletes, enables, or joins/unjoins groups as requested, then closes handles and connections.

The command offers an interface similar to Windows net, but operates directly on the SAMR object model. It first resolves the server handle, domain SID, and domain handle, then resolves RIDs and opens object handles for the user, computer, group, or localgroup subcommand. Resolving a name to a RID and reading details from that RID are separate RPC calls.

User and Computer handle account creation, deletion, queries, passwords, and UAC changes. Group handles domain groups; Localgroup handles aliases, so membership operations use different SAMR APIs and SID scopes. LsaTranslator converts between names and SIDs for display and member selection, separately from SAMR operations.

RPC handles have parent-child relationships. Open user, group, and domain handles must be closed even after an intermediate failure. Enumeration may take more than one request, so continuation status is part of the normal path. For a new subcommand, follow the existing object class boundaries for name resolution, handle acquisition, operations, and handle closure.

SymbolLocationEntry Point for Tracing Behavior
LsaTranslator49__init__(), Connect(), LookupName(), LookupSids()
SamrObject76__init__()
User141__init__(), Enumerate(), Query(), Create(), Remove(), SetUserAccountControl()
Computer247__init__()
Group254Enumerate(), Query(), Join(), UnJoin()
Localgroup296Enumerate(), Query(), Join(), UnJoin()
Net338__init__(), connect(), disconnect(), run()
ModuleMain Names Used
impacketversion
impacket.exampleslogger
impacket.examples.utilsparse_target
impacket.dcerpc.v5lsad, lsat, samr, transport
impacket.smbconnectionSMBConnection

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.
  • _close_domain() and disconnect() handle cleanup. Check that new early returns and exception paths still reach them.

This command uses dcerpc.v5.samr / lsad / lsat / transport and SMBConnection. SamrObject handles common handle operations, while LsaTranslator converts between SIDs and names.