From 4627d0a119d62c5b0db1d0959c9cad5ef8b18d81 Mon Sep 17 00:00:00 2001 From: termanix <50464194+termanix@users.noreply.github.com> Date: Mon, 21 Oct 2024 22:11:42 +0300 Subject: [PATCH 01/11] Update for parse_result_attributes Signed-off-by: termanix <50464194+termanix@users.noreply.github.com> --- nxc/protocols/ldap.py | 1 + 1 file changed, 1 insertion(+) diff --git a/nxc/protocols/ldap.py b/nxc/protocols/ldap.py index 7780a5b1c..e864a6209 100644 --- a/nxc/protocols/ldap.py +++ b/nxc/protocols/ldap.py @@ -184,6 +184,7 @@ def get_ldap_info(self, host): attributes=["defaultNamingContext", "dnsHostName"], sizeLimit=0, ) + for item in resp: if isinstance(item, ldapasn1_impacket.SearchResultEntry) is not True: continue From 496ea6539496e1d490a6e7805fdb181f43dab7a3 Mon Sep 17 00:00:00 2001 From: termanix <50464194+termanix@users.noreply.github.com> Date: Tue, 22 Oct 2024 21:38:01 +0300 Subject: [PATCH 02/11] Updated get_ldap_info with parse_result_attributes Signed-off-by: termanix <50464194+termanix@users.noreply.github.com> --- nxc/protocols/ldap.py | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/nxc/protocols/ldap.py b/nxc/protocols/ldap.py index e864a6209..b4164deea 100644 --- a/nxc/protocols/ldap.py +++ b/nxc/protocols/ldap.py @@ -184,28 +184,24 @@ def get_ldap_info(self, host): attributes=["defaultNamingContext", "dnsHostName"], sizeLimit=0, ) - - 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": - base_dn = str(attribute["vals"][0]) - target_domain = sub( - ",DC=", - ".", - base_dn[base_dn.lower().find("dc="):], - flags=I, - )[3:] - if str(attribute["type"]) == "dnsHostName": - target = str(attribute["vals"][0]) - except Exception as e: - self.logger.debug("Exception:", exc_info=True) - self.logger.info(f"Skipping item, cannot process due to error {e}") + resp_parse = parse_result_attributes(resp) + + target = None + target_domain = None + base_dn = None + try: + for attribute in resp_parse: + base_dn = attribute.get("defaultNamingContext") + if base_dn: + base_dn = str(base_dn) + target_domain = sub(r",DC=", ".", base_dn[base_dn.lower().find("dc="):], flags=I)[3:] + + target = attribute.get("dnsHostName") + if target: + target = str(target) + 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 [None, None, None] self.logger.debug(f"Target: {target}; target_domain: {target_domain}; base_dn: {base_dn}") From 3d186ec434ffabae3f3e1fbdda12531b9b0b5dfd Mon Sep 17 00:00:00 2001 From: termanix <50464194+termanix@users.noreply.github.com> Date: Mon, 28 Oct 2024 18:10:38 +0200 Subject: [PATCH 03/11] Update check_if_admin parse_result_attributes Signed-off-by: termanix <50464194+termanix@users.noreply.github.com> --- nxc/protocols/ldap.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/nxc/protocols/ldap.py b/nxc/protocols/ldap.py index b4164deea..e2008d507 100644 --- a/nxc/protocols/ldap.py +++ b/nxc/protocols/ldap.py @@ -656,33 +656,33 @@ def check_if_admin(self): search_filter = "(userAccountControl:1.2.840.113556.1.4.803:=8192)" attributes = ["objectSid"] resp = self.search(search_filter, attributes, sizeLimit=0) + resp_parse = parse_result_attributes(resp) answers = [] if resp and (self.password != "" or self.lmhash != "" or self.nthash != "") and self.username != "": - for attribute in resp[0][1]: - if str(attribute["type"]) == "objectSid": - sid = self.sid_to_str(attribute["vals"][0]) - self.sid_domain = "-".join(sid.split("-")[:-1]) + + for item in resp_parse: + sid = item.get("objectSid").encode("latin1") + sid = self.sid_to_str(sid) + self.sid_domain = "-".join(sid.split("-")[:-1]) # 2. get all group cn name search_filter = "(|(objectSid=" + self.sid_domain + "-512)(objectSid=" + self.sid_domain + "-544)(objectSid=" + self.sid_domain + "-519)(objectSid=S-1-5-32-549)(objectSid=S-1-5-32-551))" attributes = ["distinguishedName"] resp = self.search(search_filter, attributes, sizeLimit=0) + resp_parse = parse_result_attributes(resp) answers = [] - for item in resp: - if isinstance(item, ldapasn1_impacket.SearchResultEntry) is not True: - continue - for attribute in item["attributes"]: - if str(attribute["type"]) == "distinguishedName": - answers.append(str("(memberOf:1.2.840.113556.1.4.1941:=" + attribute["vals"][0] + ")")) + + for item in resp_parse: + answers.append(str("(memberOf:1.2.840.113556.1.4.1941:=" + item.get("distinguishedName") + ")")) # 3. get member of these groups search_filter = "(&(objectCategory=user)(sAMAccountName=" + self.username + ")(|" + "".join(answers) + "))" attributes = [""] resp = self.search(search_filter, attributes, sizeLimit=0) answers = [] - for item in resp: - if isinstance(item, ldapasn1_impacket.SearchResultEntry) is not True: - continue + resp_parse = parse_result_attributes(resp) + + for item in resp_parse: if item: self.admin_privs = True From 9889414c2e7f53da774741c8eccd5be8f2dcd832 Mon Sep 17 00:00:00 2001 From: termanix <50464194+termanix@users.noreply.github.com> Date: Mon, 28 Oct 2024 19:59:52 +0200 Subject: [PATCH 04/11] Update groups parse_result_attributes Signed-off-by: termanix <50464194+termanix@users.noreply.github.com> --- nxc/protocols/ldap.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/nxc/protocols/ldap.py b/nxc/protocols/ldap.py index d4780b470..643a469ea 100644 --- a/nxc/protocols/ldap.py +++ b/nxc/protocols/ldap.py @@ -768,17 +768,14 @@ def groups(self): search_filter = "(objectCategory=group)" attributes = ["name"] resp = self.search(search_filter, attributes, 0) + resp_parse = parse_result_attributes(resp) if resp: self.logger.debug(f"Total of records returned {len(resp):d}") - for item in resp: - if isinstance(item, ldapasn1_impacket.SearchResultEntry) is not True: - continue + for item in resp_parse: name = "" try: - for attribute in item["attributes"]: - if str(attribute["type"]) == "name": - name = str(attribute["vals"][0]) + name = item.get("name") self.logger.highlight(f"{name}") except Exception as e: self.logger.debug("Exception:", exc_info=True) From 78063a030844f299127f0d8d0c4733308fd0a6b0 Mon Sep 17 00:00:00 2001 From: termanix <50464194+termanix@users.noreply.github.com> Date: Mon, 28 Oct 2024 20:01:11 +0200 Subject: [PATCH 05/11] Update asreproast parse_result_attributes Signed-off-by: termanix <50464194+termanix@users.noreply.github.com> --- nxc/protocols/ldap.py | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/nxc/protocols/ldap.py b/nxc/protocols/ldap.py index 643a469ea..00020ca23 100644 --- a/nxc/protocols/ldap.py +++ b/nxc/protocols/ldap.py @@ -889,15 +889,14 @@ def asreproast(self): "lastLogon", ] resp = self.search(search_filter, attributes, 0) + resp_parse = parse_result_attributes(resp) if resp is None: self.logger.highlight("No entries found!") elif resp: answers = [] self.logger.display(f"Total of records returned {len(resp):d}") - for item in resp: - if isinstance(item, ldapasn1_impacket.SearchResultEntry) is not True: - continue + for item in resp_parse: mustCommit = False sAMAccountName = "" memberOf = "" @@ -905,18 +904,13 @@ def asreproast(self): userAccountControl = 0 lastLogon = "N/A" try: - for attribute in item["attributes"]: - if str(attribute["type"]) == "sAMAccountName": - sAMAccountName = str(attribute["vals"][0]) - mustCommit = True - elif str(attribute["type"]) == "userAccountControl": - userAccountControl = "0x%x" % int(attribute["vals"][0]) - elif str(attribute["type"]) == "memberOf": - memberOf = str(attribute["vals"][0]) - elif str(attribute["type"]) == "pwdLastSet": - pwdLastSet = "" if str(attribute["vals"][0]) == "0" else str(datetime.fromtimestamp(self.getUnixTime(int(str(attribute["vals"][0]))))) - elif str(attribute["type"]) == "lastLogon": - lastLogon = "" if str(attribute["vals"][0]) == "0" else str(datetime.fromtimestamp(self.getUnixTime(int(str(attribute["vals"][0]))))) + sAMAccountName = item.get("sAMAccountName") + mustCommit = sAMAccountName is not None + userAccountControl = "0x%x" % int(item.get("userAccountControl", 0)) + memberOf = str(item.get("memberOf")) + pwdLastSet = "" if str(item.get("pwdLastSet")) == "0" else str(datetime.fromtimestamp(self.getUnixTime(int(str(item.get("pwdLastSet")))))) + pwdLastSet = "" if str(item.get("lastLogon")) == "0" else str(datetime.fromtimestamp(self.getUnixTime(int(str(item.get("lastLogon")))))) + if mustCommit is True: answers.append( [ From 7b4f5ea65f9f272fc49e8760f5162bf3c7228557 Mon Sep 17 00:00:00 2001 From: termanix <50464194+termanix@users.noreply.github.com> Date: Mon, 28 Oct 2024 20:15:12 +0200 Subject: [PATCH 06/11] Update kerberoasting parse_result_attributes Signed-off-by: termanix <50464194+termanix@users.noreply.github.com> --- nxc/protocols/ldap.py | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/nxc/protocols/ldap.py b/nxc/protocols/ldap.py index 00020ca23..9b03cb1a9 100644 --- a/nxc/protocols/ldap.py +++ b/nxc/protocols/ldap.py @@ -949,6 +949,7 @@ def kerberoasting(self): "lastLogon", ] resp = self.search(searchFilter, attributes, 0) + resp_parse = parse_result_attributes(resp) self.logger.debug(f"Search Filter: {searchFilter}") self.logger.debug(f"Attributes: {attributes}") self.logger.debug(f"Response: {resp}") @@ -957,9 +958,7 @@ def kerberoasting(self): elif resp: answers = [] - for item in resp: - if isinstance(item, ldapasn1_impacket.SearchResultEntry) is not True: - continue + for item in resp_parse: mustCommit = False sAMAccountName = "" memberOf = "" @@ -969,24 +968,17 @@ def kerberoasting(self): lastLogon = "N/A" delegation = "" try: - for attribute in item["attributes"]: - if str(attribute["type"]) == "sAMAccountName": - sAMAccountName = str(attribute["vals"][0]) - mustCommit = True - elif str(attribute["type"]) == "userAccountControl": - userAccountControl = str(attribute["vals"][0]) - if int(userAccountControl) & UF_TRUSTED_FOR_DELEGATION: - delegation = "unconstrained" - elif int(userAccountControl) & UF_TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION: - delegation = "constrained" - elif str(attribute["type"]) == "memberOf": - memberOf = str(attribute["vals"][0]) - elif str(attribute["type"]) == "pwdLastSet": - pwdLastSet = "" if str(attribute["vals"][0]) == "0" else str(datetime.fromtimestamp(self.getUnixTime(int(str(attribute["vals"][0]))))) - elif str(attribute["type"]) == "lastLogon": - lastLogon = "" if str(attribute["vals"][0]) == "0" else str(datetime.fromtimestamp(self.getUnixTime(int(str(attribute["vals"][0]))))) - elif str(attribute["type"]) == "servicePrincipalName": - SPNs = [str(spn) for spn in attribute["vals"]] + sAMAccountName = item.get("sAMAccountName") + mustCommit = sAMAccountName is not None + userAccountControl = int(item.get("userAccountControl", 0)) + memberOf = str(item.get("memberOf")) + if userAccountControl & UF_TRUSTED_FOR_DELEGATION: + delegation = "unconstrained" + elif userAccountControl & UF_TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION: + delegation = "constrained" + pwdLastSet = "" if str(item.get("pwdLastSet")) == "0" else str(datetime.fromtimestamp(self.getUnixTime(int(str(item.get("pwdLastSet")))))) + lastLogon = "" if str(item.get("lastLogon")) == "0" else str(datetime.fromtimestamp(self.getUnixTime(int(str(item.get("lastLogon")))))) + SPNs = [str(spn) for spn in item.get("servicePrincipalName")] if mustCommit is True: if int(userAccountControl) & UF_ACCOUNTDISABLE: From ec09a5a35bbffaa594ad559b8c12bee1e72e11cb Mon Sep 17 00:00:00 2001 From: termanix <50464194+termanix@users.noreply.github.com> Date: Mon, 28 Oct 2024 20:46:35 +0200 Subject: [PATCH 07/11] Update query parse_result_attributes Signed-off-by: termanix <50464194+termanix@users.noreply.github.com> --- nxc/protocols/ldap.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/nxc/protocols/ldap.py b/nxc/protocols/ldap.py index 9b03cb1a9..403222f07 100644 --- a/nxc/protocols/ldap.py +++ b/nxc/protocols/ldap.py @@ -1050,19 +1050,21 @@ def query(self): self.logger.debug(f"Querying LDAP server with filter: {search_filter} and attributes: {attributes}") try: resp = self.search(search_filter, attributes, 0) + resp_parse = parse_result_attributes(resp) except LDAPFilterSyntaxError as e: self.logger.fail(f"LDAP Filter Syntax Error: {e}") return - for item in resp: - if isinstance(item, ldapasn1_impacket.SearchResultEntry) is not True: - continue - self.logger.success(f"Response for object: {item['objectName']}") - for attribute in item["attributes"]: - attr = f"{attribute['type']}:" - vals = str(attribute["vals"]).replace("\n", "") - if "SetOf: " in vals: - vals = vals.replace("SetOf: ", "") - self.logger.highlight(f"{attr:<20} {vals}") + + for item in resp_parse: + self.logger.success(f"Response for object: {item.get('distinguishedName')}") + for attr, value in item.items(): + if isinstance(value, list): + self.logger.highlight(f"{attr:<20}: {' '.join(value)}") + elif isinstance(value, str) and not value.isprintable(): + # Convert non-printable strings to hex format + self.logger.highlight(f"{attr:<20}: {value.encode('latin1').hex()}") + else: + self.logger.highlight(f"{attr:<20}: {value}") def trusted_for_delegation(self): # Building the search filter From c96b703bd7334a385359b9b513fd331ed4e0c957 Mon Sep 17 00:00:00 2001 From: termanix <50464194+termanix@users.noreply.github.com> Date: Mon, 28 Oct 2024 20:58:39 +0200 Subject: [PATCH 08/11] Update trusted-for-delegation parse_result_attributes Signed-off-by: termanix <50464194+termanix@users.noreply.github.com> --- nxc/protocols/ldap.py | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/nxc/protocols/ldap.py b/nxc/protocols/ldap.py index 403222f07..5d3bdac01 100644 --- a/nxc/protocols/ldap.py +++ b/nxc/protocols/ldap.py @@ -1077,13 +1077,12 @@ def trusted_for_delegation(self): "lastLogon", ] resp = self.search(searchFilter, attributes, 0) + resp_parse = parse_result_attributes(resp) answers = [] self.logger.debug(f"Total of records returned {len(resp):d}") - for item in resp: - if isinstance(item, ldapasn1_impacket.SearchResultEntry) is not True: - continue + for item in resp_parse: mustCommit = False sAMAccountName = "" memberOf = "" @@ -1091,18 +1090,13 @@ def trusted_for_delegation(self): userAccountControl = 0 lastLogon = "N/A" try: - for attribute in item["attributes"]: - if str(attribute["type"]) == "sAMAccountName": - sAMAccountName = str(attribute["vals"][0]) - mustCommit = True - elif str(attribute["type"]) == "userAccountControl": - userAccountControl = "0x%x" % int(attribute["vals"][0]) - elif str(attribute["type"]) == "memberOf": - memberOf = str(attribute["vals"][0]) - elif str(attribute["type"]) == "pwdLastSet": - pwdLastSet = "" if str(attribute["vals"][0]) == "0" else str(datetime.fromtimestamp(self.getUnixTime(int(str(attribute["vals"][0]))))) - elif str(attribute["type"]) == "lastLogon": - lastLogon = "" if str(attribute["vals"][0]) == "0" else str(datetime.fromtimestamp(self.getUnixTime(int(str(attribute["vals"][0]))))) + sAMAccountName = item.get("sAMAccountName") + mustCommit = sAMAccountName is not None + userAccountControl = "0x%x" % int(item.get("userAccountControl", 0)) + memberOf = str(item.get("memberOf")) + pwdLastSet = "" if str(item.get("pwdLastSet")) == "0" else str(datetime.fromtimestamp(self.getUnixTime(int(str(item.get("pwdLastSet")))))) + lastLogon = "" if str(item.get("lastLogon")) == "0" else str(datetime.fromtimestamp(self.getUnixTime(int(str(item.get("lastLogon")))))) + if mustCommit is True: answers.append( [ From 2f17bb27b32195d6599b1037b5031ca3d49a0bf2 Mon Sep 17 00:00:00 2001 From: termanix <50464194+termanix@users.noreply.github.com> Date: Mon, 28 Oct 2024 20:59:43 +0200 Subject: [PATCH 09/11] Update password-not-required parse_result_attributes Signed-off-by: termanix <50464194+termanix@users.noreply.github.com> --- nxc/protocols/ldap.py | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/nxc/protocols/ldap.py b/nxc/protocols/ldap.py index 5d3bdac01..b5673b1f4 100644 --- a/nxc/protocols/ldap.py +++ b/nxc/protocols/ldap.py @@ -1143,10 +1143,9 @@ def password_not_required(self): return False answers = [] self.logger.debug(f"Total of records returned {len(resp):d}") + resp_parse = parse_result_attributes(resp) - for item in resp: - if isinstance(item, ldapasn1_impacket.SearchResultEntry) is not True: - continue + for item in resp_parse: mustCommit = False sAMAccountName = "" memberOf = "" @@ -1155,20 +1154,16 @@ def password_not_required(self): status = "enabled" lastLogon = "N/A" try: - for attribute in item["attributes"]: - if str(attribute["type"]) == "sAMAccountName": - sAMAccountName = str(attribute["vals"][0]) - mustCommit = True - elif str(attribute["type"]) == "userAccountControl": - if int(attribute["vals"][0]) & 2: - status = "disabled" - userAccountControl = f"0x{int(attribute['vals'][0]):x}" - elif str(attribute["type"]) == "memberOf": - memberOf = str(attribute["vals"][0]) - elif str(attribute["type"]) == "pwdLastSet": - pwdLastSet = "" if str(attribute["vals"][0]) == "0" else str(datetime.fromtimestamp(self.getUnixTime(int(str(attribute["vals"][0]))))) - elif str(attribute["type"]) == "lastLogon": - lastLogon = "" if str(attribute["vals"][0]) == "0" else str(datetime.fromtimestamp(self.getUnixTime(int(str(attribute["vals"][0]))))) + sAMAccountName = item.get("sAMAccountName") + mustCommit = sAMAccountName is not None + userAccountControl = int(item.get("userAccountControl", 0)) + if userAccountControl & 2: + status = "disabled" + userAccountControl = f"0x{int(item.get('userAccountControl', 0)):x}" + memberOf = str(item.get("memberOf")) + pwdLastSet = "" if str(item.get("pwdLastSet")) == "0" else str(datetime.fromtimestamp(self.getUnixTime(int(str(item.get("pwdLastSet")))))) + lastLogon = "" if str(item.get("lastLogon")) == "0" else str(datetime.fromtimestamp(self.getUnixTime(int(str(item.get("lastLogon")))))) + if mustCommit is True: answers.append( [ From 85600e66b42120187dd691d2df1d3e2be5b8f9df Mon Sep 17 00:00:00 2001 From: termanix <50464194+termanix@users.noreply.github.com> Date: Mon, 28 Oct 2024 21:35:00 +0200 Subject: [PATCH 10/11] Update admin-count parse_result_attributes Signed-off-by: termanix <50464194+termanix@users.noreply.github.com> --- nxc/protocols/ldap.py | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/nxc/protocols/ldap.py b/nxc/protocols/ldap.py index b5673b1f4..02c4f375a 100644 --- a/nxc/protocols/ldap.py +++ b/nxc/protocols/ldap.py @@ -1196,31 +1196,19 @@ def admin_count(self): "lastLogon", ] resp = self.search(searchFilter, attributes, 0) + resp_parse = parse_result_attributes(resp) answers = [] self.logger.debug(f"Total of records returned {len(resp):d}") - for item in resp: - if isinstance(item, ldapasn1_impacket.SearchResultEntry) is not True: - continue - mustCommit = False - sAMAccountName = "" - memberOf = "" - pwdLastSet = "" - userAccountControl = 0 - lastLogon = "N/A" - try: - for attribute in item["attributes"]: - if str(attribute["type"]) == "sAMAccountName": - sAMAccountName = str(attribute["vals"][0]) - mustCommit = True - elif str(attribute["type"]) == "userAccountControl": - userAccountControl = "0x%x" % int(attribute["vals"][0]) - elif str(attribute["type"]) == "memberOf": - memberOf = str(attribute["vals"][0]) - elif str(attribute["type"]) == "pwdLastSet": - pwdLastSet = "" if str(attribute["vals"][0]) == "0" else str(datetime.fromtimestamp(self.getUnixTime(int(str(attribute["vals"][0]))))) - elif str(attribute["type"]) == "lastLogon": - lastLogon = "" if str(attribute["vals"][0]) == "0" else str(datetime.fromtimestamp(self.getUnixTime(int(str(attribute["vals"][0]))))) + for item in resp_parse: + try: + sAMAccountName = item.get("sAMAccountName", " ") + mustCommit = sAMAccountName is not None + userAccountControl = f"0x{int(item.get('userAccountControl', 0)):x}" + memberOf = str(item.get("memberOf", " ")) + pwdLastSet = "" if str(item.get("pwdLastSet", 0)) == "0" else str(datetime.fromtimestamp(self.getUnixTime(int(str(item.get("pwdLastSet", 0)))))) + lastLogon = "" if str(item.get("lastLogon", 0)) == "0" else str(datetime.fromtimestamp(self.getUnixTime(int(str(item.get("lastLogon", 0)))))) + if mustCommit is True: answers.append( [ From 26391a3370c07340a9cc8f643585c4e02013266a Mon Sep 17 00:00:00 2001 From: termanix <50464194+termanix@users.noreply.github.com> Date: Mon, 28 Oct 2024 21:58:53 +0200 Subject: [PATCH 11/11] Update variables Signed-off-by: termanix <50464194+termanix@users.noreply.github.com> --- nxc/protocols/ldap.py | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/nxc/protocols/ldap.py b/nxc/protocols/ldap.py index 02c4f375a..099fb4080 100644 --- a/nxc/protocols/ldap.py +++ b/nxc/protocols/ldap.py @@ -904,12 +904,12 @@ def asreproast(self): userAccountControl = 0 lastLogon = "N/A" try: - sAMAccountName = item.get("sAMAccountName") + sAMAccountName = item.get("sAMAccountName", "") mustCommit = sAMAccountName is not None userAccountControl = "0x%x" % int(item.get("userAccountControl", 0)) - memberOf = str(item.get("memberOf")) - pwdLastSet = "" if str(item.get("pwdLastSet")) == "0" else str(datetime.fromtimestamp(self.getUnixTime(int(str(item.get("pwdLastSet")))))) - pwdLastSet = "" if str(item.get("lastLogon")) == "0" else str(datetime.fromtimestamp(self.getUnixTime(int(str(item.get("lastLogon")))))) + memberOf = str(item.get("memberOf", " ")) + pwdLastSet = "" if str(item.get("pwdLastSet", 0)) == "0" else str(datetime.fromtimestamp(self.getUnixTime(int(str(item.get("pwdLastSet", 0)))))) + pwdLastSet = "" if str(item.get("lastLogon", 0)) == "0" else str(datetime.fromtimestamp(self.getUnixTime(int(str(item.get("lastLogon", 0)))))) if mustCommit is True: answers.append( @@ -968,16 +968,16 @@ def kerberoasting(self): lastLogon = "N/A" delegation = "" try: - sAMAccountName = item.get("sAMAccountName") + sAMAccountName = item.get("sAMAccountName", "") mustCommit = sAMAccountName is not None userAccountControl = int(item.get("userAccountControl", 0)) - memberOf = str(item.get("memberOf")) + memberOf = str(item.get("memberOf", " ")) if userAccountControl & UF_TRUSTED_FOR_DELEGATION: delegation = "unconstrained" elif userAccountControl & UF_TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION: delegation = "constrained" - pwdLastSet = "" if str(item.get("pwdLastSet")) == "0" else str(datetime.fromtimestamp(self.getUnixTime(int(str(item.get("pwdLastSet")))))) - lastLogon = "" if str(item.get("lastLogon")) == "0" else str(datetime.fromtimestamp(self.getUnixTime(int(str(item.get("lastLogon")))))) + pwdLastSet = "" if str(item.get("pwdLastSet", 0)) == "0" else str(datetime.fromtimestamp(self.getUnixTime(int(str(item.get("pwdLastSet", 0)))))) + lastLogon = "" if str(item.get("lastLogon", 0)) == "0" else str(datetime.fromtimestamp(self.getUnixTime(int(str(item.get("lastLogon", 0)))))) SPNs = [str(spn) for spn in item.get("servicePrincipalName")] if mustCommit is True: @@ -1090,12 +1090,12 @@ def trusted_for_delegation(self): userAccountControl = 0 lastLogon = "N/A" try: - sAMAccountName = item.get("sAMAccountName") + sAMAccountName = item.get("sAMAccountName", "") mustCommit = sAMAccountName is not None userAccountControl = "0x%x" % int(item.get("userAccountControl", 0)) - memberOf = str(item.get("memberOf")) - pwdLastSet = "" if str(item.get("pwdLastSet")) == "0" else str(datetime.fromtimestamp(self.getUnixTime(int(str(item.get("pwdLastSet")))))) - lastLogon = "" if str(item.get("lastLogon")) == "0" else str(datetime.fromtimestamp(self.getUnixTime(int(str(item.get("lastLogon")))))) + memberOf = str(item.get("memberOf", " ")) + pwdLastSet = "" if str(item.get("pwdLastSet", 0)) == "0" else str(datetime.fromtimestamp(self.getUnixTime(int(str(item.get("pwdLastSet", 0)))))) + lastLogon = "" if str(item.get("lastLogon", 0)) == "0" else str(datetime.fromtimestamp(self.getUnixTime(int(str(item.get("lastLogon", 0)))))) if mustCommit is True: answers.append( @@ -1146,23 +1146,17 @@ def password_not_required(self): resp_parse = parse_result_attributes(resp) for item in resp_parse: - mustCommit = False - sAMAccountName = "" - memberOf = "" - pwdLastSet = "" - userAccountControl = 0 status = "enabled" - lastLogon = "N/A" try: - sAMAccountName = item.get("sAMAccountName") + sAMAccountName = item.get("sAMAccountName", "") mustCommit = sAMAccountName is not None userAccountControl = int(item.get("userAccountControl", 0)) if userAccountControl & 2: status = "disabled" userAccountControl = f"0x{int(item.get('userAccountControl', 0)):x}" - memberOf = str(item.get("memberOf")) - pwdLastSet = "" if str(item.get("pwdLastSet")) == "0" else str(datetime.fromtimestamp(self.getUnixTime(int(str(item.get("pwdLastSet")))))) - lastLogon = "" if str(item.get("lastLogon")) == "0" else str(datetime.fromtimestamp(self.getUnixTime(int(str(item.get("lastLogon")))))) + memberOf = str(item.get("memberOf", " ")) + pwdLastSet = "" if str(item.get("pwdLastSet", 0)) == "0" else str(datetime.fromtimestamp(self.getUnixTime(int(str(item.get("pwdLastSet", 0)))))) + lastLogon = "" if str(item.get("lastLogon", 0)) == "0" else str(datetime.fromtimestamp(self.getUnixTime(int(str(item.get("lastLogon", 0)))))) if mustCommit is True: answers.append( @@ -1202,7 +1196,7 @@ def admin_count(self): for item in resp_parse: try: - sAMAccountName = item.get("sAMAccountName", " ") + sAMAccountName = item.get("sAMAccountName", "") mustCommit = sAMAccountName is not None userAccountControl = f"0x{int(item.get('userAccountControl', 0)):x}" memberOf = str(item.get("memberOf", " "))