Skip to content

Impacket regsecrets.py

Back to the category index / Back to the command index

Retrieves SAM hashes, LSA secrets, and cached credentials through Remote Registry. It does not target NTDS.

ItemDetails
Implementationexamples/regsecrets.py
CategorySecrets / DPAPI / registry / file analysis
Size251 lines
DistributionInstalled as a script through scripts=examples/*.py in setup.py

Run python examples/regsecrets.py -h for the current option definitions.

ArgumentDescription
target[[domain/]username[:password]@]
-tsAdd a timestamp to each log message
-debugEnable debug output
-systemSYSTEM hive to parse
-bootkeyBoot key for the SYSTEM hive
-nosamDo not retrieve SAM information
-nocacheDo not retrieve MSCache information
-nolsaDo not retrieve LSA secrets
-throttleDelay in seconds between operations
-outputfileBase output filename; extensions are added for SAM, secrets, and cached credentials
-historyDump password history (NTDS and SAM hashes) and LSA secret OldVal values
-hashesNTLM hashes in LMHASH:NTHASH format
-no-passDo not prompt for a password (useful with -k)
-kUse Kerberos authentication. Look for matching credentials in the ccache file named by KRB5CCNAME; if none are valid, use those specified on the command line
-aesKeyAES key for Kerberos authentication (128 or 256 bits)
-keytabRead SPN keys from a keytab file
-dc-ipDomain controller IP address; if omitted, use the domain name (FQDN) from the target parameter
-target-ipTarget machine IP address; if omitted, use the target value. Useful when a NetBIOS target name cannot be resolved

After connecting over SMB, RemoteOperations prepares access to the boot key and registry data. The tool prefers a supplied SYSTEM hive or boot key, then runs SAMHashes and LSASecrets according to the options and handles history and output files. Finally, it cleans up temporary hives, RemoteRegistry state, and connections.

Decrypting SAM and LSA secrets requires a boot key specific to the target machine. DumpSecrets creates an SMB session, and RemoteOperations reconstructs the boot key from LSA class data in the SYSTEM hive. If an explicit -bootkey or local SYSTEM file is available, it switches to a path that avoids remote retrieval.

SAMHashes derives the SAM domain account encryption key from the boot key and uses each user’s RID to decrypt LM and NT hash fields. LSASecrets derives the SECURITY policy key and decrypts LSA secrets and cached domain logon records according to their versions and algorithms. SAM and the LSA cache do not use the same encryption format, even within the same hive.

Remote retrieval may use the Registry service and temporary hive or file access. -nosam, -nocache, and -nolsa should skip unnecessary remote operations as well as their decoders. Output files contain secrets, so identify what was saved on partial success and restore service state and temporary resources in cleanup().

SymbolLocationWhere to trace its responsibility
DumpSecrets66__init__(), connect(), dump(), cleanup()
ModuleMain names used
impacketversion
impacket.exampleslogger
impacket.examples.utilsparse_target
impacket.smbconnectionSMBConnection
impacket.examples.regsecretsLSASecrets, RemoteOperations, SAMHashes
impacket.krb5.keytabKeytab

Output, side effects, and required privileges

Section titled “Output, side effects, and required privileges”
  • The tool primarily makes queries and authentication attempts. Frequent runs can affect audit logs, account lockouts, and target load.
  • Options may create or update local files. Check how existing files are handled and the permissions on output containing secrets.
  • Some paths use temporary resources such as remote services, tasks, files, shares, and WMI/RPC resources. Cleaning them up after an abnormal exit is part of the behavior contract.
  • On failure, use protocol status codes to determine whether name resolution, connection, authentication, service state, or permissions caused the stop.
  • Cleanup-related methods include cleanup(). Check that new early returns and exception paths reach it too.

The code depends on SMBConnection, RemoteOperations, SAMHashes, and LSASecrets from impacket.examples.regsecrets, plus keytabs. CLI class DumpSecrets handles orchestration rather than decoding secrets itself.

  • Syntax: python -m py_compile examples/regsecrets.py
  • CLI: python examples/regsecrets.py -h
  • No test specific to this command was found. Choose shared-module tests and, if needed, a run in an isolated environment.