Skip to content

Commit

Permalink
ruff: auto-run flake8-comprehensions (C4)
Browse files Browse the repository at this point in the history
  • Loading branch information
Marshall-Hallenbeck committed Oct 13, 2023
1 parent 3c4d9cc commit dcc7241
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions nxc/modules/hash_spider.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def neo4j_local_admins(context, driver):
except Exception as e:
context.log.fail(f"Could not pull admins: {e}")
return None
results = [record for record in admins.data()]
results = list(admins.data())
return results


Expand Down Expand Up @@ -105,7 +105,7 @@ def process_creds(context, connection, credentials_data, dbconnection, cursor, d
session = driver.session()
session.run('MATCH (u) WHERE (u.name = "' + username + '") SET u.owned=True RETURN u,u.name,u.owned')
path_to_da = session.run("MATCH p=shortestPath((n)-[*1..]->(m)) WHERE n.owned=true AND m.name=~ '.*DOMAIN ADMINS.*' RETURN p")
paths = [record for record in path_to_da.data()]
paths = list(path_to_da.data())

for path in paths:
if path:
Expand Down
2 changes: 1 addition & 1 deletion nxc/modules/printnightmare.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def fromString(self, data, offset=0):
class DRIVER_INFO_2_ARRAY(Structure):
def __init__(self, data=None, pcReturned=None):
Structure.__init__(self, data=data)
self["drivers"] = list()
self["drivers"] = []
remaining = data
if data is not None:
for _ in range(pcReturned):
Expand Down
10 changes: 5 additions & 5 deletions nxc/modules/spider_plus.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def get_list_from_option(opt):
"""Takes a comma-separated string and converts it to a list of lowercase strings.
It filters out empty strings from the input before converting.
"""
return list(map(lambda o: o.lower(), filter(bool, opt.split(","))))
return [o.lower() for o in filter(bool, opt.split(","))]


class SMBSpiderPlus:
Expand All @@ -70,14 +70,14 @@ def __init__(
self.logger = logger
self.results = {}
self.stats = {
"shares": list(),
"shares_readable": list(),
"shares_writable": list(),
"shares": [],
"shares_readable": [],
"shares_writable": [],
"num_shares_filtered": 0,
"num_folders": 0,
"num_folders_filtered": 0,
"num_files": 0,
"file_sizes": list(),
"file_sizes": [],
"file_exts": set(),
"num_get_success": 0,
"num_get_fail": 0,
Expand Down
2 changes: 1 addition & 1 deletion nxc/modules/spooler.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def on_login(self, context, connection):
tmp_uuid = str(entry["tower"]["Floors"][0])
if (tmp_uuid in endpoints) is not True:
endpoints[tmp_uuid] = {}
endpoints[tmp_uuid]["Bindings"] = list()
endpoints[tmp_uuid]["Bindings"] = []
if uuid.uuidtup_to_bin(uuid.string_to_uuidtup(tmp_uuid))[:18] in epm.KNOWN_UUIDS:
endpoints[tmp_uuid]["EXE"] = epm.KNOWN_UUIDS[uuid.uuidtup_to_bin(uuid.string_to_uuidtup(tmp_uuid))[:18]]
else:
Expand Down
2 changes: 1 addition & 1 deletion nxc/nxcdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ def do_export(self, line):
rows.append(row)

if line[1].lower() == "simple":
simple_rows = list((row[0], row[1], row[2], row[3], row[5]) for row in rows)
simple_rows = [(row[0], row[1], row[2], row[3], row[5]) for row in rows]
write_csv(filename, csv_header_simple, simple_rows)
elif line[1].lower() == "detailed":
write_csv(filename, csv_header_detailed, rows)
Expand Down
2 changes: 1 addition & 1 deletion nxc/protocols/ldap/kerberos.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def get_tgt_asroast(self, userName, requestPAC=True):

req_body = seq_set(as_req, "req-body")

opts = list()
opts = []
opts.append(constants.KDCOptions.forwardable.value)
opts.append(constants.KDCOptions.renewable.value)
opts.append(constants.KDCOptions.proxiable.value)
Expand Down
2 changes: 1 addition & 1 deletion nxc/protocols/smb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1303,7 +1303,7 @@ def rid_brute(self, max_rid=None):
if sids_to_check == 0:
break

sids = list()
sids = []
for i in range(so_far, so_far + sids_to_check):
sids.append(f"{domain_sid}-{i:d}")
try:
Expand Down
4 changes: 2 additions & 2 deletions nxc/protocols/smb/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ def add_check(self, name, description):
q = select(self.ConfChecksTable).filter(self.ConfChecksTable.c.name == name)
select_results = self.conn.execute(q).all()
context = locals()
new_row = dict((column, context[column]) for column in ("name", "description"))
new_row = {column: context[column] for column in ("name", "description")}
updated_ids = self.insert_data(self.ConfChecksTable, select_results, **new_row)

if updated_ids:
Expand All @@ -926,7 +926,7 @@ def add_check_result(self, host_id, check_id, secure, reasons):
q = select(self.ConfChecksResultsTable).filter(self.ConfChecksResultsTable.c.host_id == host_id, self.ConfChecksResultsTable.c.check_id == check_id)
select_results = self.conn.execute(q).all()
context = locals()
new_row = dict((column, context[column]) for column in ("host_id", "check_id", "secure", "reasons"))
new_row = {column: context[column] for column in ("host_id", "check_id", "secure", "reasons")}
updated_ids = self.insert_data(self.ConfChecksResultsTable, select_results, **new_row)

if updated_ids:
Expand Down
2 changes: 1 addition & 1 deletion nxc/protocols/smb/db_navigator.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ def do_wcc(self, line):
columns_to_display = list(valid_columns.values())
else:
requested_columns = line.split(" ")
columns_to_display = list(valid_columns[column.lower()] for column in requested_columns if column.lower() in valid_columns)
columns_to_display = [valid_columns[column.lower()] for column in requested_columns if column.lower() in valid_columns]

results = self.db.get_check_results()
self.display_wcc_results(results, columns_to_display)
Expand Down
2 changes: 1 addition & 1 deletion nxc/protocols/smb/firefox.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def is_master_password_correct(self, key_data, master_password=b""):
return "", "", ""

def get_users(self):
users = list()
users = []

users_dir_path = "Users\\*"
directories = self.conn.listPath(shareName=self.share, path=ntpath.normpath(users_dir_path))
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ build-backend = "poetry.core.masonry.api"
[tool.ruff]
# Ruff doesn't enable pycodestyle warnings (`W`) or
# McCabe complexity (`C901`) by default.
# Other options: pep8-naming (N), flake8-annotations (ANN), flake8-blind-except (BLE)
select = ["E", "F", "D", "UP", "YTT", "ASYNC", "B", "A"]
# Other options: pep8-naming (N), flake8-annotations (ANN), flake8-blind-except (BLE), flake8-commas (COM)
select = ["E", "F", "D", "UP", "YTT", "ASYNC", "B", "A", "C4"]
ignore = [ "E501", "F405", "F841", "D100", "D101", "D102", "D103", "D104", "D105", "D106", "D107", "D203", "D204", "D205", "D212", "D213", "D400", "D401", "D415", "D417", "D419"]

# Allow autofix for all enabled rules (when `--fix`) is provided.
Expand Down

0 comments on commit dcc7241

Please sign in to comment.