Skip to content

Commit fad77dd

Browse files
committed
fix for a ImportError bug reported by g@brindi.si
1 parent 9cf33ec commit fad77dd

1 file changed

Lines changed: 26 additions & 24 deletions

File tree

lib/utils/hash.py

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
except ImportError, _:
1313
from extra.fcrypt.fcrypt import crypt
1414

15+
_multiprocessing = None
16+
try:
17+
import multiprocessing
18+
_multiprocessing = multiprocessing
19+
except ImportError, _: # problems on FreeBSD (Reference: http://www.velocityreviews.com/forums/t716510-freebsd-and-multiprocessing.html)
20+
pass
21+
1522
import os
1623
import re
1724
import time
@@ -56,9 +63,6 @@
5663
from lib.core.settings import UNICODE_ENCODING
5764
from lib.core.settings import ROTATING_CHARS
5865

59-
if PYVERSION >= "2.6":
60-
import multiprocessing
61-
6266
def mysql_passwd(password, uppercase=True):
6367
"""
6468
Reference(s):
@@ -558,15 +562,15 @@ def dictionaryAttack(attack_dict):
558562
retVal = None
559563

560564
try:
561-
if PYVERSION >= "2.6" and not IS_WIN:
562-
if multiprocessing.cpu_count() > 1:
563-
infoMsg = "starting %d processes " % multiprocessing.cpu_count()
565+
if _multiprocessing and not IS_WIN:
566+
if _multiprocessing.cpu_count() > 1:
567+
infoMsg = "starting %d processes " % _multiprocessing.cpu_count()
564568
singleTimeLogMessage(infoMsg)
565569

566570
processes = []
567-
retVal = multiprocessing.Queue()
568-
for i in xrange(multiprocessing.cpu_count()):
569-
p = multiprocessing.Process(target=__bruteProcessVariantA, args=(attack_info, hash_regex, kb.wordlist, suffix, retVal, i, multiprocessing.cpu_count()))
571+
retVal = _multiprocessing.Queue()
572+
for i in xrange(_multiprocessing.cpu_count()):
573+
p = _multiprocessing.Process(target=__bruteProcessVariantA, args=(attack_info, hash_regex, kb.wordlist, suffix, retVal, i, _multiprocessing.cpu_count()))
570574
processes.append(p)
571575

572576
for p in processes:
@@ -576,10 +580,9 @@ def dictionaryAttack(attack_dict):
576580
p.join()
577581

578582
else:
579-
if not IS_WIN:
580-
warnMsg = "multiprocessing not supported on current version of "
581-
warnMsg += "Python (%s < 2.6)" % PYVERSION
582-
singleTimeWarnMessage(warnMsg)
583+
warnMsg = "multiprocessing hash cracking is currently "
584+
warnMsg += "not supported on this platform"
585+
singleTimeWarnMessage(warnMsg)
583586

584587
retVal = Queue()
585588
__bruteProcessVariantA(attack_info, hash_regex, kb.wordlist, suffix, retVal, 0, 1)
@@ -614,17 +617,17 @@ def dictionaryAttack(attack_dict):
614617
retVal = None
615618

616619
try:
617-
if PYVERSION >= "2.6" and not IS_WIN:
618-
if multiprocessing.cpu_count() > 1:
619-
infoMsg = "starting %d processes " % multiprocessing.cpu_count()
620+
if _multiprocessing and not IS_WIN:
621+
if _multiprocessing.cpu_count() > 1:
622+
infoMsg = "starting %d processes " % _multiprocessing.cpu_count()
620623
singleTimeLogMessage(infoMsg)
621624

622625
processes = []
623-
retVal = multiprocessing.Queue()
624-
found_ = multiprocessing.Value('i', False)
626+
retVal = _multiprocessing.Queue()
627+
found_ = _multiprocessing.Value('i', False)
625628

626-
for i in xrange(multiprocessing.cpu_count()):
627-
p = multiprocessing.Process(target=__bruteProcessVariantB, args=(user, hash_, kwargs, hash_regex, kb.wordlist, suffix, retVal, found_, i, multiprocessing.cpu_count()))
629+
for i in xrange(_multiprocessing.cpu_count()):
630+
p = _multiprocessing.Process(target=__bruteProcessVariantB, args=(user, hash_, kwargs, hash_regex, kb.wordlist, suffix, retVal, found_, i, _multiprocessing.cpu_count()))
628631
processes.append(p)
629632

630633
for p in processes:
@@ -636,10 +639,9 @@ def dictionaryAttack(attack_dict):
636639
found = found_.value != 0
637640

638641
else:
639-
if not IS_WIN:
640-
warnMsg = "multiprocessing not supported on current version of "
641-
warnMsg += "Python (%s < 2.6)" % PYVERSION
642-
singleTimeWarnMessage(warnMsg)
642+
warnMsg = "multiprocessing hash cracking is currently "
643+
warnMsg += "not supported on this platform"
644+
singleTimeWarnMessage(warnMsg)
643645

644646
class Value():
645647
pass

0 commit comments

Comments
 (0)