Feature/trust-keys (TDO secrets dump) - #1321
Conversation
Expose impacket secretsdump's trust key extraction (fortra/impacket#2207) through NetExec's --ntds: dumps Trusted Domain Object secrets and derives inter-realm Kerberos (AES256, AES128) and RC4 keys for each trust direction. Also fixes the account-line status stripping in add_hash(), which blindly dropped the last space-separated word of every secret line (meant to strip the trailing "Enabled"/"Disabled" on account lines) and was truncating the trust key lines, which contain spaces but no status suffix.
Like --trust-keys but skips account enumeration entirely (implied --just-dc behavior in impacket), emitting only the trust keys. Useful when only the inter-realm keys are needed, for a faster and quieter dump.
--just-trust-keys reused the regular NTDS dump summary ("NTDS hashes",
"added to the database", grep-disabled hint), which is meaningless
when only trust keys are dumped (no accounts are enumerated). Show a
summary specific to that mode instead.
Trust key lines never contain "Enabled"/"Disabled" (they have no account status), so the --enabled filter silently dropped them entirely. Detect trust key lines and always show them regardless of --enabled.
NeffIsBack
left a comment
There was a problem hiding this comment.
Hi and thanks for the PR!
Does rc4_hmac refer to the nt hash? Maybe we should align it with the original ntds output, also in respect to dumping the kerberos keys only when --kerberos-keys is specified.
| printUserStatus=True, | ||
| trustKeys=self.args.trust_keys, | ||
| justTrustKeys=self.args.just_trust_keys, | ||
| domainFQDN=self.domain, |
There was a problem hiding this comment.
That must be self.targetDomain
|
Hi, wdym by "Maybe we should align it with the original ntds output"? Do you mean deleting the For For now, i'm changing |
|
Seems right to me. I'll change this later. 👍 |
Signed-off-by: mpgn <5891788+mpgn@users.noreply.github.com>
Set default value for --trust-keys argument to True. Signed-off-by: mpgn <5891788+mpgn@users.noreply.github.com>
|
Should be good if you want to test it :) |
|
Is it possible to separate it visually from the other output (e.g. adding a |



Description
Exposes impacket secretsdump's trust key extraction (fortra/impacket#2207) through NetExec's
smb --ntds.Adds two new flags:
--trust-keys: in addition to the usual NTDS account secrets, dumps Trusted Domain Object (TDO) secrets and derives, for each trust direction (Incoming/Outgoing), the inter-realm Kerberos keys (AES256, AES128) and the RC4 (NT) hash, for both the current and the previous trust password.--just-trust-keys: same extraction, but dumps ONLY the trust keys and skips account enumeration entirely (faster, quieter, no NTDS account secrets).Also fixes two pre-existing bugs in
smb.py's NTDS output handling that surfaced while wiring this in:add_hash()blindly dropped the last space-separated word of every secret line (meant to strip the trailing "Enabled"/"Disabled" on account lines), which truncated trust key lines since their direction label ((Incoming, previous)) also contains spaces. Now only strips the last word when it's actually a status.--enabledsilently dropped all trust key lines entirely, since they have no account "Enabled"/"Disabled" status to match against. Trust keys are now always shown with--enabled, except previous-password trust keys (trust equivalent of history), which are excluded like disabled/history entries are.Dependency: requires impacket built from a commit that includes fortra/impacket#2207 (already the case since NetExec pulls impacket from
git+https://github.com/fortra/impacketHEAD inpyproject.toml;poetry.lockneeds to be refreshed to a commit at or after the merge).This change was implemented with the assistance of Claude Code (Sonnet 5): it wrote the flag wiring, the fixes to
add_hash(). I reviewed and directed each change.Type of change
Setup guide for the review
Tested against a Windows Server 2022 (build 20348) Domain Controller in a domain (
serval.int) with multiple trusts (incoming, outgoing, bidirectional, and a one-way external trust). Authenticated with-k(Kerberos).--enabled): run--ntds --trust-keys(or--just-trust-keys) against a DC with at least one trust configured; without the fix, trust key lines show truncated (e.g.dev.serval.int (Incoming,with the hash missing) and disappear entirely when--enabledis added.--ntdsdump. No additional GPO or registry changes needed. Both the online DRSUAPI path and--ntds vsswere exercised.Commands used:
Screenshots (if appropriate):
Checklist:
poetry run ruff check ., use--fixto automatically fix what it can)tests/e2e_commands.txtfile if necessary (new modules or features are required to be added to the e2e tests)