Skip to content

Commit 081ab77

Browse files
committed
fix(mssql): handle TDS error when NTLM challenge absent and fix local-auth flow
1 parent 08ad1cc commit 081ab77

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

nxc/protocols/mssql.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,24 @@ def enum_host_info(self):
134134
self.logger.info(f"Failed to receive NTLM challenge, reason: {e!s}")
135135
return False
136136
else:
137-
ntlm_info = parse_challenge(challenge)
138-
self.targetDomain = self.domain = ntlm_info["domain"]
139-
self.hostname = ntlm_info["hostname"]
140-
self.server_os = ntlm_info["os_version"]
141-
self.logger.extra["hostname"] = self.hostname
142-
self.db.add_host(self.host, self.hostname, self.targetDomain, self.server_os, len(self.mssql_instances),)
137+
if not challenge.startswith(b"NTLMSSP\x00"):
138+
try:
139+
text = challenge.decode("utf-16le", errors="ignore")
140+
clean = "".join(c for c in text if c.isascii() and (c.isprintable() or c == " "))
141+
start = next((i for i, c in enumerate(clean) if c.isupper()), 0)
142+
end = clean.rfind(".")
143+
error_msg = clean[start:end + 1].strip() if 0 <= start < end else clean.strip()
144+
except Exception:
145+
error_msg = ""
146+
self.logger.fail(f"Server does not support Integrated Windows Authentication{f': {error_msg}' if error_msg else ''}")
147+
else:
148+
ntlm_info = parse_challenge(challenge)
149+
self.targetDomain = self.domain = ntlm_info["domain"]
150+
self.hostname = ntlm_info["hostname"]
151+
self.server_os = ntlm_info["os_version"]
152+
self.logger.extra["hostname"] = self.hostname
153+
154+
self.db.add_host(self.host, self.hostname, self.domain, self.server_os, len(self.mssql_instances))
143155

144156
if self.args.domain:
145157
self.domain = self.args.domain

0 commit comments

Comments
 (0)