Skip to content

Commit 3209e52

Browse files
authored
Merge pull request Pennyw0rth#677 from Pennyw0rth/neff-fix-ldap-kerb-dom-trust
Fix domain trust with kerberos in ldap
2 parents c198413 + a12c642 commit 3209e52

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

nxc/protocols/ldap.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
)
2626
from impacket.krb5 import constants
2727
from impacket.krb5.kerberosv5 import getKerberosTGS, SessionKeyDecryptionError
28+
from impacket.krb5.ccache import CCache
2829
from impacket.krb5.types import Principal, KerberosException
2930
from impacket.ldap import ldap as ldap_impacket
3031
from impacket.ldap import ldaptypes
@@ -232,7 +233,6 @@ def get_ldap_username(self):
232233
def enum_host_info(self):
233234
self.hostname = self.target.split(".")[0].upper() if "." in self.target else self.target
234235
self.remoteName = self.target
235-
self.domain = self.targetDomain
236236

237237
ntlm_challenge = None
238238
bindRequest = ldapasn1_impacket.BindRequest()
@@ -250,6 +250,14 @@ def enum_host_info(self):
250250
ntlm_info = parse_challenge(ntlm_challenge)
251251
self.server_os = ntlm_info["os_version"]
252252

253+
if self.args.domain:
254+
self.domain = self.args.domain
255+
elif self.args.use_kcache: # Fixing domain trust, just pull the auth domain out of the ticket
256+
self.domain = CCache.parseFile()[0]
257+
self.username = CCache.parseFile()[1]
258+
else:
259+
self.domain = self.targetDomain
260+
253261
# using kdcHost is buggy on impacket when using trust relation between ad so we kdcHost must stay to none if targetdomain is not equal to domain
254262
if not self.kdcHost and self.domain and self.domain == self.targetDomain:
255263
result = self.resolver(self.domain)
@@ -276,15 +284,15 @@ def print_host_info(self):
276284
self.logger.display(f"{self.server_os} (name:{self.hostname}) (domain:{self.domain})")
277285

278286
def kerberos_login(self, domain, username, password="", ntlm_hash="", aesKey="", kdcHost="", useCache=False):
279-
self.username = username
287+
self.username = username if not self.username else self.username # With ccache we get the username from the ticket
280288
self.password = password
281289
self.domain = domain
282290
self.kdcHost = kdcHost
283291
self.aesKey = aesKey
284292

285293
lmhash = ""
286294
nthash = ""
287-
self.username = username
295+
288296
# This checks to see if we didn't provide the LM Hash
289297
if ntlm_hash.find(":") != -1:
290298
lmhash, nthash = ntlm_hash.split(":")

0 commit comments

Comments
 (0)