Skip to content

Commit fbf2546

Browse files
committed
Fix laps login with kerberos
1 parent abb5f1d commit fbf2546

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

nxc/protocols/ldap/laps.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ def kerberos_login(self, domain, username, password="", ntlm_hash="", aesKey="",
3939
lmhash = ""
4040
nthash = ""
4141

42-
if kdcHost is None:
43-
kdcHost = domain
42+
if kdcHost is None or domain not in kdcHost:
43+
self.logger.fail("Please provide the FQDN of the domain controller with --kdcHost")
44+
exit(1)
4445

4546
# This checks to see if we didn't provide the LM Hash
4647
if ntlm_hash and ntlm_hash.find(":") != -1:
@@ -52,11 +53,12 @@ def kerberos_login(self, domain, username, password="", ntlm_hash="", aesKey="",
5253
baseDN = ""
5354
domainParts = domain.split(".")
5455
for i in domainParts:
55-
baseDN += f"dc={i},"
56+
baseDN += f"DC={i},"
5657
# Remove last ','
5758
baseDN = baseDN[:-1]
5859

5960
try:
61+
self.logger.info(f"Connecting to ldap://{kdcHost} - {baseDN} - {domain} [1]")
6062
ldap_connection = ldap_impacket.LDAPConnection(f"ldap://{kdcHost}", baseDN, dns_server if dns_server else domain)
6163
ldap_connection.kerberosLogin(
6264
username,
@@ -103,15 +105,11 @@ def kerberos_login(self, domain, username, password="", ntlm_hash="", aesKey="",
103105
color="magenta" if error_code in ldap_error_status else "red",
104106
)
105107
return False
106-
107108
except OSError:
108109
self.logger.debug(f"{domain}\\{username}:{password if password else ntlm_hash} {'Error connecting to the domain, please add option --kdcHost with the FQDN of the domain controller'}")
109110
return False
110111
except KerberosError as e:
111-
self.logger.fail(
112-
f"{domain}\\{username}:{password if password else ntlm_hash} {e!s}",
113-
color="red",
114-
)
112+
self.logger.fail(f"{domain}\\{username}:{password if password else ntlm_hash} {e!s}", color="red")
115113
return False
116114

117115
def auth_login(self, domain, username, password, ntlm_hash, dns_server):
@@ -273,7 +271,7 @@ def laps_search(self, username, password, cred_type, domain, dns_server):
273271
if self.kerberos:
274272
if self.kdcHost is None:
275273
self.logger.fail("Add --kdcHost parameter to use laps with kerberos")
276-
return None, None, None, None
274+
return None, None, None
277275

278276
connection = ldapco.kerberos_login(
279277
domain[0],

0 commit comments

Comments
 (0)