1616
1717from extra .pydes .pyDes import des
1818from extra .pydes .pyDes import CBC
19+ from lib .core .common import checkFile
1920from lib .core .common import conf
2021from lib .core .common import dataToStdout
2122from lib .core .common import getFileItems
@@ -191,11 +192,23 @@ def dictionaryAttack():
191192
192193 hash_ = hash_ .split ()[0 ]
193194
194- for _ , regex in getPublicTypeMembers (HASH ):
195- if re .match (regex , hash_ ):
195+ for name , regex in getPublicTypeMembers (HASH ):
196+ if kb .dbms == DBMS .ORACLE and regex == HASH .MYSQL_OLD :
197+ continue
198+ elif kb .dbms == DBMS .MYSQL and regex == HASH .ORACLE_OLD :
199+ continue
200+ elif re .match (regex , hash_ ):
196201 rehash = regex
202+ infoMsg = "using hash method: '%s'" % name
203+ logger .info (infoMsg )
197204 break
198205
206+ if rehash :
207+ break
208+
209+ if rehash :
210+ break
211+
199212 if rehash :
200213 for (user , hashes ) in kb .data .cachedUsersPasswords .items ():
201214 for hash_ in hashes :
@@ -207,7 +220,7 @@ def dictionaryAttack():
207220 if re .match (rehash , hash_ ):
208221 hash_ = hash_ .lower ()
209222
210- if rehash in (HASH .MYSQL , HASH .MYSQL_OLD , HASH .MD5_GENERIC , HASH .SHA1_GENERIC ) and kb . dbms != DBMS . ORACLE :
223+ if rehash in (HASH .MYSQL , HASH .MYSQL_OLD , HASH .MD5_GENERIC , HASH .SHA1_GENERIC ):
211224 attack_info .append ([(user , hash_ ), {}])
212225 elif rehash in (HASH .ORACLE_OLD , HASH .POSTGRES ):
213226 attack_info .append ([(user , hash_ ), {'username' : user }])
@@ -216,24 +229,34 @@ def dictionaryAttack():
216229 elif rehash in (HASH .MSSQL , HASH .MSSQL_OLD ):
217230 attack_info .append ([(user , hash_ ), {'salt' : hash_ [6 :14 ]}])
218231
219- infoMsg = "loading dictionary from: '%s'" % paths .WORDLIST_TXT
232+ if rehash == HASH .ORACLE_OLD : #it's the slowest of all methods hence smaller default dict
233+ message = "what's the dictionary's location? [%s]" % paths .ORACLE_DEFAULT_PASSWD
234+ dictpath = readInput (message , default = paths .ORACLE_DEFAULT_PASSWD )
235+
236+ else :
237+ message = "what's the dictionary's location? [%s]" % paths .WORDLIST
238+ dictpath = readInput (message , default = paths .WORDLIST )
239+
240+ checkFile (dictpath )
241+
242+ infoMsg = "loading dictionary from: '%s'" % dictpath
220243 logger .info (infoMsg )
221- wordlist = getFileItems (paths . WORDLIST_TXT , None , False )
244+ wordlist = getFileItems (dictpath , None , False )
222245
223246 infoMsg = "running dictionary attack"
224247 logger .info (infoMsg )
225248
226249 length = len (wordlist )
227250
228- if rehash in (HASH .MYSQL , HASH .MYSQL_OLD , HASH .MD5_GENERIC , HASH .SHA1_GENERIC ) and kb . dbms != DBMS . ORACLE :
251+ if rehash in (HASH .MYSQL , HASH .MYSQL_OLD , HASH .MD5_GENERIC , HASH .SHA1_GENERIC ):
229252 count = 0
230253 for word in wordlist :
231254 count += 1
232255 current = __functions__ [rehash ](password = word , uppercase = False )
233256 for item in attack_info :
234257 ((user , hash_ ), _ ) = item
235258
236- if count % 1117 == 0 or count == length :
259+ if count % 1117 == 0 or count == length or rehash in ( HASH . ORACLE_OLD ) :
237260 status = '%d/%d words (%d%s)' % (count , length , round (100.0 * count / length ), '%' )
238261 dataToStdout ("\r [%s] [INFO] %s" % (time .strftime ("%X" ), status ), True )
239262
@@ -242,25 +265,30 @@ def dictionaryAttack():
242265 #dataToStdout("\r[%s] [INFO] found: %s:%s\n" % (time.strftime("%X"), user, word), True)
243266 attack_info .remove (item )
244267
268+ dataToStdout ("\n " , True )
245269 else :
246270 for ((user , hash_ ), kwargs ) in attack_info :
247271 count = 0
248272 for word in wordlist :
249273 current = __functions__ [rehash ](password = word , uppercase = False , ** kwargs )
250274
251275 count += 1
252- if count % 1117 == 0 or count == length :
253- status = '%d/%d words (%d%s)' % (count , length , round (100.0 * count / length ), '%' )
276+ if count % 1117 == 0 or count == length or rehash in ( HASH . ORACLE_OLD ) :
277+ status = '%d/%d words (%d%s) (user: %s) ' % (count , length , round (100.0 * count / length ), '%' , user )
254278 dataToStdout ("\r [%s] [INFO] %s" % (time .strftime ("%X" ), status ), True )
255279
256280 if hash_ == current :
257281 results .append ((user , hash_ , word ))
258282 #dataToStdout("\r[%s] [INFO] found: %s:%s\n" % (time.strftime("%X"), user, word), True)
259283 break
260284
261- dataToStdout ("\n " , True )
285+ dataToStdout ("\n " , True )
286+
262287 blank = " "
263288 for (user , hash_ , password ) in results :
264289 for i in xrange (len (kb .data .cachedUsersPasswords [user ])):
265290 if kb .data .cachedUsersPasswords [user ][i ] and hash_ .lower () in kb .data .cachedUsersPasswords [user ][i ].lower ():
266291 kb .data .cachedUsersPasswords [user ][i ] += "%s%spassword: %s" % ('\n ' if kb .data .cachedUsersPasswords [user ][i ][- 1 ] != '\n ' else '' , blank , password )
292+ else :
293+ errMsg = "hash format unrecognized"
294+ logger .error (errMsg )
0 commit comments