|
81 | 81 | from lib.core.settings import ROTATING_CHARS
|
82 | 82 | from lib.core.wordlist import Wordlist
|
83 | 83 | from thirdparty.colorama.initialise import init as coloramainit
|
| 84 | +from thirdparty.oset.pyoset import oset |
84 | 85 | from thirdparty.pydes.pyDes import des
|
85 | 86 | from thirdparty.pydes.pyDes import CBC
|
86 | 87 |
|
@@ -555,37 +556,37 @@ def storeHashesToFile(attack_dict):
|
555 | 556 | if not attack_dict:
|
556 | 557 | return
|
557 | 558 |
|
| 559 | + items = oset() |
| 560 | + |
| 561 | + for user, hashes in attack_dict.items(): |
| 562 | + for hash_ in hashes: |
| 563 | + hash_ = hash_.split()[0] if hash_ and hash_.strip() else hash_ |
| 564 | + if hash_ and hash_ != NULL and hashRecognition(hash_): |
| 565 | + item = None |
| 566 | + if user and not user.startswith(DUMMY_USER_PREFIX): |
| 567 | + item = "%s:%s\n" % (user.encode(UNICODE_ENCODING), hash_.encode(UNICODE_ENCODING)) |
| 568 | + else: |
| 569 | + item = "%s\n" % hash_.encode(UNICODE_ENCODING) |
| 570 | + |
| 571 | + if item and item not in items: |
| 572 | + items.add(item) |
| 573 | + |
558 | 574 | if kb.storeHashesChoice is None:
|
559 | 575 | message = "do you want to store hashes to a temporary file "
|
560 | 576 | message += "for eventual further processing with other tools [y/N] "
|
561 | 577 |
|
562 | 578 | kb.storeHashesChoice = readInput(message, default='N', boolean=True)
|
563 | 579 |
|
564 |
| - if not kb.storeHashesChoice: |
565 |
| - return |
566 |
| - |
567 |
| - handle, filename = tempfile.mkstemp(prefix=MKSTEMP_PREFIX.HASHES, suffix=".txt") |
568 |
| - os.close(handle) |
| 580 | + if kb.storeHashesChoice: |
| 581 | + handle, filename = tempfile.mkstemp(prefix=MKSTEMP_PREFIX.HASHES, suffix=".txt") |
| 582 | + os.close(handle) |
569 | 583 |
|
570 |
| - infoMsg = "writing hashes to a temporary file '%s' " % filename |
571 |
| - logger.info(infoMsg) |
572 |
| - |
573 |
| - items = set() |
574 |
| - |
575 |
| - with open(filename, "w+") as f: |
576 |
| - for user, hashes in attack_dict.items(): |
577 |
| - for hash_ in hashes: |
578 |
| - hash_ = hash_.split()[0] if hash_ and hash_.strip() else hash_ |
579 |
| - if hash_ and hash_ != NULL and hashRecognition(hash_): |
580 |
| - item = None |
581 |
| - if user and not user.startswith(DUMMY_USER_PREFIX): |
582 |
| - item = "%s:%s\n" % (user.encode(UNICODE_ENCODING), hash_.encode(UNICODE_ENCODING)) |
583 |
| - else: |
584 |
| - item = "%s\n" % hash_.encode(UNICODE_ENCODING) |
| 584 | + infoMsg = "writing hashes to a temporary file '%s' " % filename |
| 585 | + logger.info(infoMsg) |
585 | 586 |
|
586 |
| - if item and item not in items: |
587 |
| - f.write(item) |
588 |
| - items.add(item) |
| 587 | + with open(filename, "w+") as f: |
| 588 | + for item in items: |
| 589 | + f.write(item) |
589 | 590 |
|
590 | 591 | def attackCachedUsersPasswords():
|
591 | 592 | if kb.data.cachedUsersPasswords:
|
|
0 commit comments