Skip to content

Commit 05ad12f

Browse files
committed
add kill option if user wants to kill process and read files
1 parent 059a20b commit 05ad12f

1 file changed

Lines changed: 21 additions & 11 deletions

File tree

nxc/modules/notepad.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ def __init__(self, context=None):
3737
self.FILE_PATH_REGEX = r"^[A-Za-z]:\\(?:[^<>:\"/\\|?*]+\\)*[^<>:\"/\\|?*]+\.[\w]{1,5}$"
3838

3939
def options(self, context, module_options):
40-
"""No options available."""
40+
"""KILL // Kill for notepad.exe process. Default False."""
41+
if "KILL" not in module_options:
42+
self.kill = False
43+
else:
44+
self.kill = module_options["KILL"]
4145

4246
def extract_strings(self, data, min_length=4):
4347
"""Extract printable strings from binary data, similar to the strings command."""
@@ -91,16 +95,20 @@ def read_and_decode_file(self, connection, context, file_path, user):
9195
connection.conn.getFile("C$", file_path, buf.write)
9296
except Exception as e:
9397
if "STATUS_SHARING_VIOLATION" in str(e): # It means notepad.exe is open on target.
94-
# If there's a sharing violation, try alternative approach
95-
context.log.debug(f"Sharing violation on {file_path}, trying alternative method")
96-
try:
97-
context.log.debug(f"Trying to kill notepad.exe process for {user} user.")
98-
# To Do: Kill process with RPC, connection.execute can be detect by EDRs and module wont work. Or copy the target bin files without trigger the EDRs
99-
connection.execute("taskkill /IM notepad.exe /F") # If notepad.exe open by user, needs to kill that process for reading files.
100-
time.sleep(1) # Sleep 1 sec for finding and reading processing
101-
context.log.debug(f"Notepad process was successfully killed for {user}")
102-
except Exception as e:
103-
context.log.debug(f"Alternative method failed: {e}")
98+
if self.kill:
99+
# If there's a sharing violation, try alternative approach
100+
context.log.debug(f"Sharing violation on {file_path}, trying alternative method")
101+
try:
102+
context.log.debug(f"Trying to kill notepad.exe process for {user} user.")
103+
# To Do: Kill process with RPC, connection.execute can be detect by EDRs and module wont work. Or copy the target bin files without trigger the EDRs
104+
connection.execute("taskkill /IM notepad.exe /F") # If notepad.exe open by user, needs to kill that process for reading files.
105+
time.sleep(1) # Sleep 1 sec for finding and reading processing
106+
context.log.debug(f"Notepad process was successfully killed for {user}")
107+
except Exception as e:
108+
context.log.debug(f"Alternative method failed: {e}")
109+
else:
110+
context.log.fail("Notepad.exe is open on target. If want to kill process, add kill option true. (-o KILL=True)")
111+
return []
104112
else:
105113
# If it's a different error, just skip this file
106114
context.log.debug(f"Error accessing {file_path}: {e}")
@@ -162,6 +170,8 @@ def on_admin_login(self, context, connection):
162170
output_file.write(f"Source: C:\\{file_path}\n\n")
163171
output_file.write("\n".join(content_lines)) # Write strings line by line
164172
context.log.success(f"Notepad tab state content written to: {path}")
173+
else:
174+
break
165175
except SessionError as e:
166176
error = self.get_error_string(e)
167177
if error == "STATUS_OBJECT_NAME_NOT_FOUND" or error == "STATUS_OBJECT_PATH_NOT_FOUND":

0 commit comments

Comments
 (0)