Convert for loops into list comprehensions
parent
2391d1d5ba
commit
e672dce25f
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -946,22 +946,13 @@ class ldap(connection):
|
|||
elif str(attribute["type"]) == "lastLogon":
|
||||
lastLogon = "<never>" 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)}")
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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 = [
|
||||
[
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue