Skip to content

Back to the Category Index / Back to the Command Index

Queries LSA for SIDs formed from successive RIDs to enumerate the domain SID and associated account names.

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

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

ArgumentDescription
target[[domain/]username[:password]@]<targetName or address>
maxRidMaximum RID to check (default: 4000).
-debugEnable debug logging.
-tsAdd timestamps to log output.
-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).
-domain-sidsEnumerate domain SIDs (likely forwarding requests to the DC).
-hashesNTLM hashes in LMHASH:NTHASH format.
-no-passSkip the password prompt (useful when proxying through smbrelayx).
-kUse Kerberos authentication. Read credentials from the ccache (KRB5CCNAME) based on the target; fall back to command-line credentials if none are valid.

The command binds to LSARPC over an SMB named pipe and obtains the domain SID from policy information. It appends RIDs to that SID and repeats lookups, displaying resolved SIDs, types, and names. -domain-sids focuses on reporting discovered domain SIDs.

LSA lookup is not an API that returns a list of names. Instead, the command builds candidate SIDs by adding RIDs in sequence to the domain SID and asks the server to resolve them. It first obtains the account domain SID from a policy handle, then sends batches of S-1-5-...-RID values to LsarLookupSids to discover users, groups, and aliases.

Many RIDs do not exist, so STATUS_NONE_MAPPED and STATUS_SOME_NOT_MAPPED are normal responses during enumeration. Even when only some SIDs in a batch resolve, the translated-name array must be matched correctly to domain-list indexes. Ending on every exception would stop the search at the first gap in the RID range.

The result is not a complete list of directory objects. Deleted RIDs, lookup permissions, the RID limit, and other domain SIDs affect what appears. -domain-sids focuses on collecting discovered domain information, but the output must distinguish guessed SIDs from domain names returned by the server.

SymbolLocationEntry Point for Tracing Behavior
LSALookupSid36__init__(), dump()
ModuleMain Names Used
impacket.exampleslogger
impacket.examples.utilsparse_target
impacketversion
impacket.dcerpc.v5lsad, lsat, transport
impacket.dcerpc.v5.samrSID_NAME_USE
impacket.dcerpc.v5.dtypesMAXIMUM_ALLOWED
impacket.dcerpc.v5.rpcrtDCERPCException

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 dcerpc.v5.transport / lsad / lsat and the shared target parser. LSALookupSid.dump() handles connection and enumeration, and must treat STATUS_SOME_NOT_MAPPED as a normal search result.