Skip to content

Commit

Permalink
Merge pull request #530 from Pennyw0rth/ldap_socks
Browse files Browse the repository at this point in the history
fix connection issue with socks ldap
  • Loading branch information
mpgn authored Jan 3, 2025
2 parents 56e9222 + 3ec787c commit fb96e78
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions nxc/protocols/ldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ def proto_logger(self):
)

def create_conn_obj(self):
target = ""
target_domain = ""
base_dn = ""
try:
proto = "ldaps" if (self.args.gmsa or self.port == 636) else "ldap"
ldap_url = f"{proto}://{self.host}"
Expand All @@ -187,9 +190,6 @@ def create_conn_obj(self):
for item in resp:
if isinstance(item, ldapasn1_impacket.SearchResultEntry) is not True:
continue
target = None
target_domain = None
base_dn = None
try:
for attribute in item["attributes"]:
if str(attribute["type"]) == "defaultNamingContext":
Expand All @@ -205,8 +205,9 @@ def create_conn_obj(self):
except Exception as e:
self.logger.debug("Exception:", exc_info=True)
self.logger.info(f"Skipping item, cannot process due to error {e}")
except OSError:
return False
except OSError as e:
self.logger.error(f"Error getting ldap info {e}")

self.logger.debug(f"Target: {target}; target_domain: {target_domain}; base_dn: {base_dn}")
self.target = target
self.targetDomain = target_domain
Expand All @@ -229,7 +230,7 @@ def get_ldap_username(self):

def enum_host_info(self):
self.baseDN = self.args.base_dn if self.args.base_dn else self.baseDN # Allow overwriting baseDN from args
self.hostname = self.target.split(".")[0].upper()
self.hostname = self.target.split(".")[0].upper() if "." in self.target else self.target
self.remoteName = self.target
self.domain = self.targetDomain

Expand Down

0 comments on commit fb96e78

Please sign in to comment.