hash_1_16.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. def storeHashesToFile(attack_dict):
  2. if not attack_dict:
  3. return
  4. if kb.storeHashesChoice is None:
  5. message = "do you want to store hashes to a temporary file "
  6. message += "for eventual further processing with other tools [y/N] "
  7. test = readInput(message, default="N")
  8. kb.storeHashesChoice = test[0] in ("y", "Y")
  9. if not kb.storeHashesChoice:
  10. return
  11. handle, filename = tempfile.mkstemp(prefix=MKSTEMP_PREFIX.HASHES, suffix=".txt")
  12. os.close(handle)
  13. infoMsg = "writing hashes to a temporary file '%s' " % filename
  14. logger.info(infoMsg)
  15. items = set()
  16. with open(filename, "w+") as f:
  17. for user, hashes in attack_dict.items():
  18. for hash_ in hashes:
  19. hash_ = hash_.split()[0] if hash_ and hash_.strip() else hash_
  20. if hash_ and hash_ != NULL and hashRecognition(hash_):
  21. item = None
  22. if user and not user.startswith(DUMMY_USER_PREFIX):
  23. item = "%s:%s\n" % (user.encode(UNICODE_ENCODING), hash_.encode(UNICODE_ENCODING))
  24. else:
  25. item = "%s\n" % hash_.encode(UNICODE_ENCODING)
  26. if item and item not in items:
  27. f.write(item)
  28. items.add(item)