Skip to content

lookupsid: add -lookup-domain and -lookup-name - #2349

Open
bandrel wants to merge 2 commits into
fortra:masterfrom
bandrel:lookupsid-lookup-domain-name
Open

bandrel wants to merge 2 commits into
fortra:masterfrom
bandrel:lookupsid-lookup-domain-name

Conversation

@bandrel

@bandrel bandrel commented Oct 27, 2026 •

Copy link
Copy Markdown

lookupsid.py can only brute force the target's own account/primary domain. When the target is fixed, for example a relayed session through ntlmrelayx's SOCKS proxy, there's no way to enumerate a trusted domain even though the target will forward those lookups across the trust.

This adds:

  • -lookup-domain DOMAIN: resolves DOMAIN's SID via LsarLookupNames on the target and brute forces RIDs under it instead.
  • -lookup-name NAME (repeatable): resolves specific names to their SID and account type instead of brute forcing, e.g. -lookup-name 'DOMAIN\HOST$'. Unqualified names use -lookup-domain when given.

Both are rejected in combination with -domain-sids. Default behavior is unchanged.

lookupsid.py -no-pass DOMAINA/user@hostB -lookup-domain DOMAINA 10000
lookupsid.py -no-pass DOMAINA/user@hostB -lookup-domain DOMAINA -lookup-name 'WS01$' -lookup-name svc_sql

Example output for -lookup-name:

DOMAINA\WS01$: S-1-5-21-...-1604 (SidTypeUser)
DOMAINA\svc_sql: S-1-5-21-...-1123 (SidTypeUser)
DOMAINA\nope: not found

🤖 Generated with Claude Code

@anadrianmanrique anadrianmanrique added the in review This issue or pull request is being analyzed label Oct 28, 2026
godylockz pushed a commit to godylockz/impacket that referenced this pull request Nov 11, 2026
godylockz pushed a commit to godylockz/impacket that referenced this pull request Nov 22, 2026
-lookup-domain DOMAIN resolves DOMAIN's SID with LsarLookupNames on the
target and brute forces RIDs under it instead of the target's own
domain. The target forwards the lookups, so a trusted domain can be
enumerated through a host in another domain. This helps when the
target is fixed, e.g. a relayed session through ntlmrelayx's SOCKS
proxy.

-lookup-name NAME (repeatable) resolves specific names to their SID and
account type instead of brute forcing, e.g. -lookup-name 'DOMAIN\HOST$'.
Names without a domain are qualified with -lookup-domain when given.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bandrel
bandrel force-pushed the lookupsid-lookup-domain-name branch from 249659b to 7a903b4 Compare November 23, 2026 22:40
@bandrel

bandrel commented Nov 23, 2026

Copy link
Copy Markdown
Author

@gabrielg5 I rebased and pushed so the action should succeed now

@gabrielg5 gabrielg5 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey hi!
Thanks for this one. Left a couple suggestions there...

Also one observation from testing -lookup-name in GOAD; KINGSLANDING$, WINTERFELL$, and CASTELBLACK$ all resolved successfully, and Windows returned SidTypeUser for each computer account. The script prints that value as returned by LSA. This matches MS-LSAT’s SID type definitions (https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-lsat/171e9a87-8e01-4bd8-a35e-3468128c8fc4), which say that the protocol does not use SidTypeComputer
This is different than your description. Did you see SidTypeComputer in a different setup?

Thank you!

Comment thread examples/lookupsid.py

options = parser.parse_args()

if options.lookup_domain and options.domain_sids:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a wrapper passes -lookup-domain "$domain" and the variable is empty, the script silently falls back to the default account domain.
Think it's better if we keep the current behavior when the flag is omitted and raise a parser error when it’s supplied with an empty value.

Suggested change
if options.lookup_domain and options.domain_sids:
if options.lookup_domain == '':
parser.error('-lookup-domain requires a non-empty domain name')
if options.lookup_domain and options.domain_sids:

Comment thread examples/lookupsid.py Outdated
Comment on lines +210 to +213
group.add_argument('-lookup-domain', action='store', metavar='DOMAIN', help='Resolve DOMAIN\'s SID through the target and '
'enumerate it instead (e.g. a trusted domain; requests are forwarded across the trust)')
group.add_argument('-lookup-name', action='append', metavar='NAME', help='Resolve NAME (e.g. DOMAIN\\HOST$) to its SID '
'instead of brute forcing. Can be repeated. Names without a domain use -lookup-domain if given')

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A nit one... Rephrased help text for the newly added parameters. Think it clarifies better the double-use of -lookup-domain

Suggested change
group.add_argument('-lookup-domain', action='store', metavar='DOMAIN', help='Resolve DOMAIN\'s SID through the target and '
'enumerate it instead (e.g. a trusted domain; requests are forwarded across the trust)')
group.add_argument('-lookup-name', action='append', metavar='NAME', help='Resolve NAME (e.g. DOMAIN\\HOST$) to its SID '
'instead of brute forcing. Can be repeated. Names without a domain use -lookup-domain if given')
group.add_argument('-lookup-domain', metavar='DOMAIN',
help='Domain to enumerate. With -lookup-name, use DOMAIN as the default qualifier for unqualified names.')
group.add_argument('-lookup-name', action='append', metavar='NAME',
help='Resolve NAME to its SID and show the SID type reported by the server. '
'Repeat for multiple names. Skips RID enumeration.')

Comment thread examples/lookupsid.py Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make the startup log reflect the lookup mode.

Suggested change
if self.__lookup_names:
logging.info('Resolving names at %s', remoteName)
else:
logging.info('Brute forcing SIDs at %s', remoteName)

@gabrielg5 gabrielg5 added enhancement Implemented features can be improved or revised waiting for response Further information is needed from people who opened the issue or pull request medium Medium priority item and removed in review This issue or pull request is being analyzed labels Nov 23, 2026
Reject an empty -lookup-domain so a wrapper passing an unset variable
does not silently fall back to the account domain. Clarify the help
text for both flags and log "Resolving names" instead of "Brute
forcing SIDs" when -lookup-name is used.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bandrel

bandrel commented Nov 24, 2026

Copy link
Copy Markdown
Author

Thanks, applied all three suggestions in 35d98a4. You're right on the SID type: computer accounts come back as SidTypeUser per MS-LSAT; the SidTypeComputer in the description was my mistake, not something I observed. I've corrected the example output in the PR description.

@gabrielg5 gabrielg5 removed the waiting for response Further information is needed from people who opened the issue or pull request label Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Implemented features can be improved or revised medium Medium priority item

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants