Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix lsass Dump Files Deleting Process When Dump Fail #542

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions nxc/modules/handlekatz.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def on_admin_login(self, context, connection):

if not p or p == "None":
context.log.fail("Failed to execute command to get LSASS PID")
self.delete_handlekatz_binary(connection, context)
return
# we get a CSV string back from `tasklist`, so we grab the PID from it
pid = p.split(",")[1][1:-1]
Expand Down Expand Up @@ -113,11 +114,7 @@ def on_admin_login(self, context, connection):
except Exception as e:
context.log.fail(f"Error while get file: {e}")

try:
connection.conn.deleteFile(self.share, self.tmp_share + self.handlekatz)
context.log.success(f"Deleted handlekatz file on the {self.share} share")
except Exception as e:
context.log.fail(f"[OPSEC] Error deleting handlekatz file on share {self.share}: {e}")
self.delete_handlekatz_binary()

try:
connection.conn.deleteFile(self.share, self.tmp_share + machine_name)
Expand Down Expand Up @@ -182,3 +179,13 @@ def on_admin_login(self, context, connection):
add_user_bh(credz_bh, None, context.log, connection.config)
except Exception as e:
context.log.fail(f"Error opening dump file: {e}")

else:
self.delete_handlekatz_binary(connection, context)

def delete_handlekatz_binary(self, connection, context):
try:
connection.conn.deleteFile(self.share, self.tmp_share + self.handlekatz)
context.log.success(f"Deleted handlekatz file on the {self.share} share")
except Exception as e:
context.log.fail(f"[OPSEC] Error deleting handlekatz file on share {self.share}: {e}")
3 changes: 3 additions & 0 deletions nxc/modules/nanodump.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ def on_admin_login(self, context, connection):
except Exception as e:
self.context.log.fail(f"Error opening dump file: {e}")

else:
self.delete_nanodump_binary()

def delete_nanodump_binary(self):
try:
self.connection.execute(f"del {self.remote_tmp_dir + self.nano}")
Expand Down
16 changes: 11 additions & 5 deletions nxc/modules/procdump.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,7 @@ def on_admin_login(self, context, connection):
except Exception as e:
context.log.fail(f"Error while get file: {e}")

try:
connection.conn.deleteFile(self.share, self.tmp_share + self.procdump)
context.log.success(f"Deleted procdump file on the {self.share} share")
except Exception as e:
context.log.fail(f"Error deleting procdump file on share {self.share}: {e}")
self.delete_procdump_binary(connection, context)

try:
connection.conn.deleteFile(self.share, self.tmp_share + machine_name)
Expand Down Expand Up @@ -152,3 +148,13 @@ def on_admin_login(self, context, connection):
add_user_bh(credz_bh, None, context.log, connection.config)
except Exception as e:
context.log.fail("Error openning dump file", str(e))

else:
self.delete_procdump_binary(connection, context)

def delete_procdump_binary(self, connection, context):
try:
connection.conn.deleteFile(self.share, self.tmp_share + self.procdump)
context.log.success(f"Deleted procdump file on the {self.share} share")
except Exception as e:
context.log.fail(f"Error deleting procdump file on share {self.share}: {e}")