@@ -102,7 +102,10 @@ def run(self):
102102
103103 # Credential parsing
104104 username = self .args .username if self .args .username else ""
105+ file_username = self .args .file_username if self .args .file_username else username
106+
105107 password = self .args .password if self .args .password else ""
108+ file_password = self .args .file_password if self .args .file_password else password
106109
107110 lmhash , nthash = "" , ""
108111 if not password and self .args .hashes :
@@ -111,11 +114,27 @@ def run(self):
111114 else :
112115 lmhash , nthash = "aad3b435b51404eeaad3b435b51404ee" , self .args .hashes
113116
117+ file_lmhash , file_nthash = "" , ""
118+ if not file_password and self .args .file_hashes :
119+ if ":" in self .args .file_hashes :
120+ file_lmhash , file_nthash = self .args .file_hashes .split (":" )
121+ else :
122+ file_lmhash , file_nthash = "aad3b435b51404eeaad3b435b51404ee" , self .args .file_hashes
123+
124+
125+
126+
114127 # Exec methods parsing
115128 exec_methods = self .args .exec .split ("," ) if self .args .exec else None
116129 if exec_methods and "winrm" in exec_methods and len (exec_methods )> 1 :
117130 lsassy_logger .error (f"Incompatible methods winrm and { exec_methods } - can only use either winrm or others" )
118131
132+ # Ports parsing
133+ if self .args .file_port == 0 :
134+ self .args .file_port = 5985 if self .args .file_interaction == "winrm" else 445
135+ if self .args .port == 0 :
136+ self .args .port = 5985 if exec_methods and "winrm" in exec_methods else 445
137+
119138 # Dump modules options parsing
120139 options = (
121140 {v .split ("=" )[0 ]: v .split ("=" )[1 ] for v in self .args .options .split ("," )}
@@ -155,33 +174,57 @@ def run(self):
155174 return False
156175
157176 try :
158- if exec_methods and "winrm" in exec_methods :
177+ if self . args . file_interaction == "winrm" :
159178 session = WinrmSession ()
160- self .args .port = 5985
161179 else :
162180 session = Session ()
163181 session .get_session (
164182 address = self .target ,
165183 target_ip = self .target ,
166- port = self .args .port ,
167- lmhash = lmhash ,
168- nthash = nthash ,
169- username = username ,
170- password = password ,
184+ port = self .args .file_port ,
185+ lmhash = file_lmhash ,
186+ nthash = file_nthash ,
187+ username = file_username ,
188+ password = file_password ,
171189 domain = self .args .domain ,
172190 aesKey = self .args .aesKey ,
173191 dc_ip = self .args .dc_ip ,
174192 kerberos = self .args .kerberos ,
175193 timeout = self .args .timeout ,
176194 )
177195
196+ if exec_methods and "winrm" in exec_methods :
197+ exec_session = WinrmSession ()
198+ else :
199+ exec_session = Session ()
200+ # if the sessions are the same we dont want two sessions
201+ if isinstance (exec_session , type (session )):
202+ del exec_session
203+ exec_session = session
204+ else :
205+ exec_session .get_session (
206+ address = self .target ,
207+ target_ip = self .target ,
208+ port = self .args .port ,
209+ lmhash = lmhash ,
210+ nthash = nthash ,
211+ username = username ,
212+ password = password ,
213+ domain = self .args .domain ,
214+ aesKey = self .args .aesKey ,
215+ dc_ip = self .args .dc_ip ,
216+ kerberos = self .args .kerberos ,
217+ timeout = self .args .timeout ,
218+ )
219+
220+
178221 if session .smb_session is None :
179222 lsassy_logger .warning ("Couldn't connect to remote host" )
180223 return False
181224
182225 if not parse_only :
183226 dumper = Dumper (
184- session , self .args .timeout , self .args .time_between_commands
227+ exec_session , session , self .args .timeout , self .args .time_between_commands
185228 ).load (self .args .dump_method )
186229 if dumper is None :
187230 lsassy_logger .error ("Unable to load dump module" )
@@ -295,3 +338,11 @@ def run(self):
295338 lsassy_logger .debug (
296339 "Potential issue while closing SMB session: {}" .format (str (e ))
297340 )
341+ try :
342+ # Im not gonna break up the whole try except block. If exec_session is unassigned we dont care.
343+ exec_session .smb_session .close ()
344+ lsassy_logger .debug ("SMB session closed" )
345+ except Exception as e :
346+ lsassy_logger .debug (
347+ "Potential issue while closing SMB session: {}" .format (str (e ))
348+ )
0 commit comments