From 7296e3c7157010b1da288bcc640336be96118549 Mon Sep 17 00:00:00 2001 From: mpgn <5891788+mpgn@users.noreply.github.com> Date: Thu, 2 Jan 2025 21:51:39 +0100 Subject: [PATCH 1/3] fix connection issue with socks ldap --- nxc/protocols/ldap.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/nxc/protocols/ldap.py b/nxc/protocols/ldap.py index c45dc3dbb..05556cea3 100644 --- a/nxc/protocols/ldap.py +++ b/nxc/protocols/ldap.py @@ -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}" @@ -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": @@ -205,9 +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 - self.logger.debug(f"Target: {target}; target_domain: {target_domain}; base_dn: {base_dn}") + except OSError as e: + self.logger.error(f"Error getting ldap info { str(e) }") + self.target = target self.targetDomain = target_domain self.baseDN = base_dn @@ -229,7 +229,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 From 45b81a43061772e526968ca9e6688e704da60a24 Mon Sep 17 00:00:00 2001 From: mpgn <5891788+mpgn@users.noreply.github.com> Date: Thu, 2 Jan 2025 21:56:02 +0100 Subject: [PATCH 2/3] fix ruff --- nxc/protocols/ldap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nxc/protocols/ldap.py b/nxc/protocols/ldap.py index 05556cea3..ec65c03d6 100644 --- a/nxc/protocols/ldap.py +++ b/nxc/protocols/ldap.py @@ -206,7 +206,7 @@ def create_conn_obj(self): self.logger.debug("Exception:", exc_info=True) self.logger.info(f"Skipping item, cannot process due to error {e}") except OSError as e: - self.logger.error(f"Error getting ldap info { str(e) }") + self.logger.error(f"Error getting ldap info {e}") self.target = target self.targetDomain = target_domain From 3ec787cda2c1b9716bf23ea18f4ae1b362451442 Mon Sep 17 00:00:00 2001 From: mpgn <5891788+mpgn@users.noreply.github.com> Date: Thu, 2 Jan 2025 21:59:47 +0100 Subject: [PATCH 3/3] re-add debug line --- nxc/protocols/ldap.py | 1 + 1 file changed, 1 insertion(+) diff --git a/nxc/protocols/ldap.py b/nxc/protocols/ldap.py index ec65c03d6..584ff0b59 100644 --- a/nxc/protocols/ldap.py +++ b/nxc/protocols/ldap.py @@ -208,6 +208,7 @@ def create_conn_obj(self): 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 self.baseDN = base_dn