|
|
@ -1,22 +1,72 @@
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import time
|
|
|
|
import multiprocessing
|
|
|
|
import sys
|
|
|
|
import sys
|
|
|
|
|
|
|
|
import time
|
|
|
|
import locale
|
|
|
|
import locale
|
|
|
|
|
|
|
|
|
|
|
|
tempsN_1 = time.time();
|
|
|
|
|
|
|
|
globalTime = time.time()
|
|
|
|
|
|
|
|
nbMot = 0
|
|
|
|
|
|
|
|
passwordCrypte = ""
|
|
|
|
|
|
|
|
tabChar = list("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ")
|
|
|
|
tabChar = list("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ")
|
|
|
|
|
|
|
|
nbProcess = 4
|
|
|
|
verbose = False
|
|
|
|
verbose = False
|
|
|
|
def main():
|
|
|
|
|
|
|
|
gestionParams()
|
|
|
|
class App():
|
|
|
|
tabPass =list("a")
|
|
|
|
def __init__(self):
|
|
|
|
global passwordCrypte
|
|
|
|
|
|
|
|
found, passTrouve = testPass(True,0,tabPass,passwordCrypte)
|
|
|
|
## La liste contenant nos object Processe
|
|
|
|
if found == True :
|
|
|
|
self.processes = list()
|
|
|
|
if(time.time() - globalTime) > 60 :
|
|
|
|
self.queue = multiprocessing.Queue()
|
|
|
|
seconds = time.time() - globalTime
|
|
|
|
self.infoQueue = multiprocessing.Queue()
|
|
|
|
|
|
|
|
self.found = False
|
|
|
|
|
|
|
|
self.appTime = time.time()
|
|
|
|
|
|
|
|
global nbProcess
|
|
|
|
|
|
|
|
global verbose
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for i in range(0,nbProcess):
|
|
|
|
|
|
|
|
p=ProcessBrurteForce(self.queue, i,nbProcess , "totor","",4,verbose)
|
|
|
|
|
|
|
|
self.processes.append(p)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
|
|
|
|
for proc in self.processes:
|
|
|
|
|
|
|
|
proc.start()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
procAlive=True
|
|
|
|
|
|
|
|
totalMotParSecondes =0
|
|
|
|
|
|
|
|
while procAlive:
|
|
|
|
|
|
|
|
totalMotParSecondes =0
|
|
|
|
|
|
|
|
procAlive =False
|
|
|
|
|
|
|
|
for proc in self.processes:
|
|
|
|
|
|
|
|
#proc.join()
|
|
|
|
|
|
|
|
resultat = self.queue.get()
|
|
|
|
|
|
|
|
if resultat[0]== 0 :
|
|
|
|
|
|
|
|
if resultat[1] == True :
|
|
|
|
|
|
|
|
#print("RESULT: %s" % resultat[2])
|
|
|
|
|
|
|
|
self.displayResult(resultat[2])
|
|
|
|
|
|
|
|
for proc in self.processes:
|
|
|
|
|
|
|
|
proc.terminate()
|
|
|
|
|
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
elif resultat[0] == 1:
|
|
|
|
|
|
|
|
WordsSeconds = round(resultat[1]/resultat[2])
|
|
|
|
|
|
|
|
totalMotParSecondes = totalMotParSecondes + WordsSeconds
|
|
|
|
|
|
|
|
locale.setlocale(locale.LC_ALL, 'french_france')
|
|
|
|
|
|
|
|
WordsSeconds = locale.format('%d', WordsSeconds, grouping=True)
|
|
|
|
|
|
|
|
print(resultat[4]+" : " + '{:>30}'.format(WordsSeconds) + " Mots/s \tMot actuel : " + resultat[3])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
print("/!\ useCase" + resultat[0] +"non traité")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#on verifie qu'il y a encore des process en cours (il n'y ap aps de do while en python
|
|
|
|
|
|
|
|
if proc.is_alive():
|
|
|
|
|
|
|
|
procAlive =True
|
|
|
|
|
|
|
|
if verbose:
|
|
|
|
|
|
|
|
locale.setlocale(locale.LC_ALL, 'french_france')
|
|
|
|
|
|
|
|
totalMotParSecondes = locale.format('%d', totalMotParSecondes, grouping=True)
|
|
|
|
|
|
|
|
print("Mots Par Secondes : " +'{:>30}'.format(totalMotParSecondes)+ " Mots/s")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def displayResult(self,passTrouve):
|
|
|
|
|
|
|
|
if(time.time() - self.appTime) > 60 :
|
|
|
|
|
|
|
|
seconds = time.time() - self.appTime
|
|
|
|
m, s = divmod(seconds, 60)
|
|
|
|
m, s = divmod(seconds, 60)
|
|
|
|
h, m = divmod(m, 60)
|
|
|
|
h, m = divmod(m, 60)
|
|
|
|
d ,h = divmod(h, 24)
|
|
|
|
d ,h = divmod(h, 24)
|
|
|
@ -27,111 +77,98 @@ def main():
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
print("Found ! : " + passTrouve +" en " + "%d:%02d" % (m, s))
|
|
|
|
print("Found ! : " + passTrouve +" en " + "%d:%02d" % (m, s))
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
print("Found ! : " + passTrouve +" en " + str(time.time() - globalTime) + " secondes")
|
|
|
|
print("Found ! : " + passTrouve +" en " + str(time.time() - self.appTime) + " secondes")
|
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
def gestionParams():
|
|
|
|
|
|
|
|
passSet = False
|
|
|
|
|
|
|
|
global passwordCrypte
|
|
|
|
|
|
|
|
global verbose
|
|
|
|
|
|
|
|
if len(sys.argv) > 1:
|
|
|
|
|
|
|
|
for argv in sys.argv:
|
|
|
|
|
|
|
|
if "--help" == argv or "-h" == argv:
|
|
|
|
|
|
|
|
helpMessage()
|
|
|
|
|
|
|
|
elif "--pass" in argv or "-p" in argv:
|
|
|
|
|
|
|
|
tabParam = "".join(str.split(argv,"=")[0])
|
|
|
|
|
|
|
|
passwordCrypte = "".join(str.split(argv,tabParam + "="))
|
|
|
|
|
|
|
|
for char in passwordCrypte:
|
|
|
|
|
|
|
|
if char not in tabChar:
|
|
|
|
|
|
|
|
print("Error : Unavaliable caractere \t" + char)
|
|
|
|
|
|
|
|
print()
|
|
|
|
|
|
|
|
helpMessage()
|
|
|
|
|
|
|
|
print("Searched password : \t"+ passwordCrypte)
|
|
|
|
|
|
|
|
passSet = True
|
|
|
|
|
|
|
|
elif "--verbose" == argv or "-v" == argv:
|
|
|
|
|
|
|
|
print("/!\ Verbose : Worst performance")
|
|
|
|
|
|
|
|
verbose = True
|
|
|
|
|
|
|
|
elif argv == sys.argv[0]:
|
|
|
|
|
|
|
|
print()
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
print("Error : Unknown command \t" + argv)
|
|
|
|
|
|
|
|
print()
|
|
|
|
|
|
|
|
helpMessage()
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
print("Error : You need to set a password to Search")
|
|
|
|
|
|
|
|
print()
|
|
|
|
|
|
|
|
helpMessage()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if passSet == False:
|
|
|
|
class ProcessBrurteForce(multiprocessing.Process):
|
|
|
|
print("Error : You need to set a password to Search")
|
|
|
|
def __init__(self,queue, idx, nbInstence,password, clef, limite, verbose):
|
|
|
|
print()
|
|
|
|
super().__init__()
|
|
|
|
helpMessage()
|
|
|
|
self.queue = queue
|
|
|
|
|
|
|
|
self.idx = idx
|
|
|
|
def helpMessage():
|
|
|
|
self.nbInstence = nbInstence
|
|
|
|
print("Usage : " )
|
|
|
|
|
|
|
|
print("\t--help, -h\t Print this message")
|
|
|
|
#la queue contien 3 valeur :int useCase = 0, boolean found, list passTrouve
|
|
|
|
print("\t--pass=[passwordSearch], -p=[passwordSearch]")
|
|
|
|
#la queue contien 5 valeur :int useCase = 1, nbMots, time secondes , list motEnCours nom du thread
|
|
|
|
print("\t\tSelect pasword to Search")
|
|
|
|
#useCase = 0, on remonte les information contenant le mot Trouvé ou non
|
|
|
|
print("\t--verbose, -v\t More output")
|
|
|
|
#useCase = 1, on remonte des information sur les performances
|
|
|
|
print()
|
|
|
|
#gestion du temps
|
|
|
|
sys.exit()
|
|
|
|
self.nbMot = 0
|
|
|
|
|
|
|
|
self.procTime = time.time()
|
|
|
|
def testSpeed(tabPass):
|
|
|
|
self.verbose = verbose
|
|
|
|
global nbMot
|
|
|
|
|
|
|
|
global tempsN_1
|
|
|
|
self.password = password
|
|
|
|
if (time.time() - tempsN_1) > 5 :
|
|
|
|
self.clef = clef
|
|
|
|
WordsSeconds = round(nbMot/(time.time() - tempsN_1))
|
|
|
|
self.limite = limite
|
|
|
|
locale.setlocale(locale.LC_ALL, 'french_france')
|
|
|
|
self.tabPass = list("a")
|
|
|
|
WordsSeconds = locale.format('%d', WordsSeconds, grouping=True)
|
|
|
|
self.isFound = False
|
|
|
|
str_number = str(ord('a'))
|
|
|
|
return
|
|
|
|
print('{:>30}'.format(WordsSeconds) + " Mots/s \tMot actuel : " + "".join(tabPass))
|
|
|
|
|
|
|
|
nbMot = 0
|
|
|
|
def testSpeed(self):
|
|
|
|
tempsN_1 = time.time()
|
|
|
|
self.nbMot = self.nbMot+1
|
|
|
|
|
|
|
|
if (time.time() - self.procTime) > 5 :
|
|
|
|
def testPass(isFirst, pos, tabPass, password ):
|
|
|
|
self.queue.put([1,self.nbMot,time.time() - self.procTime, "".join(self.tabPass),multiprocessing.current_process().name])
|
|
|
|
found = False
|
|
|
|
self.nbMot = 0
|
|
|
|
passTrouve = ""
|
|
|
|
self.procTime = time.time()
|
|
|
|
global nbMot
|
|
|
|
|
|
|
|
global tempsN_1
|
|
|
|
|
|
|
|
global verbose
|
|
|
|
|
|
|
|
#Première boucle, permet de parcourir l'enssembles des caractères du tableau
|
|
|
|
|
|
|
|
for char in tabChar:
|
|
|
|
|
|
|
|
tabPass[pos] = char
|
|
|
|
|
|
|
|
if verbose == True:
|
|
|
|
|
|
|
|
nbMot = nbMot +1;
|
|
|
|
|
|
|
|
testSpeed(tabPass)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if "".join(tabPass) == password:
|
|
|
|
def run(self):
|
|
|
|
found=True
|
|
|
|
#print(multiprocessing.current_process().name + "\tStart")
|
|
|
|
passTrouve = "".join(tabPass)
|
|
|
|
found , passTrouve = self.checkChar(0)
|
|
|
|
return found, passTrouve
|
|
|
|
if not found:
|
|
|
|
#else:
|
|
|
|
while not found and len(self.tabPass) < self.limite:
|
|
|
|
#print("".join(tabPass) + "\t | " + str(len(tabPass)))
|
|
|
|
self.tabPass = self.tabPass + list('a')
|
|
|
|
|
|
|
|
found,passTrouve =self.recursiveFunction(len(self.tabPass)-1)
|
|
|
|
|
|
|
|
if found == True :
|
|
|
|
|
|
|
|
passTrouve = "".join(self.tabPass)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not found :
|
|
|
|
|
|
|
|
indexMin = round((len(tabChar)/self.nbInstence)*self.idx)
|
|
|
|
|
|
|
|
indexMax = round(indexMin + (len(tabChar)/self.nbInstence))
|
|
|
|
|
|
|
|
self.tabPass = self.tabPass + list(tabChar[indexMin])
|
|
|
|
|
|
|
|
#print(multiprocessing.current_process().name + "\tRange : " + str(indexMin) + " - " + str(indexMax))
|
|
|
|
|
|
|
|
for i in range(indexMin,indexMax):
|
|
|
|
|
|
|
|
self.tabPass[len(self.tabPass)-1] = tabChar[i]
|
|
|
|
|
|
|
|
found,passTrouve =self.recursiveFunction(len(self.tabPass)-2)
|
|
|
|
|
|
|
|
if found == True:
|
|
|
|
|
|
|
|
#la queue contien 2 valeur : boolean found, list passTrouve
|
|
|
|
|
|
|
|
#la queue contien 4 valeur : nbMots, time secondes , list motEnCours nom du thread
|
|
|
|
|
|
|
|
self.queue.put([0,found, passTrouve])
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
# Seconde boucle, ne s'execute que si on est dans la première instance de la fonction,
|
|
|
|
print(multiprocessing.current_process().name + "\tStop")
|
|
|
|
# elle permet de rajouter les caractère au fur et à mesure
|
|
|
|
#la queue contien 2 valeur : boolean found, list passTrouve
|
|
|
|
|
|
|
|
#la queue contien 4 valeur : nbMots, time secondes , list motEnCours nom du thread
|
|
|
|
|
|
|
|
self.queue.put([0,found, passTrouve])
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
if isFirst == True and found == False:
|
|
|
|
def recursiveFunction(self,index):
|
|
|
|
while found != True:
|
|
|
|
found , passTrouve = self.checkChar(index)
|
|
|
|
tabPass = tabPass + list('a')
|
|
|
|
if index > 0 and not found:
|
|
|
|
found,passTrouve =testPass(False,len(tabPass)-1 , tabPass,password)
|
|
|
|
for char in tabChar :
|
|
|
|
if found == True :
|
|
|
|
self.tabPass[index] = char
|
|
|
|
found=True
|
|
|
|
found, passTrouve =self.recursiveFunction(index-1)
|
|
|
|
passTrouve = "".join(tabPass)
|
|
|
|
if found == True :
|
|
|
|
return found, passTrouve
|
|
|
|
passTrouve = "".join(self.tabPass)
|
|
|
|
|
|
|
|
return found, passTrouve
|
|
|
|
# Troisième boucle, elle permet d'itéré el caractère précédent dans la chainde de caractère
|
|
|
|
|
|
|
|
if pos > 0 and found == False:
|
|
|
|
return found, passTrouve
|
|
|
|
for char in tabChar :
|
|
|
|
|
|
|
|
tabPass[pos] = char
|
|
|
|
#Cette fonction permet de replacer le dernier caractère de la Chaine
|
|
|
|
found, passTrouve =testPass(False,pos-1, tabPass,password)
|
|
|
|
def checkChar(self,index):
|
|
|
|
if found == True :
|
|
|
|
found = False
|
|
|
|
|
|
|
|
passTrouve = ""
|
|
|
|
|
|
|
|
for char in tabChar:
|
|
|
|
|
|
|
|
if self.verbose:
|
|
|
|
|
|
|
|
self.testSpeed()
|
|
|
|
|
|
|
|
self.tabPass[index] = char
|
|
|
|
|
|
|
|
if "".join(self.tabPass) == self.password:
|
|
|
|
found=True
|
|
|
|
found=True
|
|
|
|
passTrouve = "".join(tabPass)
|
|
|
|
passTrouve = "".join(self.tabPass)
|
|
|
|
return found, passTrouve
|
|
|
|
return found, passTrouve
|
|
|
|
passTrouve = "".join(tabPass)
|
|
|
|
#print("".join(self.tabPass))
|
|
|
|
return found , passTrouve
|
|
|
|
return found, passTrouve
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__' :
|
|
|
|
#si le fichier est lancé seul
|
|
|
|
main()
|
|
|
|
if __name__ == '__main__' :
|
|
|
|
|
|
|
|
application = App()
|
|
|
|
|
|
|
|
application.run()
|
|
|
|
|
|
|
|
sys.exit()
|