Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a14697e

Browse files
committed
Implementation for an Issue #272
1 parent 6b007ab commit a14697e

1 file changed

Lines changed: 27 additions & 18 deletions

File tree

lib/utils/hash.py

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,28 @@ def _encode64(input_, count):
300300
HASH.WORDPRESS: wordpress_passwd
301301
}
302302

303+
def storeHashesToFile(attack_dict):
304+
if not attack_dict:
305+
return
306+
307+
handle, filename = tempfile.mkstemp(suffix=".txt")
308+
os.close(handle)
309+
310+
warnMsg = "writing hashes to file '%s' " % filename
311+
warnMsg += "for eventual further processing with other tools"
312+
logger.warn(warnMsg)
313+
314+
with open(filename, "w+") as f:
315+
for user, hashes in attack_dict.items():
316+
for hash_ in hashes:
317+
if user and not user.startswith(DUMMY_USER_PREFIX):
318+
f.write("%s:%s\n" % (user.encode(UNICODE_ENCODING), hash_.encode(UNICODE_ENCODING)))
319+
else:
320+
f.write("%s\n" % hash_.encode(UNICODE_ENCODING))
321+
303322
def attackCachedUsersPasswords():
304323
if kb.data.cachedUsersPasswords:
324+
storeHashesToFile(kb.data.cachedUsersPasswords)
305325
results = dictionaryAttack(kb.data.cachedUsersPasswords)
306326

307327
for (_, hash_, password) in results:
@@ -360,9 +380,13 @@ def attackDumpedTable():
360380
col_passwords.add(column)
361381

362382
if attack_dict:
363-
message = "recognized possible password hashes in column%s " % ("s" if len(col_passwords) > 1 else "")
364-
message += "'%s'. Do you want to " % ", ".join(col for col in col_passwords)
365-
message += "crack them via a dictionary-based attack? %s" % ("[y/N/q]" if conf.multipleTargets else "[Y/n/q]")
383+
infoMsg = "recognized possible password hashes in column%s " % ("s" if len(col_passwords) > 1 else "")
384+
infoMsg += "'%s'" % ", ".join(col for col in col_passwords)
385+
logger.info(infoMsg)
386+
387+
storeHashesToFile(attack_dict)
388+
389+
message = "do you want to crack them via a dictionary-based attack? %s" % ("[y/N/q]" if conf.multipleTargets else "[Y/n/q]")
366390
test = readInput(message, default="N" if conf.multipleTargets else "Y")
367391

368392
if test[0] in ("n", "N"):
@@ -826,21 +850,6 @@ class Value():
826850

827851
results.extend(resumes)
828852

829-
fp = None
830-
for user, hash_ in user_hash:
831-
if not any(_[1] == hash_ for _ in results):
832-
if fp is None:
833-
handle, filename = tempfile.mkstemp(suffix=".txt")
834-
os.close(handle)
835-
fp = open(filename, "w+")
836-
singleTimeLogMessage("writing uncracked hashes to file '%s' for eventual further processing" % filename)
837-
if user and not user.startswith(DUMMY_USER_PREFIX):
838-
fp.write("%s:%s\n" % (user.encode(UNICODE_ENCODING), hash_.encode(UNICODE_ENCODING)))
839-
else:
840-
fp.write("%s\n" % hash_.encode(UNICODE_ENCODING))
841-
if fp:
842-
fp.close()
843-
844853
if len(hash_regexes) == 0:
845854
warnMsg = "unknown hash format. "
846855
warnMsg += "Please report by e-mail to %s" % ML

0 commit comments

Comments
 (0)