From ef33729381b3e08b5cceb39952e6f1a1dea1c156 Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Wed, 12 Dec 2012 09:59:24 +0100 Subject: [PATCH] Writing only unique hashes to an output file (for eventual cracking with 3rd party tools) --- lib/utils/hash.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/utils/hash.py b/lib/utils/hash.py index 0815d19e0..485e50b41 100644 --- a/lib/utils/hash.py +++ b/lib/utils/hash.py @@ -312,15 +312,23 @@ def storeHashesToFile(attack_dict): warnMsg += "for eventual further processing with other tools" logger.warn(warnMsg) + items = set() + with open(filename, "w+") as f: for user, hashes in attack_dict.items(): for hash_ in hashes: if not hash_ or hash_ == NULL or not hashRecognition(hash_): continue + + item = None if user and not user.startswith(DUMMY_USER_PREFIX): - f.write("%s:%s\n" % (user.encode(UNICODE_ENCODING), hash_.encode(UNICODE_ENCODING))) + item = "%s:%s\n" % (user.encode(UNICODE_ENCODING), hash_.encode(UNICODE_ENCODING)) else: - f.write("%s\n" % hash_.encode(UNICODE_ENCODING)) + item = "%s\n" % hash_.encode(UNICODE_ENCODING) + + if item and item not in items: + f.write(item) + items.add(item) def attackCachedUsersPasswords(): if kb.data.cachedUsersPasswords: