Skip to content

Fix: persist credentials after Kerberos login (smb/mssql/ldap) - #1248

Open
Goultarde wants to merge 3 commits into
Pennyw0rth:mainfrom
Goultarde:feature/kerberos-store-creds
Open

Fix: persist credentials after Kerberos login (smb/mssql/ldap)#1248
Goultarde wants to merge 3 commits into
Pennyw0rth:mainfrom
Goultarde:feature/kerberos-store-creds

Conversation

@Goultarde

@Goultarde Goultarde commented May 25, 2026

Copy link
Copy Markdown
Contributor

Description

After a successful Kerberos authentication, credentials were not being saved to the NXC database for SMB and MSSQL. LDAP had the opposite issue: it was storing credentials even when authenticating from a ccache (--use-kcache), risking empty or incorrect entries.

  • SMB/MSSQL: add credential storage (plaintext or hash), loggedin relation, and admin tracking after a successful Kerberos login
  • LDAP: skip credential storage when useCache=True to avoid storing stale/empty credentials when using --use-kcache
  • All three protocols share the same guard: skip if ccache, empty username, or --delegate (SMB)

No additional dependencies required.

This PR was created with the assistance of AI (Claude code, used for code
structure).

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Deprecation of feature or functionality
  • This change requires a documentation update
  • This requires a third party update (such as Impacket, Dploot, lsassy, etc)
  • This PR was created with the assistance of AI (list what type of assistance, tool(s)/model(s) in the description)

Setup guide for the review

Bug reproduction:

Authenticate against a target using Kerberos with a password or NT hash:

nxc smb <target> -u <user> -p <password> -k
nxc mssql <target> -u <user> -p <password> -k
nxc ldap <target> -u <user> -p <password> -k

Before this fix, nxc smb show creds would not show the credential after a Kerberos login. After the fix it does.

For the LDAP regression, authenticate from an existing ccache and verify no empty credential is stored:

KRB5CCNAME=/tmp/user.ccache nxc ldap <target> --use-kcache

Tested on: Python 3.14, Arch Linux, against a Windows Server 2022 GOAD lab.

Screenshots (if appropriate):

Before

SMB
image
MSSQL
image
LDAP
image

After

SMB
image
MSSQL
image

LDAP
image

Checklist:

  • I have ran Ruff against my changes (poetry: poetry run ruff check ., use --fix to automatically fix what it can)
  • I have performed a self-review of my own code (not an AI review)
  • I have commented my code, particularly in hard-to-understand areas

Goultarde and others added 3 commits May 7, 2026 08:18
The kerberos_login() path in smb and mssql never called
db.add_credential / db.add_loggedin_relation / db.add_admin_user, so a
successful auth via -k left no trace in the NXC database. ldap stored
the credential but did not gate on useCache, so a ccache login with no
secret in hand could still trigger the storage path.

This patch mirrors the persistence logic of plaintext_login / hash_login
for each affected protocol, picking the credtype from whichever input
was provided:

  - password    -> "plaintext"
  - ntlm_hash   -> "hash"
  - aesKey      -> intentionally skipped (no matching credtype in DB)
  - useCache    -> intentionally skipped (no usable secret in hand)
  - --delegate  -> skipped on smb (S4U impersonation, not our secret)

Storage is gated on (self.username and a usable cred_value), so guest
or null sessions stay out of the database.

Per-protocol scope:
- smb / mssql: full path (add_credential + add_loggedin_relation +
  add_admin_user when self.admin_privs).
- ldap: only add_credential, since the LDAP database backend exposes
  neither add_loggedin_relation nor add_admin_user.

Not touched:
- wmi: its database backend has no add_credential (none of the login
  paths persist creds today).
- rdp: same situation as wmi.
@NeffIsBack

Copy link
Copy Markdown
Member

Hi and thanks for the PR!

So far credentials weren't stored when Kerberos is used because of all the false positives that can occur as you mentioned (delegation, ticket auth etc). If we decide to store creds with Kerberos now we have to be careful that we don't miss to exclude any auth that doesn't originate from the supplied hash/password.

@Goultarde

Copy link
Copy Markdown
Contributor Author

Hi ! (Sorry, I thought I had already answered)
Thanks for the feedback, I completely understand the concern now, otherwise we end up with false positives in the database.

I'll take some time to think about how best to handle them and make sure only the supplied password/hash gets stored.

@NeffIsBack

Copy link
Copy Markdown
Member

No worries, take your time :)

Sounds good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants