fix: use target FQDN directly for Kerberos SPN when host is already fully qualified#6
Open
fix: use target FQDN directly for Kerberos SPN when host is already fully qualified#6
Conversation
Reconstructing the remote name as {netbios_hostname}.{targetDomain} produces
the wrong SPN when a host's DNS suffix differs from the AD domain name
(e.g. host.aepsc.com registered in AD vs the constructed host.corp.aepsc.com),
resulting in KDC_ERR_S_PRINCIPAL_UNKNOWN. Use self.host directly when it is
already an FQDN, matching Impacket's smbclient behaviour.
|
It looks like the PR template may not have been filled out. The following sections appear to be missing:
Please edit your PR description to include them. The template helps reviewers understand and test your changes. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When using Kerberos authentication (
-k/--use-kcache) against a target specified as an FQDN, NXC reconstructs the remote name used for SPN lookup as{netbios_hostname}.{targetDomain}(smb.py:285):This breaks in environments where a host's DNS suffix differs from the AD Kerberos realm. For example:
host.example.comHOSTdomain.example.comcifs/host.domain.example.com@DOMAIN.EXAMPLE.COM❌cifs/host.example.com@DOMAIN.EXAMPLE.COM✅The KDC returns
KDC_ERR_S_PRINCIPAL_UNKNOWNbecause the reconstructed SPN doesn't match what the machine has registered. To make things worse, the return value ofkerberos_login()is not checked in the--use-kcachepath (connection.py), so NXC prints "Successfully authenticated using Kerberos cache" even after the failure and then hits a connection reset when trying to enumerate shares.This is confirmed by Impacket's
smbclient.py -k -debug, which shows it uses the target hostname as-is for the SPN and lets the KDC resolve it:Fix
When the target is already an FQDN (contains a dot), use it directly as
remoteNameso the SPN matches the host's actual AD registration. Only fall back to constructing{hostname}.{targetDomain}when a bare hostname (no dot) is passed, since there is no FQDN to use in that case.Test plan
nxc smb host.example.com -k --use-kcache --shareswherehost.example.comhas a DNS suffix different from the AD domain — confirm auth succeeds and shares enumeratenxc smb host.domain.example.com -k --use-kcache --shareswhere DNS suffix matches AD domain — confirm no regressionnxc smb BAREHOST -k --use-kcache --sharespassing a bare hostname — confirm fallback to{hostname}.{domain}construction still works