From f1ef834e4b910b825335352325597f21672f6832 Mon Sep 17 00:00:00 2001 From: SoftAndoWetto <188264635+SoftAndoWetto@users.noreply.github.com> Date: Sun, 8 Nov 2026 16:08:08 +0000 Subject: [PATCH 1/8] Flag Unconstrained delegation in LDAP processing Record Unconstrained delegation before overwriting delegation and rightsTo. Signed-off-by: SoftAndoWetto <188264635+SoftAndoWetto@users.noreply.github.com> --- nxc/protocols/ldap.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nxc/protocols/ldap.py b/nxc/protocols/ldap.py index 333b4aaf01..4a92faceec 100644 --- a/nxc/protocols/ldap.py +++ b/nxc/protocols/ldap.py @@ -1333,9 +1333,9 @@ def printTable(items, header): protocolTransition = 1 if item.get("msDS-AllowedToDelegateTo") is not None: - if protocolTransition == 0: - delegation = "Constrained" - rightsTo = item.get("msDS-AllowedToDelegateTo") + # Already flagged Unconstrained, record it before delegation/rightsTo get overwritten + if delegation == "Unconstrained": + answers.append([sAMAccountName, objectType, delegation, rightsTo]) # Not an elif as an object could both have RBCD and another type of delegation if item.get("msDS-AllowedToActOnBehalfOfOtherIdentity") is not None: From 166e88c175939f633c92b0e3d0aca2496d0f7517 Mon Sep 17 00:00:00 2001 From: SoftAndoWetto <188264635+SoftAndoWetto@users.noreply.github.com> Date: Fri, 13 Nov 2026 11:25:22 +0000 Subject: [PATCH 2/8] Improve delegation logic in ldap.py Refactor delegation handling logic for clarity and correctness. Signed-off-by: SoftAndoWetto <188264635+SoftAndoWetto@users.noreply.github.com> --- 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 4a92faceec..a9b44e417d 100644 --- a/nxc/protocols/ldap.py +++ b/nxc/protocols/ldap.py @@ -1326,16 +1326,16 @@ def printTable(items, header): # Filter out DCs, unconstrained delegation to DCs is not a useful information if userAccountControl & UF_TRUSTED_FOR_DELEGATION and not userAccountControl & UF_SERVER_TRUST_ACCOUNT: - delegation = "Unconstrained" - rightsTo.append("N/A") - elif userAccountControl & UF_TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION: + # Append immediately: an account can also have constrained delegation configured + answers.append([sAMAccountName, objectType, "Unconstrained", "N/A"]) + if userAccountControl & UF_TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION: delegation = "Constrained w/ Protocol Transition" protocolTransition = 1 - + if item.get("msDS-AllowedToDelegateTo") is not None: - # Already flagged Unconstrained, record it before delegation/rightsTo get overwritten - if delegation == "Unconstrained": - answers.append([sAMAccountName, objectType, delegation, rightsTo]) + if protocolTransition == 0: + delegation = "Constrained" + rightsTo = item.get("msDS-AllowedToDelegateTo") # Not an elif as an object could both have RBCD and another type of delegation if item.get("msDS-AllowedToActOnBehalfOfOtherIdentity") is not None: From 221add872036de2d35586095f85dca09ccd7a1a3 Mon Sep 17 00:00:00 2001 From: Alexander Neff Date: Mon, 16 Nov 2026 00:40:23 +0100 Subject: [PATCH 3/8] Formatting --- nxc/protocols/ldap.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/nxc/protocols/ldap.py b/nxc/protocols/ldap.py index a9b44e417d..957a40f207 100644 --- a/nxc/protocols/ldap.py +++ b/nxc/protocols/ldap.py @@ -1328,15 +1328,20 @@ def printTable(items, header): if userAccountControl & UF_TRUSTED_FOR_DELEGATION and not userAccountControl & UF_SERVER_TRUST_ACCOUNT: # Append immediately: an account can also have constrained delegation configured answers.append([sAMAccountName, objectType, "Unconstrained", "N/A"]) + if userAccountControl & UF_TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION: delegation = "Constrained w/ Protocol Transition" protocolTransition = 1 - + if item.get("msDS-AllowedToDelegateTo") is not None: if protocolTransition == 0: delegation = "Constrained" rightsTo = item.get("msDS-AllowedToDelegateTo") + # Add to answers if delegation was found + if delegation in ["Unconstrained", "Constrained", "Constrained w/ Protocol Transition"]: + answers.append([sAMAccountName, objectType, delegation, rightsTo]) + # Not an elif as an object could both have RBCD and another type of delegation if item.get("msDS-AllowedToActOnBehalfOfOtherIdentity") is not None: databyte = item.get("msDS-AllowedToActOnBehalfOfOtherIdentity") @@ -1357,10 +1362,6 @@ def printTable(items, header): for rights, objType in zip(rbcdRights, rbcdObjType, strict=True): answers.append([rights, objType, "Resource-Based Constrained", sAMAccountName]) - - if delegation in ["Unconstrained", "Constrained", "Constrained w/ Protocol Transition"]: - answers.append([sAMAccountName, objectType, delegation, rightsTo]) - except Exception as e: self.logger.error(f"Skipping item, cannot process due to error {e}") From 46f986f82fece96142ea51efe109046708082a5a Mon Sep 17 00:00:00 2001 From: Alexander Neff Date: Mon, 16 Nov 2026 00:43:28 +0100 Subject: [PATCH 4/8] Undo nested function calling --- nxc/protocols/ldap.py | 52 +++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/nxc/protocols/ldap.py b/nxc/protocols/ldap.py index 957a40f207..bdb3bf13fe 100644 --- a/nxc/protocols/ldap.py +++ b/nxc/protocols/ldap.py @@ -1270,32 +1270,6 @@ def query(self): self.logger.highlight(f"{attribute:<20} {value}") def find_delegation(self): - def printTable(items, header): - colLen = [] - - # Calculating maximum length before parsing CN. - for i, col in enumerate(header): - rowMaxLen = max(len(row[1].split(",")[0].split("CN=")[-1]) for row in items) if i == 1 else max(len(str(row[i])) for row in items) - colLen.append(max(rowMaxLen, len(col))) - - # Create the format string for each row - outputFormat = " ".join([f"{{{num}:{width}s}}" for num, width in enumerate(colLen)]) - - # Print header - self.logger.highlight(outputFormat.format(*header)) - self.logger.highlight(" ".join(["-" * itemLen for itemLen in colLen])) - - # Print rows - for row in items: - # Get first CN value. - if "CN=" in row[1]: - row[1] = row[1].split(",")[0].split("CN=")[-1] - - # Added join for DelegationRightsTo - row[3] = ", ".join(str(x) for x in row[3]) if isinstance(row[3], list) else row[3] - - self.logger.highlight(outputFormat.format(*row)) - # Building the search filter search_filter = (f"(&(|(UserAccountControl:1.2.840.113556.1.4.803:={UF_TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION})" f"(UserAccountControl:1.2.840.113556.1.4.803:={UF_TRUSTED_FOR_DELEGATION})" @@ -1366,7 +1340,31 @@ def printTable(items, header): self.logger.error(f"Skipping item, cannot process due to error {e}") if answers: - printTable(answers, header=["AccountName", "AccountType", "DelegationType", "DelegationRightsTo"]) + header = ["AccountName", "AccountType", "DelegationType", "DelegationRightsTo"] + colLen = [] + + # Calculating maximum length before parsing CN. + for i, col in enumerate(header): + rowMaxLen = max(len(row[1].split(",")[0].split("CN=")[-1]) for row in answers) if i == 1 else max(len(str(row[i])) for row in answers) + colLen.append(max(rowMaxLen, len(col))) + + # Create the format string for each row + outputFormat = " ".join([f"{{{num}:{width}s}}" for num, width in enumerate(colLen)]) + + # Print header + self.logger.highlight(outputFormat.format(*header)) + self.logger.highlight(" ".join(["-" * itemLen for itemLen in colLen])) + + # Print rows + for row in answers: + # Get first CN value. + if "CN=" in row[1]: + row[1] = row[1].split(",")[0].split("CN=")[-1] + + # Added join for DelegationRightsTo + row[3] = ", ".join(str(x) for x in row[3]) if isinstance(row[3], list) else row[3] + + self.logger.highlight(outputFormat.format(*row)) else: self.logger.fail("No entries found!") From 642b800040f2b63cf2de55c10ded413c1db9c938 Mon Sep 17 00:00:00 2001 From: Alexander Neff Date: Mon, 16 Nov 2026 00:56:40 +0100 Subject: [PATCH 5/8] Formatting --- nxc/protocols/ldap.py | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/nxc/protocols/ldap.py b/nxc/protocols/ldap.py index bdb3bf13fe..71fdfc220f 100644 --- a/nxc/protocols/ldap.py +++ b/nxc/protocols/ldap.py @@ -1285,32 +1285,25 @@ def find_delegation(self): self.logger.debug(f"Total of records returned {len(resp_parsed)}") for item in resp_parsed: - sAMAccountName = "" - userAccountControl = 0 - delegation = "" - objectType = "" - rightsTo = [] - protocolTransition = 0 - try: sAMAccountName = item["sAMAccountName"] - userAccountControl = int(item["userAccountControl"]) - objectType = item.get("objectCategory") + objectType = item["objectCategory"] # Filter out DCs, unconstrained delegation to DCs is not a useful information if userAccountControl & UF_TRUSTED_FOR_DELEGATION and not userAccountControl & UF_SERVER_TRUST_ACCOUNT: # Append immediately: an account can also have constrained delegation configured answers.append([sAMAccountName, objectType, "Unconstrained", "N/A"]) - if userAccountControl & UF_TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION: - delegation = "Constrained w/ Protocol Transition" - protocolTransition = 1 - + # Constrained delegation + delegation = "" + rightsTo = [] if item.get("msDS-AllowedToDelegateTo") is not None: - if protocolTransition == 0: + if userAccountControl & UF_TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION: + delegation = "Constrained w/ Protocol Transition" + else: delegation = "Constrained" - rightsTo = item.get("msDS-AllowedToDelegateTo") + rightsTo = item["msDS-AllowedToDelegateTo"] # Add to answers if delegation was found if delegation in ["Unconstrained", "Constrained", "Constrained w/ Protocol Transition"]: From 570cc75109ca774ef555816ec40b9d643ac87965 Mon Sep 17 00:00:00 2001 From: Alexander Neff Date: Mon, 16 Nov 2026 00:57:08 +0100 Subject: [PATCH 6/8] Add fixed header size to prevent super long multi line header output --- nxc/protocols/ldap.py | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/nxc/protocols/ldap.py b/nxc/protocols/ldap.py index 71fdfc220f..4dc13ff966 100644 --- a/nxc/protocols/ldap.py +++ b/nxc/protocols/ldap.py @@ -1333,20 +1333,9 @@ def find_delegation(self): self.logger.error(f"Skipping item, cannot process due to error {e}") if answers: - header = ["AccountName", "AccountType", "DelegationType", "DelegationRightsTo"] - colLen = [] - - # Calculating maximum length before parsing CN. - for i, col in enumerate(header): - rowMaxLen = max(len(row[1].split(",")[0].split("CN=")[-1]) for row in answers) if i == 1 else max(len(str(row[i])) for row in answers) - colLen.append(max(rowMaxLen, len(col))) - - # Create the format string for each row - outputFormat = " ".join([f"{{{num}:{width}s}}" for num, width in enumerate(colLen)]) - # Print header - self.logger.highlight(outputFormat.format(*header)) - self.logger.highlight(" ".join(["-" * itemLen for itemLen in colLen])) + self.logger.highlight(f"{'AccountName':<15} {'AccountType':<15} {'DelegationType':<35} {'DelegationRightsTo':<40}") + self.logger.highlight(f"{'-' * 15} {'-' * 15} {'-' * 35} {'-' * 40}") # Print rows for row in answers: @@ -1357,7 +1346,7 @@ def find_delegation(self): # Added join for DelegationRightsTo row[3] = ", ".join(str(x) for x in row[3]) if isinstance(row[3], list) else row[3] - self.logger.highlight(outputFormat.format(*row)) + self.logger.highlight(f"{row[0]:<15} {row[1]:<15} {row[2]:<35} {row[3]:<40}") else: self.logger.fail("No entries found!") From 2d08bb94e212f10cae7c3c3e9ffc17ed41b88ea6 Mon Sep 17 00:00:00 2001 From: Alexander Neff Date: Mon, 16 Nov 2026 00:59:39 +0100 Subject: [PATCH 7/8] Deprecate trusted-for-delegation flag --- nxc/protocols/ldap.py | 3 +++ nxc/protocols/ldap/proto_args.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/nxc/protocols/ldap.py b/nxc/protocols/ldap.py index 4dc13ff966..f8990f1279 100644 --- a/nxc/protocols/ldap.py +++ b/nxc/protocols/ldap.py @@ -1351,6 +1351,9 @@ def find_delegation(self): self.logger.fail("No entries found!") def trusted_for_delegation(self): + self.logger.fail("[REMOVED] Use --find-delegation instead.") + return + # Building the search filter searchFilter = f"(userAccountControl:1.2.840.113556.1.4.803:={UF_TRUSTED_FOR_DELEGATION})" resp = self.search(searchFilter, attributes=["sAMAccountName"], sizeLimit=0) diff --git a/nxc/protocols/ldap/proto_args.py b/nxc/protocols/ldap/proto_args.py index e9813c6341..89a9ae5d20 100644 --- a/nxc/protocols/ldap/proto_args.py +++ b/nxc/protocols/ldap/proto_args.py @@ -27,7 +27,7 @@ def proto_args(parser, parents): vgroup.add_argument("--base-dn", metavar="BASE_DN", dest="base_dn", type=str, default=None, help="base DN for search queries") vgroup.add_argument("--query", nargs=2, help="Query LDAP with a custom filter and attributes") vgroup.add_argument("--find-delegation", action="store_true", help="Finds delegation relationships within an Active Directory domain. (Enabled Accounts only)") - vgroup.add_argument("--trusted-for-delegation", action="store_true", help="Get the list of users and computers with flag TRUSTED_FOR_DELEGATION") + vgroup.add_argument("--trusted-for-delegation", action="store_true", help="[REMOVED] Use --find-delegation instead.") vgroup.add_argument("--password-not-required", action="store_true", help="Get the list of users with flag PASSWD_NOTREQD") vgroup.add_argument("--admin-count", action="store_true", help="Get user that had the value adminCount=1") vgroup.add_argument("--users", nargs="*", help="Enumerate domain users") From fea1703f7c8691523a37e54201394a6203384a8c Mon Sep 17 00:00:00 2001 From: Alexander Neff Date: Mon, 16 Nov 2026 01:04:54 +0100 Subject: [PATCH 8/8] Simplify logic --- nxc/protocols/ldap.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/nxc/protocols/ldap.py b/nxc/protocols/ldap.py index f8990f1279..2130e5759b 100644 --- a/nxc/protocols/ldap.py +++ b/nxc/protocols/ldap.py @@ -1275,7 +1275,6 @@ def find_delegation(self): f"(UserAccountControl:1.2.840.113556.1.4.803:={UF_TRUSTED_FOR_DELEGATION})" "(msDS-AllowedToDelegateTo=*)(msDS-AllowedToActOnBehalfOfOtherIdentity=*))" f"(!(UserAccountControl:1.2.840.113556.1.4.803:={UF_ACCOUNTDISABLE})))") - # f"(!(UserAccountControl:1.2.840.113556.1.4.803:={UF_SERVER_TRUST_ACCOUNT})))") This would filter out RBCD to DCs attributes = ["sAMAccountName", "pwdLastSet", "userAccountControl", "objectCategory", "msDS-AllowedToActOnBehalfOfOtherIdentity", "msDS-AllowedToDelegateTo"] @@ -1290,26 +1289,21 @@ def find_delegation(self): userAccountControl = int(item["userAccountControl"]) objectType = item["objectCategory"] + # Unconstrained delegation # Filter out DCs, unconstrained delegation to DCs is not a useful information if userAccountControl & UF_TRUSTED_FOR_DELEGATION and not userAccountControl & UF_SERVER_TRUST_ACCOUNT: # Append immediately: an account can also have constrained delegation configured answers.append([sAMAccountName, objectType, "Unconstrained", "N/A"]) # Constrained delegation - delegation = "" - rightsTo = [] if item.get("msDS-AllowedToDelegateTo") is not None: if userAccountControl & UF_TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION: delegation = "Constrained w/ Protocol Transition" else: delegation = "Constrained" - rightsTo = item["msDS-AllowedToDelegateTo"] + answers.append([sAMAccountName, objectType, delegation, item["msDS-AllowedToDelegateTo"]]) - # Add to answers if delegation was found - if delegation in ["Unconstrained", "Constrained", "Constrained w/ Protocol Transition"]: - answers.append([sAMAccountName, objectType, delegation, rightsTo]) - - # Not an elif as an object could both have RBCD and another type of delegation + # Resource-Based Constrained Delegation if item.get("msDS-AllowedToActOnBehalfOfOtherIdentity") is not None: databyte = item.get("msDS-AllowedToActOnBehalfOfOtherIdentity") rbcdRights = []