diff --git a/nxc/modules/groupmembership.py b/nxc/modules/groupmembership.py index 9867e605..93f0a121 100644 --- a/nxc/modules/groupmembership.py +++ b/nxc/modules/groupmembership.py @@ -71,9 +71,7 @@ class NXCModule: if str(primaryGroupID) == "513": memberOf.append("CN=Domain Users,CN=Users,DC=XXXXX,DC=XXX") elif str(attribute["type"]) == "memberOf": - for group in attribute["vals"]: - if isinstance(group._value, bytes): - memberOf.append(str(group)) + memberOf += [str(group) for group in attribute["vals"] if isinstance(group._value, bytes)] except Exception as e: context.log.debug("Exception:", exc_info=True) diff --git a/nxc/modules/keepass_trigger.py b/nxc/modules/keepass_trigger.py index dd7af1ff..9f7f2cea 100644 --- a/nxc/modules/keepass_trigger.py +++ b/nxc/modules/keepass_trigger.py @@ -194,9 +194,7 @@ class NXCModule: next(csv_reader) # to skip the header line keepass_process_list = list(csv_reader) # check if multiple processes belonging to different users are running (in order to choose which one to restart) - keepass_users = [] - for process in keepass_process_list: - keepass_users.append(process[1]) + keepass_users = [process[1] for process in keepass_process_list] if len(keepass_users) == 0: context.log.fail("No running KeePass process found, aborting restart") return diff --git a/nxc/modules/mssql_priv.py b/nxc/modules/mssql_priv.py index 0f8825cb..5ef8a753 100644 --- a/nxc/modules/mssql_priv.py +++ b/nxc/modules/mssql_priv.py @@ -157,9 +157,7 @@ class NXCModule: ------- str: The SQL statement to execute the command using the grantors. """ - exec_as = [] - for grantor in grantors: - exec_as.append(f"EXECUTE AS LOGIN = '{grantor}';") + exec_as = [f"EXECUTE AS LOGIN = '{grantor}';" for grantor in grantors] return "".join(exec_as) def perform_impersonation_check(self, user: User, grantors=None): diff --git a/nxc/protocols/ftp/db_navigator.py b/nxc/protocols/ftp/db_navigator.py index f4085988..5c805af8 100644 --- a/nxc/protocols/ftp/db_navigator.py +++ b/nxc/protocols/ftp/db_navigator.py @@ -65,8 +65,7 @@ class navigator(DatabaseNavigator): data = [["HostID", "Host", "Port", "Banner"]] host_id_list = [h[0] for h in hosts] - for h in hosts: - data.append([h[0], h[1], h[2], h[3], h[4]]) + data += [[h[0], h[1], h[2], h[3], h[4]] for h in hosts] print_table(data, title="Host") @@ -147,8 +146,7 @@ class navigator(DatabaseNavigator): for link in logins: link_id, cred_id, host_id = link hosts = self.db.get_hosts(host_id) - for h in hosts: - access_data.append([h[0], h[1], h[2], h[3]]) + access_data += [[h[0], h[1], h[2], h[3]] for h in hosts] # we look if it's greater than one because the header row always exists if len(access_data) > 1: diff --git a/nxc/protocols/ldap.py b/nxc/protocols/ldap.py index 13df8e29..3230569f 100644 --- a/nxc/protocols/ldap.py +++ b/nxc/protocols/ldap.py @@ -946,22 +946,13 @@ class ldap(connection): 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": - for spn in attribute["vals"]: - SPNs.append(str(spn)) + SPNs = [str(spn) for spn in attribute["vals"]] if mustCommit is True: if int(userAccountControl) & UF_ACCOUNTDISABLE: self.logger.debug(f"Bypassing disabled account {sAMAccountName} ") else: - for spn in SPNs: - answers.append([ - spn, - sAMAccountName, - memberOf, - pwdLastSet, - lastLogon, - delegation, - ]) + answers += [[spn, sAMAccountName, memberOf, pwdLastSet, lastLogon, delegation] for spn in SPNs] except Exception as e: nxc_logger.error(f"Skipping item, cannot process due to error {str(e)}") diff --git a/nxc/protocols/smb.py b/nxc/protocols/smb.py index 9cbc48d7..703bfddd 100755 --- a/nxc/protocols/smb.py +++ b/nxc/protocols/smb.py @@ -726,32 +726,9 @@ class smb(connection): amsi_bypass = self.args.amsi_bypass[0] if self.args.amsi_bypass else None if os.path.isfile(payload): with open(payload) as commands: - for c in commands: - response.append( - self.execute( - create_ps_command( - c, - force_ps32=force_ps32, - dont_obfs=dont_obfs, - custom_amsi=amsi_bypass, - ), - get_output, - methods, - ) - ) + response = [self.execute(create_ps_command(c.strip(), force_ps32=force_ps32, dont_obfs=dont_obfs, custom_amsi=amsi_bypass), get_output, methods) for c in commands] else: - response = [ - self.execute( - create_ps_command( - payload, - force_ps32=force_ps32, - dont_obfs=dont_obfs, - custom_amsi=amsi_bypass, - ), - get_output, - methods, - ) - ] + response = [self.execute(create_ps_command(payload, force_ps32=force_ps32, dont_obfs=dont_obfs, custom_amsi=amsi_bypass), get_output, methods)] return response def shares(self): @@ -830,9 +807,7 @@ class smb(connection): return permissions def get_dc_ips(self): - dc_ips = [] - for dc in self.db.get_domain_controllers(domain=self.domain): - dc_ips.append(dc[1]) + dc_ips = [dc[1] for dc in self.db.get_domain_controllers(domain=self.domain)] if not dc_ips: dc_ips.append(self.host) return dc_ips @@ -1262,9 +1237,7 @@ class smb(connection): if sids_to_check == 0: break - sids = [] - for i in range(so_far, so_far + sids_to_check): - sids.append(f"{domain_sid}-{i:d}") + sids = [f"{domain_sid}-{i:d}" for i in range(so_far, so_far + sids_to_check)] try: lsat.hLsarLookupSids(dce, policy_handle, sids, lsat.LSAP_LOOKUP_LEVEL.LsapLookupWksta) except DCERPCException as e: diff --git a/nxc/protocols/smb/db_navigator.py b/nxc/protocols/smb/db_navigator.py index e3702f72..9805de02 100644 --- a/nxc/protocols/smb/db_navigator.py +++ b/nxc/protocols/smb/db_navigator.py @@ -227,18 +227,7 @@ class navigator(DatabaseNavigator): ] ] - for group in groups: - data.append( - [ - group[0], - group[1], - group[2], - group[3], - len(self.db.get_group_relations(group_id=group[0])), - group[4], - group[5], - ] - ) + data += [[group[0], group[1], group[2], group[3], len(self.db.get_group_relations(group_id=group[0])), group[4], group[5]] for group in groups] print_table(data, title="Group") data = [ [ diff --git a/nxc/protocols/smb/firefox.py b/nxc/protocols/smb/firefox.py index e5a874b8..429b9c80 100644 --- a/nxc/protocols/smb/firefox.py +++ b/nxc/protocols/smb/firefox.py @@ -175,7 +175,7 @@ class FirefoxTriage: for d in directories: if d.get_longname() not in self.false_positive and d.is_directory() > 0: - users.append(d.get_longname()) + users.append(d.get_longname()) # noqa: PERF401, ignoring for readability return users @staticmethod