Skip to content

Commit b3ce231

Browse files
committed
Numerous ruff linter adjustments and fixes
1 parent e2e196f commit b3ce231

10 files changed

Lines changed: 846 additions & 792 deletions

File tree

nxc/logger.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def add_file_log(self, log_file=None):
175175
file_creation = False
176176

177177
if not os.path.isfile(output_file):
178-
open(output_file, "x") # noqa: SIM115
178+
open(output_file, "x")
179179
file_creation = True
180180

181181
file_handler = RotatingFileHandler(output_file, maxBytes=100000, encoding="utf-8")

nxc/modules/daclread.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def options(self, context, module_options):
231231
context.log.debug("There is a target specified!")
232232
if re.search(r"^(.+)\/([^\/]+)$", module_options["TARGET"]) is not None:
233233
try:
234-
self.target_file = open(module_options["TARGET"]) # noqa: SIM115
234+
self.target_file = open(module_options["TARGET"])
235235
self.target_sAMAccountName = None
236236
except Exception:
237237
context.log.fail("The file doesn't exist or cannot be openned.")

nxc/modules/handlekatz.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ def on_admin_login(self, context, connection):
126126
except Exception as e:
127127
context.log.fail(f"[OPSEC] Error deleting lsass.dmp file on share {self.share}: {e}")
128128

129-
h_in = open(self.dir_result + machine_name, "rb") # noqa: SIM115
130-
h_out = open(self.dir_result + machine_name + ".decode", "wb") # noqa: SIM115
129+
h_in = open(self.dir_result + machine_name, "rb")
130+
h_out = open(self.dir_result + machine_name + ".decode", "wb")
131131

132132
bytes_in = bytearray(h_in.read())
133133
bytes_in_len = len(bytes_in)

nxc/modules/user-desc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def create_log_file(self, host, time):
9494
logfile = Path.home().joinpath(".nxc").joinpath("logs").joinpath(logfile)
9595

9696
self.context.log.info(f"Creating log file '{logfile}'")
97-
self.log_file = open(logfile, "w") # noqa: SIM115
97+
self.log_file = open(logfile, "w")
9898
self.append_to_log("User:", "Description:")
9999

100100
def delete_log_file(self):

nxc/protocols/ftp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def get_file(self, filename):
139139
# Check if the file exists
140140
self.conn.size(filename)
141141
# Attempt to download the file
142-
self.conn.retrbinary(f"RETR {filename}", open(downloaded_file, "wb").write) # noqa: SIM115
142+
self.conn.retrbinary(f"RETR {filename}", open(downloaded_file, "wb").write)
143143
except error_perm as error_message:
144144
self.logger.fail(f"Failed to download the file. Response: ({error_message})")
145145
self.conn.close()
@@ -157,7 +157,7 @@ def get_file(self, filename):
157157
def put_file(self, local_file, remote_file):
158158
try:
159159
# Attempt to upload the file
160-
self.conn.storbinary(f"STOR {remote_file}", open(local_file, "rb")) # noqa: SIM115
160+
self.conn.storbinary(f"STOR {remote_file}", open(local_file, "rb"))
161161
except error_perm as error_message:
162162
self.logger.fail(f"Failed to upload file. Response: ({error_message})")
163163
return False

nxc/protocols/nfs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -562,13 +562,13 @@ def get_root_handles(self, mount_fh):
562562
# Format for the file id see: https://elixir.bootlin.com/linux/v6.13.4/source/include/linux/exportfs.h#L25
563563
fh = bytearray(mount_fh)
564564
if filesystem in [FileID.ext, FileID.unknown]:
565-
root_handles.append(bytes(fh[:3] + b"\x02" + fh[4:4+fh_fsid_len] + b"\x02\x00\x00\x00" + b"\x00\x00\x00\x00" + b"\x02\x00\x00\x00"))
566-
root_handles.append(bytes(fh[:3] + b"\x02" + fh[4:4+fh_fsid_len] + b"\x80\x00\x00\x00" + b"\x00\x00\x00\x00" + b"\x80\x00\x00\x00"))
565+
root_handles.append(bytes(fh[:3] + b"\x02" + fh[4:4 + fh_fsid_len] + b"\x02\x00\x00\x00" + b"\x00\x00\x00\x00" + b"\x02\x00\x00\x00"))
566+
root_handles.append(bytes(fh[:3] + b"\x02" + fh[4:4 + fh_fsid_len] + b"\x80\x00\x00\x00" + b"\x00\x00\x00\x00" + b"\x80\x00\x00\x00"))
567567
if filesystem in [FileID.btrfs, FileID.unknown]:
568568
# Iterate over btrfs subvolumes, use 16 as default similar to the guys from nfs-security-tooling
569569
for i in range(16):
570570
subvolume = int.to_bytes(i) + b"\x01\x00\x00"
571-
root_handles.append(bytes(fh[:3] + b"\x4d" + fh[4:4+fh_fsid_len] + b"\x00\x01\x00\x00" + b"\x00\x00\x00\x00" + subvolume + b"\x00\x00\x00\x00" + b"\x00\x00\x00\x00"))
571+
root_handles.append(bytes(fh[:3] + b"\x4d" + fh[4:4 + fh_fsid_len] + b"\x00\x01\x00\x00" + b"\x00\x00\x00\x00" + subvolume + b"\x00\x00\x00\x00" + b"\x00\x00\x00\x00"))
572572

573573
return root_handles
574574

nxc/protocols/smb.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ def __init__(self, args, db, host):
132132
self.c_share_write_checked = False
133133
self.isdc = False
134134

135-
136135
connection.__init__(self, args, db, host)
137136

138137
def proto_logger(self):
@@ -612,7 +611,6 @@ def create_conn_obj(self):
612611
self.logger.debug("SMBv1 fallback disabled; not attempting SMBv1 connection.")
613612
return False
614613

615-
616614
def check_if_admin(self):
617615
try:
618616
if self.password is None and not self.nthash:
@@ -1205,7 +1203,6 @@ def shares(self):
12051203

12061204
return permissions
12071205

1208-
12091206
def dir(self):
12101207
search_path = ntpath.join(self.args.dir, "*")
12111208
try:
@@ -1746,7 +1743,7 @@ def dpapi(self):
17461743

17471744
if self.args.pvk is not None:
17481745
try:
1749-
self.pvkbytes = open(self.args.pvk, "rb").read() # noqa: SIM115
1746+
self.pvkbytes = open(self.args.pvk, "rb").read()
17501747
self.logger.success(f"Loading domain backupkey from {self.args.pvk}")
17511748
except Exception as e:
17521749
self.logger.fail(str(e))
@@ -1767,7 +1764,7 @@ def dpapi(self):
17671764
use_kcache=self.use_kcache,
17681765
)
17691766

1770-
self.output_file = open(self.output_file_template.format(output_folder="dpapi"), "w", encoding="utf-8") # noqa: SIM115
1767+
self.output_file = open(self.output_file_template.format(output_folder="dpapi"), "w", encoding="utf-8")
17711768

17721769
conn = upgrade_to_dploot_connection(connection=self.conn, target=target)
17731770
if conn is None:

0 commit comments

Comments
 (0)