|
|
|
#!/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/>
|
|
|
|
|
|
|
|
|
|
|
|
from multiprocessing import Queue
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
import os
|
|
|
|
import socketserver
|
|
|
|
|
|
|
|
from BF_ProcessBruteForce import *
|
|
|
|
from BF_MultyStationClient import *
|
|
|
|
from BF_MultyStationServer import *
|
|
|
|
from BF_InterfaceServer import *
|
|
|
|
from BF_GUI import *
|
|
|
|
from BF_Constants import *
|
|
|
|
from BF_Utils import *
|
|
|
|
from BF_Encryption import *
|
|
|
|
|
|
|
|
class App():
|
|
|
|
def __init__(self):
|
|
|
|
|
|
|
|
# le Gui gerre l'affichage
|
|
|
|
self.GUI = GUI()
|
|
|
|
#self.GUI.displayHeader()
|
|
|
|
|
|
|
|
#mode de fonctionement
|
|
|
|
self.local = False
|
|
|
|
self.server = False
|
|
|
|
self.client = False
|
|
|
|
|
|
|
|
#verbose
|
|
|
|
self.verbose = False
|
|
|
|
|
|
|
|
#parametre client mode
|
|
|
|
self.serverIP = ""
|
|
|
|
self.serverPort = 0
|
|
|
|
|
|
|
|
#parametre porcess
|
|
|
|
self.password = ""
|
|
|
|
self.encryptionKey = ""
|
|
|
|
self.hashMethod=""
|
|
|
|
self.maxLength = 0
|
|
|
|
self.firstProcessIndex = 0
|
|
|
|
self.nbProcess = 0
|
|
|
|
self.nbTotalProcess = 0
|
|
|
|
|
|
|
|
## La liste contenant nos object Processe
|
|
|
|
self.processes = list()
|
|
|
|
self.queue = multiprocessing.Queue()
|
|
|
|
self.infoQueue = multiprocessing.Queue()
|
|
|
|
self.found = False
|
|
|
|
self.appTime = time.time()
|
|
|
|
|
|
|
|
def initProcess(self):
|
|
|
|
if(self.nbProcess > os.cpu_count()):
|
|
|
|
self.GUI.displayError("localhost","Ressources", "Too many process allowed for your computer")
|
|
|
|
sys.exit()
|
|
|
|
for i in range(self.firstProcessIndex, self.firstProcessIndex+self.nbProcess):
|
|
|
|
p=ProcessBruteForce(self.queue, i,self.nbTotalProcess , self.password, self.encryptionKey, self.maxLength, self.verbose, self.hashMethod)
|
|
|
|
self.processes.append(p)
|
|
|
|
|
|
|
|
def menu(self):
|
|
|
|
# Mode selection
|
|
|
|
self.GUI.displayHeader()
|
|
|
|
entry = list()
|
|
|
|
entry.append("local Mode")
|
|
|
|
entry.append("lan Mode")
|
|
|
|
choice = self.GUI.createMenu("What 's your mode ?",entry,"\t")
|
|
|
|
if(choice == 1):
|
|
|
|
self.local=True
|
|
|
|
else:
|
|
|
|
self.local = False
|
|
|
|
self.GUI.displayHeader()
|
|
|
|
entry = list()
|
|
|
|
entry.append("server")
|
|
|
|
entry.append("client")
|
|
|
|
choice = self.GUI.createMenu("What 's your role ?",entry,"\t")
|
|
|
|
if(choice == 1):
|
|
|
|
self.server=True
|
|
|
|
else:
|
|
|
|
self.client=True
|
|
|
|
#Verbose mode
|
|
|
|
self.GUI.displayHeader()
|
|
|
|
entry = list()
|
|
|
|
entry.append("True")
|
|
|
|
entry.append("False")
|
|
|
|
choice = self.GUI.createMenu("Display Stats",entry,"\t")
|
|
|
|
if(choice == 1):
|
|
|
|
self.verbose=True
|
|
|
|
else:
|
|
|
|
self.verbose=False
|
|
|
|
|
|
|
|
#get server's IP address and port if client mode
|
|
|
|
if self.client:
|
|
|
|
self.GUI.displayHeader()
|
|
|
|
self.serverIP = self.GUI.getStringInputValue("What's the IP server address ?")
|
|
|
|
self.GUI.displayHeader()
|
|
|
|
self.serverPort = self.GUI.getIntInputValue("What's the server port ?")
|
|
|
|
|
|
|
|
if self.server:
|
|
|
|
self.GUI.displayHeader()
|
|
|
|
self.serverPort = self.GUI.getIntInputValue("What's the server port ?")
|
|
|
|
#Get number of core
|
|
|
|
self.GUI.displayHeader()
|
|
|
|
self.nbProcess = self.GUI.getIntInputValue("How many core want you allowed?")
|
|
|
|
|
|
|
|
if not self.client:
|
|
|
|
#Get max size of password
|
|
|
|
self.GUI.displayHeader()
|
|
|
|
self.maxLength = self.GUI.getIntInputValue("What 's the max size of password do you want to search?")
|
|
|
|
|
|
|
|
#Get password
|
|
|
|
self.GUI.displayHeader()
|
|
|
|
self.password = self.GUI.getStringInputValue("What's your hash ?")
|
|
|
|
|
|
|
|
#Get EncryptionKey
|
|
|
|
self.GUI.displayHeader()
|
|
|
|
self.encryptionKey = self.GUI.getStringInputValue("What's your encryption key ? (if you know it)")
|
|
|
|
|
|
|
|
#Get hashMethod
|
|
|
|
self.GUI.displayHeader()
|
|
|
|
entry = list()
|
|
|
|
entry.append(HASH_METHODS.HASH_METHOD.HASH_MD5.value)
|
|
|
|
entry.append(HASH_METHODS.HASH_METHOD.HASH_SHA1.value)
|
|
|
|
entry.append(HASH_METHODS.HASH_METHOD.HASH_SHA224.value)
|
|
|
|
entry.append(HASH_METHODS.HASH_METHOD.HASH_SHA256.value)
|
|
|
|
entry.append(HASH_METHODS.HASH_METHOD.HASH_SHA384.value)
|
|
|
|
entry.append(HASH_METHODS.HASH_METHOD.HASH_SHA512.value)
|
|
|
|
entry.append(HASH_METHODS.HASH_METHOD.HASH_NONE.value)
|
|
|
|
choiceValue = self.GUI.createMenuValue("Choose a Hash Method",entry,"\t")
|
|
|
|
self.hashMethod = choiceValue
|
|
|
|
|
|
|
|
#Clear screen
|
|
|
|
self.GUI.displayHeader()
|
|
|
|
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
if self.local :
|
|
|
|
self.localMode()
|
|
|
|
else:
|
|
|
|
if self.server:
|
|
|
|
self.serverMode()
|
|
|
|
else:
|
|
|
|
self.client = True
|
|
|
|
self.clientMode()
|
|
|
|
|
|
|
|
def clientMode(self):
|
|
|
|
self.GUI.displayHeader()
|
|
|
|
client = MultyStationClient(self.serverIP, self.serverPort)
|
|
|
|
client.configToServer(str(self.nbProcess))
|
|
|
|
serverAnswer = client.receive()
|
|
|
|
key, value = BF_Utils.getValueWithKey(serverAnswer)
|
|
|
|
print(key)
|
|
|
|
if key == ANSWER_STATES.MESSAGE_STATE.STATE_KO.value:
|
|
|
|
print(value)
|
|
|
|
else:
|
|
|
|
#mise en attente de la range
|
|
|
|
self.GUI.displayMessage(self.serverIP,"Mise en attente de la range")
|
|
|
|
value = client.listen()
|
|
|
|
self.nbTotalProcess, self.firstProcessIndex, self.password, self.encryptionKey, self.maxLength, self.hashMethod = client.initParamProcessing(value)
|
|
|
|
self.initProcess()
|
|
|
|
self.executeProcess()
|
|
|
|
sys.exit()
|
|
|
|
return
|
|
|
|
|
|
|
|
def serverMode(self):
|
|
|
|
server = MultyStationServer('',self.serverPort,self.nbProcess,self.password,'1234',self.maxLength,self.hashMethod)
|
|
|
|
server.connect()
|
|
|
|
server.run()
|
|
|
|
sys.exit()
|
|
|
|
return
|
|
|
|
|
|
|
|
def localMode(self):
|
|
|
|
self.firstProcessIndex = 0
|
|
|
|
self.nbTotalProcess = self.nbProcess
|
|
|
|
self.initProcess()
|
|
|
|
self.appTime = time.time()
|
|
|
|
self.executeProcess()
|
|
|
|
|
|
|
|
def initialisation(self):
|
|
|
|
self.GUI.displayCopyright()
|
|
|
|
if not self.gestionParams():
|
|
|
|
self.menu()
|
|
|
|
|
|
|
|
def gestionParams(self):
|
|
|
|
if len(sys.argv) > 1:
|
|
|
|
for argv in sys.argv:
|
|
|
|
if PARAMS_CONSTANTS.LONG_PARAMS.HELP.value == argv or PARAMS_CONSTANTS.SHORT_PARAMS.HELP.value == argv:
|
|
|
|
self.GUI.displayShortHelp()
|
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
elif PARAMS_CONSTANTS.LONG_PARAMS.HASH.value in argv:
|
|
|
|
clefParam = "".join(str.split(argv,"=")[0])
|
|
|
|
self.password = "".join(str.split(argv,clefParam + "="))
|
|
|
|
|
|
|
|
elif PARAMS_CONSTANTS.LONG_PARAMS.MODE.value in argv or PARAMS_CONSTANTS.SHORT_PARAMS.MODE.value in argv:
|
|
|
|
clefParam = "".join(str.split(argv,"=")[0])
|
|
|
|
mode = "".join(str.split(argv,clefParam + "="))
|
|
|
|
if mode == PARAMS_CONSTANTS.PARAMS_VALUE.MODE_LOCAL.value:
|
|
|
|
self.local = True
|
|
|
|
elif mode == PARAMS_CONSTANTS.PARAMS_VALUE.MODE_LAN.value:
|
|
|
|
self.local = False
|
|
|
|
else:
|
|
|
|
self.GUI.displayError("127.0.0.1","PARAMETERS","Attribut for " + clefParam + " no reconize : "+ mode)
|
|
|
|
self.GUI.displayShortHelp()
|
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
elif PARAMS_CONSTANTS.LONG_PARAMS.ROLE.value in argv or PARAMS_CONSTANTS.SHORT_PARAMS.ROLE.value in argv:
|
|
|
|
clefParam = "".join(str.split(argv,"=")[0])
|
|
|
|
mode = "".join(str.split(argv,clefParam + "="))
|
|
|
|
if mode == PARAMS_CONSTANTS.PARAMS_VALUE.ROLE_CLIENT.value:
|
|
|
|
self.client = True
|
|
|
|
self.server = False
|
|
|
|
elif mode == PARAMS_CONSTANTS.PARAMS_VALUE.ROLE_SERVER.value:
|
|
|
|
self.client = False
|
|
|
|
self.server = True
|
|
|
|
else:
|
|
|
|
self.GUI.displayError("127.0.0.1","PARAMETERS","Attribut for " + clefParam + " no reconize : "+ mode)
|
|
|
|
self.GUI.displayShortHelp()
|
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
elif PARAMS_CONSTANTS.LONG_PARAMS.ENCRYPTION_KEY.value in argv or PARAMS_CONSTANTS.SHORT_PARAMS.ENCRYPTION_KEY.value in argv:
|
|
|
|
clefParam = "".join(str.split(argv,"=")[0])
|
|
|
|
self.encryptionKey = "".join(str.split(argv,clefParam + "="))
|
|
|
|
|
|
|
|
elif PARAMS_CONSTANTS.LONG_PARAMS.SERVER_IP.value in argv or PARAMS_CONSTANTS.SHORT_PARAMS.SERVER_IP.value in argv:
|
|
|
|
clefParam = "".join(str.split(argv,"=")[0])
|
|
|
|
self.serverIP = "".join(str.split(argv,clefParam + "="))
|
|
|
|
|
|
|
|
elif PARAMS_CONSTANTS.LONG_PARAMS.PORT.value in argv or PARAMS_CONSTANTS.SHORT_PARAMS.PORT.value in argv:
|
|
|
|
clefParam = "".join(str.split(argv,"=")[0])
|
|
|
|
self.serverPort = int("".join(str.split(argv,clefParam + "=")))
|
|
|
|
|
|
|
|
elif PARAMS_CONSTANTS.LONG_PARAMS.CORE.value in argv or PARAMS_CONSTANTS.SHORT_PARAMS.CORE.value in argv:
|
|
|
|
clefParam = "".join(str.split(argv,"=")[0])
|
|
|
|
self.nbProcess = int("".join(str.split(argv,clefParam + "=")))
|
|
|
|
|
|
|
|
elif PARAMS_CONSTANTS.LONG_PARAMS.MAX_LENGTH.value in argv or PARAMS_CONSTANTS.SHORT_PARAMS.MAX_LENGTH.value in argv:
|
|
|
|
clefParam = "".join(str.split(argv,"=")[0])
|
|
|
|
self.maxLength = int("".join(str.split(argv,clefParam + "=")))
|
|
|
|
|
|
|
|
elif PARAMS_CONSTANTS.LONG_PARAMS.VERBOSE.value == argv or PARAMS_CONSTANTS.SHORT_PARAMS.VERBOSE.value == argv:
|
|
|
|
self.verbose = True
|
|
|
|
|
|
|
|
elif argv == sys.argv[0]:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
self.GUI.displayError("127.0.0.1","PARAMETERS","Unknown command \t" + argv)
|
|
|
|
self.GUI.displayShortHelp()
|
|
|
|
sys.exit()
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def executeProcess(self):
|
|
|
|
self.appTime = time.time()
|
|
|
|
for proc in self.processes:
|
|
|
|
proc.start()
|
|
|
|
|
|
|
|
procAlive=True
|
|
|
|
totalMotParSecondes = 0
|
|
|
|
if self.client:
|
|
|
|
self.serverInterface = InterfaceServer(self.serverPort +1)
|
|
|
|
self.serverInterface.start()
|
|
|
|
|
|
|
|
while procAlive:
|
|
|
|
totalMotParSecondes =0
|
|
|
|
procAlive =False
|
|
|
|
processTime = list()
|
|
|
|
words = list()
|
|
|
|
wordsSeconds = list()
|
|
|
|
currentWords = list()
|
|
|
|
porcessName = list()
|
|
|
|
if self.client:
|
|
|
|
if not self.serverInterface.is_alive():
|
|
|
|
for proc in self.processes:
|
|
|
|
proc.terminate()
|
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
for proc in self.processes:
|
|
|
|
#proc.join()
|
|
|
|
resultat = self.queue.get()
|
|
|
|
if resultat[0]== PROCESS_CONSTANTS.MESSAGE_RETURN_TYPE.RETURN.value :
|
|
|
|
if self.client :
|
|
|
|
if resultat[1] == True :
|
|
|
|
sock = MultyStationClient(self.serverIP, self.serverPort)
|
|
|
|
sock.resultToServer(resultat[2])
|
|
|
|
self.GUI.displayResult(resultat[2],self.appTime)
|
|
|
|
for proc in self.processes:
|
|
|
|
proc.terminate()
|
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
else :
|
|
|
|
if resultat[1] == True :
|
|
|
|
self.GUI.displayResult(resultat[2],self.appTime)
|
|
|
|
for proc in self.processes:
|
|
|
|
proc.terminate()
|
|
|
|
sys.exit()
|
|
|
|
elif resultat[0] == PROCESS_CONSTANTS.MESSAGE_RETURN_TYPE.PERFS.value :
|
|
|
|
words.append(resultat[1])
|
|
|
|
processTime.append(resultat[2])
|
|
|
|
currentWords.append(resultat[3])
|
|
|
|
porcessName.append(resultat[4])
|
|
|
|
wordsSeconds.append(round(resultat[1]/resultat[2]))
|
|
|
|
totalMotParSecondes = totalMotParSecondes + round(resultat[1]/resultat[2])
|
|
|
|
else:
|
|
|
|
self.GUI.displayError('localhost','useCase',str(resultat[0]) +" non traité")
|
|
|
|
|
|
|
|
#on verifie qu'il y a encore des process en cours (il n'y a pas de do while en python
|
|
|
|
if proc.is_alive():
|
|
|
|
procAlive =True
|
|
|
|
if self.verbose:
|
|
|
|
if self.client :
|
|
|
|
sock = MultyStationClient(self.serverIP, self.serverPort)
|
|
|
|
sock.infoToServerList(words,processTime,currentWords,porcessName)
|
|
|
|
else :
|
|
|
|
self.GUI.displayProcessPerfsList('localhost',porcessName,wordsSeconds,currentWords)
|
|
|
|
self.GUI.displayTotalPerfs('localhost',totalMotParSecondes)
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
#si le fichier est lancé seul
|
|
|
|
if __name__ == '__main__' :
|
|
|
|
application = App()
|
|
|
|
application.initialisation()
|
|
|
|
application.run()
|
|
|
|
sys.exit()
|