Skip to content

Commit 1fe387e

Browse files
authored
Merge branch 'main' into regsecret
2 parents 613fd5e + b520fdf commit 1fe387e

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

nxc/protocols/ldap.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,8 @@ def enum_host_info(self):
259259
ntlm_info = parse_challenge(ntlm_challenge)
260260
self.server_os = ntlm_info["os_version"]
261261

262-
if not self.kdcHost and self.domain and self.domain == self.remoteName:
262+
# 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
263+
if not self.kdcHost and self.domain and self.domain == self.targetDomain:
263264
result = self.resolver(self.domain)
264265
self.kdcHost = result["host"] if result else None
265266
self.logger.info(f"Resolved domain: {self.domain} with dns, kdcHost: {self.kdcHost}")
@@ -805,6 +806,7 @@ def active_users(self):
805806
def asreproast(self):
806807
if self.password == "" and self.nthash == "" and self.kerberos is False:
807808
return False
809+
808810
# Building the search filter
809811
search_filter = "(&(UserAccountControl:1.2.840.113556.1.4.803:=%d)(!(UserAccountControl:1.2.840.113556.1.4.803:=%d))(!(objectCategory=computer)))" % (UF_DONT_REQUIRE_PREAUTH, UF_ACCOUNTDISABLE)
810812
attributes = [

nxc/protocols/ldap/kerberos.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def __init__(self, connection):
2828
self.username = connection.username
2929
self.password = connection.password
3030
self.domain = connection.domain
31+
self.host = connection.host
3132
self.targetDomain = connection.targetDomain
3233
self.hash = connection.hash
3334
self.lmhash = ""
@@ -223,6 +224,10 @@ def get_tgt_asroast(self, userName, requestPAC=True):
223224

224225
message = encoder.encode(as_req)
225226

227+
# If kdcHost isn't set, use the target IP for DNS resolution
228+
if not self.kdcHost:
229+
self.kdcHost = self.host
230+
226231
try:
227232
r = sendReceive(message, domain, self.kdcHost)
228233
except KerberosError as e:

nxc/protocols/smb.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,6 @@ def enum_host_info(self):
313313
self.kdcHost = result["host"] if result else None
314314
self.logger.info(f"Resolved domain: {self.domain} with dns, kdcHost: {self.kdcHost}")
315315

316-
# If we want to authenticate we should create another connection object, because we already logged in
317-
if self.args.username or self.args.cred_id or self.kerberos or self.args.use_kcache:
318-
self.create_conn_obj()
319-
320316
def print_host_info(self):
321317
signing = colored(f"signing:{self.signing}", host_info_colors[0], attrs=["bold"]) if self.signing else colored(f"signing:{self.signing}", host_info_colors[1], attrs=["bold"])
322318
smbv1 = colored(f"SMBv1:{self.smbv1}", host_info_colors[2], attrs=["bold"]) if self.smbv1 else colored(f"SMBv1:{self.smbv1}", host_info_colors[3], attrs=["bold"])
@@ -362,6 +358,8 @@ def print_host_info(self):
362358

363359
def kerberos_login(self, domain, username, password="", ntlm_hash="", aesKey="", kdcHost="", useCache=False):
364360
self.logger.debug(f"KDC set to: {kdcHost}")
361+
# Re-connect since we logged off
362+
self.create_conn_obj()
365363
lmhash = ""
366364
nthash = ""
367365

@@ -419,7 +417,6 @@ def kerberos_login(self, domain, username, password="", ntlm_hash="", aesKey="",
419417
if self.args.continue_on_success and self.signing:
420418
with contextlib.suppress(Exception):
421419
self.conn.logoff()
422-
self.create_conn_obj()
423420
return True
424421
except SessionKeyDecryptionError:
425422
# success for now, since it's a vulnerability - previously was an error
@@ -452,6 +449,7 @@ def kerberos_login(self, domain, username, password="", ntlm_hash="", aesKey="",
452449

453450
def plaintext_login(self, domain, username, password):
454451
# Re-connect since we logged off
452+
self.create_conn_obj()
455453
try:
456454
self.password = password
457455
self.username = username
@@ -484,7 +482,6 @@ def plaintext_login(self, domain, username, password):
484482
if self.args.continue_on_success and self.signing:
485483
with contextlib.suppress(Exception):
486484
self.conn.logoff()
487-
self.create_conn_obj()
488485
return True
489486
except SessionError as e:
490487
error, desc = e.getErrorString()
@@ -497,15 +494,14 @@ def plaintext_login(self, domain, username, password):
497494
return False
498495
except (ConnectionResetError, NetBIOSTimeout, NetBIOSError) as e:
499496
self.logger.fail(f"Connection Error: {e}")
500-
self.create_conn_obj()
501497
return False
502498
except BrokenPipeError:
503499
self.logger.fail("Broken Pipe Error while attempting to login")
504-
self.create_conn_obj()
505500
return False
506501

507502
def hash_login(self, domain, username, ntlm_hash):
508503
# Re-connect since we logged off
504+
self.create_conn_obj()
509505
lmhash = ""
510506
nthash = ""
511507
try:
@@ -548,7 +544,6 @@ def hash_login(self, domain, username, ntlm_hash):
548544
if self.args.continue_on_success and self.signing:
549545
with contextlib.suppress(Exception):
550546
self.conn.logoff()
551-
self.create_conn_obj()
552547
return True
553548
except SessionError as e:
554549
error, desc = e.getErrorString()
@@ -562,11 +557,9 @@ def hash_login(self, domain, username, ntlm_hash):
562557
return False
563558
except (ConnectionResetError, NetBIOSTimeout, NetBIOSError) as e:
564559
self.logger.fail(f"Connection Error: {e}")
565-
self.create_conn_obj()
566560
return False
567561
except BrokenPipeError:
568562
self.logger.fail("Broken Pipe Error while attempting to login")
569-
self.create_conn_obj()
570563
return False
571564

572565
def create_smbv1_conn(self, check=False):

0 commit comments

Comments
 (0)