|
|
|
#!/usr/bin/python3.4
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# Copyright © 2015 Matthieu DUVAL, Rudy DUCHE
|
|
|
|
|
|
|
|
# This file is part of RizzleHash.
|
|
|
|
|
|
|
|
# RizzleHash is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
|
|
|
# RizzleHash is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with RizzleHash. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
|
|
|
|
import multiprocessing
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
|
|
|
|
from BF_Encryption import *
|
|
|
|
|
|
|
|
tabChar = list("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
|
|
|
|
|
|
|
|
class ProcessBruteForce(multiprocessing.Process):
|
|
|
|
def __init__(self,queue, idx, nbInstence,hash, clef, limite, verbose, hashMethode):
|
|
|
|
super().__init__()
|
|
|
|
self.queue = queue
|
|
|
|
self.idx = idx
|
|
|
|
self.nbInstence = nbInstence
|
|
|
|
|
|
|
|
#la queue contien 3 valeur :int useCase = 0, boolean found, list passTrouve
|
|
|
|
#la queue contien 5 valeur :int useCase = 1, nbMots, time secondes , list motEnCours nom du thread
|
|
|
|
#useCase = 0, on remonte les information contenant le mot Trouvé ou non
|
|
|
|
#useCase = 1, on remonte des information sur les performances
|
|
|
|
#gestion du temps
|
|
|
|
self.nbMot = 0
|
|
|
|
self.procTime = time.time()
|
|
|
|
self.verbose = verbose
|
|
|
|
self.hashMethodeFunction = self.getFunctionHash(hashMethode)
|
|
|
|
self.hash = hash
|
|
|
|
if(clef != None):
|
|
|
|
self.keySet = True
|
|
|
|
else:
|
|
|
|
self.keySet = False
|
|
|
|
|
|
|
|
self.clef = clef
|
|
|
|
self.limite = limite
|
|
|
|
self.password = ''
|
|
|
|
self.isFound = False
|
|
|
|
|
|
|
|
self.encryptionObject = Encryption()
|
|
|
|
return
|
|
|
|
|
|
|
|
def getFunctionHash(self, hashMethode):
|
|
|
|
|
|
|
|
function = None
|
|
|
|
cryptClass = Encryption()
|
|
|
|
|
|
|
|
if hashMethode == HASH_METHODS.HASH_METHOD.HASH_MD5.value:
|
|
|
|
function = (cryptClass.md5)
|
|
|
|
elif hashMethode == HASH_METHODS.HASH_METHOD.HASH_SHA1.value:
|
|
|
|
function = (cryptClass.sha1)
|
|
|
|
elif hashMethode == HASH_METHODS.HASH_METHOD.HASH_SHA224.value:
|
|
|
|
function = (cryptClass.sha224)
|
|
|
|
elif hashMethode == HASH_METHODS.HASH_METHOD.HASH_SHA256.value:
|
|
|
|
function = (cryptClass.sha256)
|
|
|
|
elif hashMethode == HASH_METHODS.HASH_METHOD.HASH_SHA384.value:
|
|
|
|
function = (cryptClass.sha384)
|
|
|
|
elif hashMethode == HASH_METHODS.HASH_METHOD.HASH_SHA512.value:
|
|
|
|
function = (cryptClass.sha512)
|
|
|
|
else:
|
|
|
|
function = (cryptClass.none)
|
|
|
|
return (function)
|
|
|
|
|
|
|
|
def testSpeed(self):
|
|
|
|
self.nbMot = self.nbMot+1
|
|
|
|
if (time.time() - self.procTime) > 5 :
|
|
|
|
self.queue.put([1,self.nbMot,time.time() - self.procTime, "".join(self.password),multiprocessing.current_process().name])
|
|
|
|
self.nbMot = 0
|
|
|
|
self.procTime = time.time()
|
|
|
|
|
|
|
|
def md5(self,string):
|
|
|
|
return hashlib.md5(string.encode('utf-8')).hexdigest()
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
self.bruteForce(self.hash)
|
|
|
|
|
|
|
|
def recursiveFunction(self,characters, size , isLast):
|
|
|
|
self.testSpeed()
|
|
|
|
if size == 0:
|
|
|
|
yield []
|
|
|
|
|
|
|
|
elif not isLast:
|
|
|
|
for i in range(len(characters)):
|
|
|
|
for j in self.recursiveFunction(characters[:i] + characters[i:], size - 1,False):
|
|
|
|
yield [characters[i]] + j
|
|
|
|
else:
|
|
|
|
indexMin = round((len(characters)/self.nbInstence)*self.idx)
|
|
|
|
indexMax = round(indexMin + (len(characters)/self.nbInstence))
|
|
|
|
if( self.idx == self.nbInstence - 1 ):
|
|
|
|
indexMax = len(tabChar)
|
|
|
|
for i in range(indexMin,indexMax):
|
|
|
|
for j in self.recursiveFunction(characters[:i] + characters[i:], size - 1,False):
|
|
|
|
yield [characters[i]] + j
|
|
|
|
|
|
|
|
def bruteForce(self,hash):
|
|
|
|
workRange = range(0,self.limite)
|
|
|
|
stringBuilder = ''
|
|
|
|
encryptWord = Encryption()
|
|
|
|
for length in workRange:
|
|
|
|
for i in self.recursiveFunction(tabChar, length,True):
|
|
|
|
self.password = stringBuilder + ''.join(i)
|
|
|
|
if encryptWord.hashForLambda(self.hashMethodeFunction,self.password) == hash:
|
|
|
|
self.queue.put([0,True, self.password])
|
|
|
|
return
|
|
|
|
|
|
|
|
self.queue.put([0,False, self.password])
|
|
|
|
#si le fichier est lancé seul
|
|
|
|
if __name__ == '__main__' :
|
|
|
|
sys.exit()
|