@@ -121,8 +121,6 @@ def enum_host_info(self):
121121 except :
122122 pass
123123
124- self .create_conn_obj ()
125-
126124 def print_host_info (self ):
127125 if len (self .mssql_instances ) > 0 :
128126 self .logger .info ("MSSQL DB Instances: {}" .format (len (self .mssql_instances )))
@@ -166,6 +164,11 @@ def check_if_admin(self):
166164 return True
167165
168166 def plaintext_login (self , domain , username , password ):
167+ try :
168+ self .conn .disconnect ()
169+ except :
170+ pass
171+ self .create_conn_obj ()
169172
170173 try :
171174 res = self .conn .login (None , username , password , domain , None , self .args .auth_type == 'windows' )
@@ -199,9 +202,6 @@ def plaintext_login(self, domain, username, password):
199202 e ))
200203 return False
201204
202- self .conn .disconnect ()
203- self .create_conn_obj ()
204-
205205 def hash_login (self , domain , username , ntlm_hash ):
206206 lmhash = ''
207207 nthash = ''
@@ -212,33 +212,43 @@ def hash_login(self, domain, username, ntlm_hash):
212212 else :
213213 nthash = ntlm_hash
214214
215- res = self .conn .login (None , username , '' , domain , ':' + nthash if not lmhash else ntlm_hash , True )
216- if res is not True :
217- self .conn .printReplies ()
218- if self .args .no_bruteforce :
219- self .conn .disconnect ()
220- self .create_conn_obj ()
221- return False
215+ try :
216+ self .conn .disconnect ()
217+ except :
218+ pass
219+ self .create_conn_obj ()
222220
223- self .hash = ntlm_hash
224- self .username = username
225- self .domain = domain
226- self .check_if_admin ()
227- self .db .add_credential ('hash' , domain , username , ntlm_hash )
221+ try :
222+ res = self .conn .login (None , username , '' , domain , ':' + nthash if not lmhash else ntlm_hash , True )
223+ if res is not True :
224+ self .conn .printReplies ()
225+ if self .args .no_bruteforce :
226+ self .conn .disconnect ()
227+ self .create_conn_obj ()
228+ return False
228229
229- if self .admin_privs :
230- self .db .add_admin_user ('hash' , domain , username , ntlm_hash , self .host )
230+ self .hash = ntlm_hash
231+ self .username = username
232+ self .domain = domain
233+ self .check_if_admin ()
234+ self .db .add_credential ('hash' , domain , username , ntlm_hash )
231235
232- out = u'{}\\ {} {} {}' .format (domain ,
233- username ,
234- ntlm_hash ,
235- highlight ('({})' .format (self .config .get ('CME' , 'pwn3d_label' )) if self .admin_privs else '' ))
236- self .logger .success (out )
237- if not self .args .continue_on_success :
238- return True
236+ if self .admin_privs :
237+ self .db .add_admin_user ('hash' , domain , username , ntlm_hash , self .host )
239238
240- self .conn .disconnect ()
241- self .create_conn_obj ()
239+ out = u'{}\\ {} {} {}' .format (domain ,
240+ username ,
241+ ntlm_hash ,
242+ highlight ('({})' .format (self .config .get ('CME' , 'pwn3d_label' )) if self .admin_privs else '' ))
243+ self .logger .success (out )
244+ if not self .args .continue_on_success :
245+ return True
246+ except Exception as e :
247+ self .logger .error (u'{}\\ {}:{} {}' .format (domain ,
248+ username ,
249+ ntlm_hash ,
250+ e ))
251+ return False
242252
243253 def mssql_query (self ):
244254 self .conn .sql_query (self .args .mssql_query )
0 commit comments