Skip to content

Commit e993fbd

Browse files
committed
Refactored to enforce direct attribute access, preventing misleading classifications and improving error handling.
1 parent c1a0f14 commit e993fbd

1 file changed

Lines changed: 30 additions & 26 deletions

File tree

nxc/protocols/ldap.py

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -823,8 +823,9 @@ def resolve_and_display_hostname(name, domain_name=None):
823823
resp = self.search(search_filter, attributes, 0)
824824
resp_parse = parse_result_attributes(resp)
825825
for item in resp_parse:
826-
name = item.get("dNSHostName", "") # Get dNSHostName attribute or empty string
827-
resolve_and_display_hostname(name)
826+
if "dNSHostName" in item: # Get dNSHostName attribute
827+
name = item["dNSHostName"]
828+
resolve_and_display_hostname(name)
828829

829830
# Find all trusted domains
830831
self.logger.info("Enumerating Trusted Domains...")
@@ -834,31 +835,34 @@ def resolve_and_display_hostname(name, domain_name=None):
834835
trust_resp_parse = parse_result_attributes(resp)
835836

836837
if trust_resp_parse:
837-
# Find domain controllers for each trusted domain
838838
for trust in trust_resp_parse:
839-
trust_name = trust.get("name", "")
840-
trust_flat_name = trust.get("flatName", "")
841-
trust_direction = trust.get("trustDirection", 0)
842-
trust_type = trust.get("trustType", 0)
843-
844-
# Convert trust direction/type to human-readable format
845-
direction_text = {
846-
0: "Disabled",
847-
1: "Inbound",
848-
2: "Outbound",
849-
3: "Bidirectional",
850-
}.get(int(trust_direction) if trust_direction else 0, "Unknown")
851-
852-
trust_type_text = {
853-
1: "Windows NT",
854-
2: "Active Directory",
855-
3: "Kerberos",
856-
4: "DCE",
857-
5: "Azure Active Directory",
858-
}.get(int(trust_type) if trust_type else 0, "Unknown")
859-
860-
self.logger.info(f"Processing trusted domain: {trust_name} ({trust_flat_name})")
861-
self.logger.info(f"Trust type: {trust_type_text}, Direction: {direction_text}")
839+
try:
840+
trust_name = trust["name"]
841+
trust_flat_name = trust["flatName"]
842+
trust_direction = int(trust["trustDirection"])
843+
trust_type = int(trust["trustType"])
844+
845+
# Convert trust direction/type to human-readable format
846+
direction_text = {
847+
0: "Disabled",
848+
1: "Inbound",
849+
2: "Outbound",
850+
3: "Bidirectional",
851+
}[trust_direction]
852+
853+
trust_type_text = {
854+
1: "Windows NT",
855+
2: "Active Directory",
856+
3: "Kerberos",
857+
4: "DCE",
858+
5: "Azure Active Directory",
859+
}[trust_type]
860+
861+
self.logger.info(f"Processing trusted domain: {trust_name} ({trust_flat_name})")
862+
self.logger.info(f"Trust type: {trust_type_text}, Direction: {direction_text}")
863+
864+
except Exception as e:
865+
self.logger.fail(f"Failed {e} in trust entry: {trust}")
862866

863867
# Only process if it's an Active Directory trust
864868
if int(trust_type) == 2:

0 commit comments

Comments
 (0)