From 243de6a45cbddb1031544d6267c5d1c87ccfa83a Mon Sep 17 00:00:00 2001 From: CSpanias Date: Sat, 14 Nov 2026 16:43:32 +0000 Subject: [PATCH 1/3] Add LDAP password-never-expires check --- nxc/protocols/ldap.py | 22 +++++++++++++++++----- nxc/protocols/ldap/proto_args.py | 1 + tests/e2e_commands.txt | 1 + 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/nxc/protocols/ldap.py b/nxc/protocols/ldap.py index 83243b55c4..239326a89c 100644 --- a/nxc/protocols/ldap.py +++ b/nxc/protocols/ldap.py @@ -18,12 +18,10 @@ from bloodhound.ad.domain import AD from certihound import ADCSCollector, BloodHoundCEExporter, ImpacketLDAPAdapter from impacket.dcerpc.v5.samr import ( - UF_ACCOUNTDISABLE, - UF_DONT_REQUIRE_PREAUTH, - UF_TRUSTED_FOR_DELEGATION, + UF_ACCOUNTDISABLE, UF_DONT_REQUIRE_PREAUTH, + UF_DONT_EXPIRE_PASSWD, UF_TRUSTED_FOR_DELEGATION, UF_TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION, - UF_SERVER_TRUST_ACCOUNT, - SAM_MACHINE_ACCOUNT, + UF_SERVER_TRUST_ACCOUNT, SAM_MACHINE_ACCOUNT, ) from impacket.krb5 import constants from impacket.krb5.crypto import generate_kerberos_keys @@ -1400,6 +1398,20 @@ def password_not_required(self): else: self.logger.fail("No entries found!") + def password_never_expires(self): + searchFilter = f"(userAccountControl:1.2.840.113556.1.4.803:={UF_DONT_EXPIRE_PASSWD})" + attributes = ["sAMAccountName", "userAccountControl"] + resp = self.search(searchFilter, attributes, baseDN=self.baseDN) + resp_parsed = parse_result_attributes(resp) + self.logger.debug(f"Total of records returned {len(resp_parsed):d}") + + if resp_parsed: + for user in resp_parsed: + status = "disabled" if int(user["userAccountControl"]) & UF_ACCOUNTDISABLE else "enabled" + self.logger.highlight(f"User: {user['sAMAccountName']} Status: {status}") + else: + self.logger.fail("No entries found!") + def admin_count(self): # Building the search filter resp = self.search(searchFilter="(&(adminCount=1)(objectClass=user))", attributes=["sAMAccountName"], sizeLimit=0) diff --git a/nxc/protocols/ldap/proto_args.py b/nxc/protocols/ldap/proto_args.py index e9813c6341..8788b236c1 100644 --- a/nxc/protocols/ldap/proto_args.py +++ b/nxc/protocols/ldap/proto_args.py @@ -29,6 +29,7 @@ def proto_args(parser, parents): 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("--password-not-required", action="store_true", help="Get the list of users with flag PASSWD_NOTREQD") + vgroup.add_argument("--password-never-expires", action="store_true", help="Get the list of users with flag DONT_EXPIRE_PASSWORD") 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") vgroup.add_argument("--users-export", help="Enumerate domain users and export them to the specified file") diff --git a/tests/e2e_commands.txt b/tests/e2e_commands.txt index bb70bdd51f..3945622266 100644 --- a/tests/e2e_commands.txt +++ b/tests/e2e_commands.txt @@ -241,6 +241,7 @@ netexec ldap TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --kerberoa netexec ldap TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --kerberoast /tmp/kerberoasting2.txt netexec ldap TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --kerberoasting /tmp/kerberoasting3.txt --kerberoast-account test_user netexec ldap TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --trusted-for-delegation +netexec ldap TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --password-never-expires netexec ldap TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --admin-count netexec ldap TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --gmsa netexec ldap TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --pso From d0932bd7c773cbbe5f34807801f47301b2578abd Mon Sep 17 00:00:00 2001 From: CSpanias Date: Sat, 14 Nov 2026 16:57:56 +0000 Subject: [PATCH 2/3] Preserve existing LDAP import formatting --- nxc/protocols/ldap.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/nxc/protocols/ldap.py b/nxc/protocols/ldap.py index 239326a89c..0ade98ebbb 100644 --- a/nxc/protocols/ldap.py +++ b/nxc/protocols/ldap.py @@ -18,10 +18,13 @@ from bloodhound.ad.domain import AD from certihound import ADCSCollector, BloodHoundCEExporter, ImpacketLDAPAdapter from impacket.dcerpc.v5.samr import ( - UF_ACCOUNTDISABLE, UF_DONT_REQUIRE_PREAUTH, - UF_DONT_EXPIRE_PASSWD, UF_TRUSTED_FOR_DELEGATION, + UF_ACCOUNTDISABLE, + UF_DONT_REQUIRE_PREAUTH, + UF_DONT_EXPIRE_PASSWD, + UF_TRUSTED_FOR_DELEGATION, UF_TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION, - UF_SERVER_TRUST_ACCOUNT, SAM_MACHINE_ACCOUNT, + UF_SERVER_TRUST_ACCOUNT, + SAM_MACHINE_ACCOUNT, ) from impacket.krb5 import constants from impacket.krb5.crypto import generate_kerberos_keys From 96bd87e469b329b76e9373ebf4f3ebb8bbe4158e Mon Sep 17 00:00:00 2001 From: Charalampos Spanias Date: Mon, 16 Nov 2026 09:17:59 +0000 Subject: [PATCH 3/3] Filtered out disabled accounts and displayed the pwd last change timestamp. --- nxc/protocols/ldap.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/nxc/protocols/ldap.py b/nxc/protocols/ldap.py index 0ade98ebbb..121ac0c441 100644 --- a/nxc/protocols/ldap.py +++ b/nxc/protocols/ldap.py @@ -1402,16 +1402,19 @@ def password_not_required(self): self.logger.fail("No entries found!") def password_never_expires(self): - searchFilter = f"(userAccountControl:1.2.840.113556.1.4.803:={UF_DONT_EXPIRE_PASSWD})" - attributes = ["sAMAccountName", "userAccountControl"] - resp = self.search(searchFilter, attributes, baseDN=self.baseDN) + search_filter = f"(&(userAccountControl:1.2.840.113556.1.4.803:={UF_DONT_EXPIRE_PASSWD})(!(userAccountControl:1.2.840.113556.1.4.803:={UF_ACCOUNTDISABLE})))" + attributes = ["sAMAccountName", "pwdLastSet"] + resp = self.search(search_filter, attributes, baseDN=self.baseDN) resp_parsed = parse_result_attributes(resp) self.logger.debug(f"Total of records returned {len(resp_parsed):d}") if resp_parsed: + self.logger.highlight(f"{'-Username-':<30}{'-Last PW Set-':<20}") for user in resp_parsed: - status = "disabled" if int(user["userAccountControl"]) & UF_ACCOUNTDISABLE else "enabled" - self.logger.highlight(f"User: {user['sAMAccountName']} Status: {status}") + pwd_last_set = user.get("pwdLastSet", "") + if pwd_last_set: + pwd_last_set = "" if pwd_last_set == "0" else datetime.fromtimestamp(self.getUnixTime(int(pwd_last_set))).strftime("%Y-%m-%d %H:%M:%S") + self.logger.highlight(f"{user.get('sAMAccountName', ''):<30}{pwd_last_set:<20}") else: self.logger.fail("No entries found!")