parent
e06f39baae
commit
109ed57adc
@ -0,0 +1,89 @@
|
||||
#!/usr/bin/python3
|
||||
# -*- coding: utf-8 -*-
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class APPLICATION_CONSTANTS():
|
||||
NAME= "Brute Force Pass"
|
||||
VERSION = "0.6.5 - rc1"
|
||||
|
||||
class LAN_CONSTANTS():
|
||||
class MESSAGE_KEY(Enum):
|
||||
NB_CORE_CLIENT = "nbCoreClient" #peramètre passé dans la requette doit etre suivit du nombre de coeur aloué pour le calcul
|
||||
NB_CORE_TOTAL = "nbCoreTotal"
|
||||
INDEX_CORE_MIN = "indexCoreMin"
|
||||
CRYPTED_PASSWORD = "cryptedPassword"
|
||||
ENCRYPTION_KEY = "encryptionKey"
|
||||
HASH_METHOD = "hashMethode"
|
||||
PASSWORD_MAX_LENGTH = "passwordMaxLength"
|
||||
MESSAGE_TYPE = "type"
|
||||
RETURN_STATE = "returnState"
|
||||
NB_WORDS = "nbWords"
|
||||
PROCESS_TIME = "processTime"
|
||||
WORD = "word"
|
||||
LOCAL_THREAD_NAME = "threadName"
|
||||
|
||||
class MESSAGE_VALUE(Enum) :
|
||||
TYPE_INFO = "info"
|
||||
TYPE_CONFIG = "config"
|
||||
TYPE_ERROR = "error"
|
||||
TYPE_RESULT = "result"
|
||||
TYPE_DEFAULT = "default"
|
||||
STATE_OK = "OK"
|
||||
STATE_KO = "KO"
|
||||
|
||||
class MESSAGE_SPECIAL_CHAR(Enum) :
|
||||
SEPARATOR = ','
|
||||
ASIGNATOR = ':'
|
||||
SAME_VALUE_SEPRATOR = ';'
|
||||
|
||||
class PROCESS_CONSTANTS():
|
||||
class MESSAGE_RETURN_TYPE(Enum):
|
||||
PERFS = 1
|
||||
RETURN = 0
|
||||
|
||||
class PARAMS_CONSTANTS():
|
||||
class LONG_PARAMS(Enum):
|
||||
VERBOSE = "--verbose"
|
||||
HELP = "--help"
|
||||
MODE = "--mode"
|
||||
HASH = "--hash"
|
||||
ENCRYPTION_KEY = "--key"
|
||||
PORT = "--port"
|
||||
SERVER_IP = "--ip"
|
||||
ROLE = "--role"
|
||||
SECRET_PARAM = "--cd"
|
||||
CORE = "--core"
|
||||
MAX_LENGTH = "--length"
|
||||
|
||||
class SHORT_PARAMS(Enum):
|
||||
VERBOSE = "-v"
|
||||
HELP = "-h"
|
||||
MODE = "-m"
|
||||
ENCRYPTION_KEY = "-k"
|
||||
PORT = "-p"
|
||||
SERVER_IP = "-s"
|
||||
ROLE = "-r"
|
||||
CORE = "-c"
|
||||
MAX_LENGTH = "-l"
|
||||
|
||||
class PARAMS_VALUE(Enum):
|
||||
MODE_LOCAL = "local"
|
||||
MODE_LAN = "lan"
|
||||
ROLE_CLIENT = "client"
|
||||
ROLE_SERVER = "server"
|
||||
|
||||
class ANSWER_STATES():
|
||||
class MESSAGE_STATE(Enum):
|
||||
STATE_OK = "OK"
|
||||
STATE_KO = "KO"
|
||||
|
||||
class HASH_METHODS():
|
||||
class HASH_METHOD(Enum):
|
||||
HASH_MD5 = "md5"
|
||||
HASH_SHA1 = "sha1"
|
||||
HASH_SHA224 = "sha224"
|
||||
HASH_SHA256 = "sha256"
|
||||
HASH_SHA384 = "sha384"
|
||||
HASH_SHA512 = "sha512"
|
||||
HASH_NONE = "None"
|
@ -0,0 +1,15 @@
|
||||
#!/usr/bin/python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
import ctypes
|
||||
import time
|
||||
import platform
|
||||
|
||||
|
||||
class EasterEgg():
|
||||
def openTray(self):
|
||||
if platform.system() == 'Linux':
|
||||
os.system("eject -t cdrom")
|
||||
else:
|
||||
ctypes.windll.winmm.mciSendStringW("set cdaudio door open", None, 0, None)
|
@ -0,0 +1,51 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import hashlib
|
||||
import random
|
||||
|
||||
from BF_Constants import *
|
||||
|
||||
tabChar = list("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
|
||||
|
||||
class Encryption():
|
||||
def __init__(self):
|
||||
self.passwordNonCrypte = ""
|
||||
self.key = ""
|
||||
self.typeCryptage = ""
|
||||
self.passwordCrypte = ""
|
||||
return None
|
||||
|
||||
def getRandKey(self, keySize):
|
||||
keyRand = ""
|
||||
i = 0
|
||||
while i < keySize:
|
||||
keyRand = keyRand + round(randrange(0, len(tabChar)),0)
|
||||
return keyRand
|
||||
|
||||
def md5(self, string):
|
||||
return hashlib.md5(string.encode('utf-8')).hexdigest()
|
||||
|
||||
def sha1(self, string):
|
||||
return hashlib.sha1(string.encode('utf-8')).hexdigest()
|
||||
|
||||
def sha224(self, string):
|
||||
return hashlib.sha224(string.encode('utf-8')).hexdigest()
|
||||
|
||||
def sha384(self, string):
|
||||
return hashlib.sha384(string.encode('utf-8')).hexdigest()
|
||||
|
||||
def sha256(self, string):
|
||||
return hashlib.sha256(string.encode('utf-8')).hexdigest()
|
||||
|
||||
def sha512(self, string):
|
||||
return hashlib.sha512(string.encode('utf-8')).hexdigest()
|
||||
|
||||
def none(self, string):
|
||||
return string
|
||||
|
||||
def hashForLambda(self, functionLambda, string):
|
||||
return functionLambda(string)
|
||||
|
||||
|
||||
#si le fichier est lancé seul
|
||||
if __name__ == '__main__' :
|
||||
sys.exit()
|
@ -0,0 +1,248 @@
|
||||
#!/usr/bin/python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
import platform
|
||||
import locale
|
||||
from datetime import datetime
|
||||
import time
|
||||
import BF_Utils
|
||||
from BF_Constants import *
|
||||
|
||||
class GUI():
|
||||
def __init__(self):
|
||||
self.guiStartTime = str(datetime.now().time().strftime("%H:%M:%S"))
|
||||
self.guiTime=time.time()
|
||||
self.appName = APPLICATION_CONSTANTS.NAME+ " V" +APPLICATION_CONSTANTS.VERSION
|
||||
self.headerLines = self.prepareHeader()
|
||||
return
|
||||
|
||||
def prepareHeader(self):
|
||||
lines = list()
|
||||
info = list()
|
||||
lenGui = len(self.appName)
|
||||
info.append("System family : " + str(platform.system()))
|
||||
info.append("System release : " + str(platform.release()))
|
||||
info.append("Processor Core : " + str(os.cpu_count()))
|
||||
info.append("App Started at : "+self.guiStartTime)
|
||||
for value in info:
|
||||
if len(value) > lenGui:
|
||||
lenGui = len(value)
|
||||
|
||||
lines.append(self.separationLineCreator("+","+","-",lenGui+2))
|
||||
lines.append(self.centredLine("| "," |"," ",self.appName,lenGui))
|
||||
lines.append(self.separationLineCreator("+","+","-",lenGui+2))
|
||||
|
||||
for content in info:
|
||||
lines.append(str(self.leftAlignLine("| "," |"," ",content,lenGui)))
|
||||
|
||||
lines.append(self.separationLineCreator("+","+","-",lenGui+2))
|
||||
return lines
|
||||
|
||||
|
||||
def separationLineCreator(self,leftBorder,rightBorder,separator,lenGui):
|
||||
listSeparationLine = list()
|
||||
listSeparationLine.append(leftBorder)
|
||||
for i in range (0, lenGui):
|
||||
listSeparationLine.append(separator)
|
||||
listSeparationLine.append(rightBorder)
|
||||
separationLine = "".join(listSeparationLine)
|
||||
return separationLine
|
||||
|
||||
def centredLine(self,leftBorder,rightBorder,offsetChar,value,lenGui):
|
||||
lenSpace = (lenGui - len(value))/2
|
||||
if lenSpace.is_integer():
|
||||
lenSpaceLeft = int(lenSpace)
|
||||
lenSpaceRight = int(lenSpace)
|
||||
else :
|
||||
lenSpaceLeft = round(lenSpace)
|
||||
if( round(lenSpace) < lenSpace ):
|
||||
lenSpaceRight = round(lenSpace)+ 1
|
||||
else:
|
||||
lenSpaceRight = round(lenSpace)- 1
|
||||
|
||||
listSpaceLeft = list()
|
||||
for i in range(0,lenSpaceLeft):
|
||||
listSpaceLeft.append(offsetChar)
|
||||
|
||||
listSpaceRight = list()
|
||||
for i in range(0,lenSpaceRight):
|
||||
listSpaceRight.append(offsetChar)
|
||||
|
||||
centeredLine = leftBorder+"".join(listSpaceLeft) + value + "".join(listSpaceRight)+rightBorder
|
||||
return centeredLine
|
||||
|
||||
def tableLine(self,offsetChar,value1,value2,lenMaxValue1):
|
||||
tableLine = ""
|
||||
listSpaceSeparator = list()
|
||||
for i in range(0,lenMaxValue1 - len(value1)):
|
||||
listSpaceSeparator.append(offsetChar)
|
||||
|
||||
tableLine = value1+"".join(listSpaceSeparator)+value2
|
||||
return tableLine
|
||||
|
||||
def leftAlignLine(self,leftBorder,rightBorder,offsetChar,value,lenGui):
|
||||
lenSpaceRight = lenGui - len(value)
|
||||
listSpaceRight = list()
|
||||
for i in range(0,lenSpaceRight):
|
||||
listSpaceRight.append(offsetChar)
|
||||
|
||||
leftAlignLine = leftBorder+value+"".join(listSpaceRight)+rightBorder
|
||||
return leftAlignLine
|
||||
|
||||
def clearScreen(self):
|
||||
if platform.system() == 'Linux':
|
||||
os.system('clear')
|
||||
else:
|
||||
os.system('cls')
|
||||
|
||||
def setLocale(self):
|
||||
if platform.system() == 'Linux':
|
||||
locale.setlocale(locale.LC_ALL, 'french')
|
||||
else:
|
||||
locale.setlocale(locale.LC_ALL, 'french_france')
|
||||
|
||||
def displayHeader(self):
|
||||
self.clearScreen()
|
||||
for line in self.headerLines:
|
||||
print(line)
|
||||
|
||||
def displayProcessPerfs(self, host, processName, WordsSeconds, curentWord):
|
||||
self.setLocale()
|
||||
WordsSeconds = locale.format('%d', WordsSeconds, grouping=True)
|
||||
print("Host : " + host )
|
||||
print("\t"+ processName+" : " + '{:>10}'.format(WordsSeconds) + " Word/s \tCurrent word: " + curentWord)
|
||||
return
|
||||
|
||||
def displayProcessPerfsList(self, host, processName, WordsSeconds, curentWord):
|
||||
self.setLocale()
|
||||
print("Host : " + host )
|
||||
for i in range(0,len(processName)):
|
||||
WordsSeconds[i] = locale.format('%d', WordsSeconds[i], grouping=True)
|
||||
print("\t"+ processName[i]+" : " + '{:>10}'.format(WordsSeconds[i]) + " Word/s \tCurrent word: " + curentWord[i])
|
||||
return
|
||||
|
||||
def displayTotalPerfs(self, host,WordsSeconds):
|
||||
self.setLocale()
|
||||
WordsSeconds = locale.format('%d', WordsSeconds, grouping=True)
|
||||
print("Word Per Second : " +'{:>10}'.format(WordsSeconds)+ " Word/s")
|
||||
|
||||
def displayError(self, host,errorCode, errorMessage):
|
||||
print("Error at : " + host)
|
||||
print("\t"+errorCode + " : " + errorMessage)
|
||||
|
||||
def displayMessage(self,host,message):
|
||||
print("From " + host + ": " + message )
|
||||
|
||||
def displayResult(self,value,timeSeconds):
|
||||
if(time.time() - timeSeconds) > 60 :
|
||||
seconds = time.time() - timeSeconds
|
||||
d,h,m,s = self.formatTime(seconds)
|
||||
|
||||
if d != 0:
|
||||
print("Found ! : " + value +" in " + "%d:%02d:%02d:%02d" % (d,h, m, s))
|
||||
elif h != 0 :
|
||||
print("Found ! : " + value +" in " + "%d:%02d:%02d" % (h, m, s))
|
||||
else:
|
||||
print("Found ! : " + value +" in " + "%d:%02d" % (m, s))
|
||||
else:
|
||||
print("Found ! : " + value +" in " + str(round(time.time() - timeSeconds,2)) + " second")
|
||||
return
|
||||
|
||||
def formatTime(self,seconds):
|
||||
m, s = divmod(seconds, 60)
|
||||
h, m = divmod(m, 60)
|
||||
d ,h = divmod(h, 24)
|
||||
return d,h,m,s
|
||||
|
||||
def displayShortHelp(self):
|
||||
print()
|
||||
print("Usage : " )
|
||||
leftTab = list()
|
||||
leftTab.append("\t"+PARAMS_CONSTANTS.LONG_PARAMS.HELP.value+", "+ PARAMS_CONSTANTS.SHORT_PARAMS.HELP.value)
|
||||
leftTab.append("\t"+PARAMS_CONSTANTS.LONG_PARAMS.HASH.value+"=[passwordSearch]")
|
||||
leftTab.append("\t"+PARAMS_CONSTANTS.LONG_PARAMS.VERBOSE.value+", "+ PARAMS_CONSTANTS.SHORT_PARAMS.VERBOSE.value)
|
||||
leftTab.append("\t"+PARAMS_CONSTANTS.LONG_PARAMS.MODE.value+", " +PARAMS_CONSTANTS.SHORT_PARAMS.MODE.value)
|
||||
|
||||
rightTab = list()
|
||||
rightTab.append("Display help message")
|
||||
rightTab.append("Set hash to search")
|
||||
rightTab.append("Set verbose mode")
|
||||
rightTab.append("Set application mode")
|
||||
|
||||
|
||||
maxLenLeft = 0
|
||||
for value in leftTab:
|
||||
if len(value) > maxLenLeft:
|
||||
maxLenLeft = len(value)
|
||||
|
||||
for i in range(0,len(leftTab)):
|
||||
print(self.tableLine(" ",leftTab[i],rightTab[i],maxLenLeft+4))
|
||||
print()
|
||||
|
||||
def displayFullHelp(self):
|
||||
pass
|
||||
|
||||
def displayVersion(self):
|
||||
print()
|
||||
print(APPLICATION_CONSTANTS.NAME + " version " + APPLICATION_CONSTANTS.VERSION)
|
||||
|
||||
def getStringInputValue(self,question):
|
||||
print()
|
||||
return input(question +" ")
|
||||
|
||||
def getIntInputValue(self,question):
|
||||
print()
|
||||
userChoice = input(question +" ")
|
||||
if not BF_Utils.is_int(userChoice):
|
||||
self.displayHeader()
|
||||
print()
|
||||
self.displayError("localhost","EntryError","Input is not a Number !")
|
||||
userChoice = self.getIntInputValue(question)
|
||||
return int(userChoice)
|
||||
|
||||
def createMenu(self,title,entryList,margin):
|
||||
print()
|
||||
print(title)
|
||||
print()
|
||||
for i in range(0,len(entryList)):
|
||||
print(margin+ str(i + 1) + " - " + entryList[i])
|
||||
print()
|
||||
userChoice = input()
|
||||
if BF_Utils.is_int(userChoice):
|
||||
if not (int(userChoice)> 0 and int(userChoice) <= len(entryList)):
|
||||
self.displayHeader()
|
||||
print()
|
||||
self.displayError("localhost","EntryError","Choice not in the list !")
|
||||
userChoice = self.displayMenu(title,entryList,margin)
|
||||
|
||||
else:
|
||||
self.displayHeader()
|
||||
print()
|
||||
self.displayError("localhost","EntryError","Input is not a Number !")
|
||||
userChoice = self.displayMenu(title,entryList,margin)
|
||||
return int(userChoice)
|
||||
|
||||
def createMenuValue(self,title,entryList,margin):
|
||||
print()
|
||||
print(title)
|
||||
print()
|
||||
for i in range(0,len(entryList)):
|
||||
print(margin+ str(i + 1) + " - " + entryList[i])
|
||||
print()
|
||||
userChoice = input()
|
||||
if BF_Utils.is_int(userChoice):
|
||||
if not (int(userChoice)> 0 and int(userChoice) <= len(entryList)):
|
||||
self.displayHeader()
|
||||
print()
|
||||
self.displayError("localhost","EntryError","Choice not in the list !")
|
||||
userChoice = self.displayMenu(title,entryList,margin)
|
||||
|
||||
else:
|
||||
self.displayHeader()
|
||||
print()
|
||||
self.displayError("localhost","EntryError","Input is not a Number !")
|
||||
userChoice = self.displayMenu(title,entryList,margin)
|
||||
return entryList[int(userChoice) - 1]
|
||||
|
||||
|
@ -0,0 +1,51 @@
|
||||
#!/usr/bin/python3
|
||||
# -*- coding: utf-8 -*-
|
||||
import socketserver
|
||||
from threading import Thread
|
||||
import signal
|
||||
|
||||
from BF_Constants import *
|
||||
from BF_EasterEgg import *
|
||||
import BF_Utils
|
||||
FOUND = False
|
||||
|
||||
class InterfaceServerHandler(socketserver.BaseRequestHandler):
|
||||
def handle(self):
|
||||
self.messageType = LAN_CONSTANTS.MESSAGE_VALUE.TYPE_DEFAULT.value
|
||||
self.messageState = LAN_CONSTANTS.MESSAGE_VALUE.STATE_OK.value
|
||||
self.data = self.request.recv(1024).strip()
|
||||
self.traitementResponse(self.data.decode('utf-8'),self.client_address[0])
|
||||
|
||||
if self.messageType == LAN_CONSTANTS.MESSAGE_VALUE.TYPE_RESULT.value:
|
||||
if self.messageState == LAN_CONSTANTS.MESSAGE_VALUE.STATE_OK.value:
|
||||
#self.request.sendall(bytes(BF_Utils.createMessage(LAN_CONSTANTS.MESSAGE_KEY.MESSAGE_KEY.RETURN_STATE.value,LAN_CONSTANTS.MESSAGE_VALUE.STATE_OK.value,False),"utf-8"))
|
||||
|
||||
global FOUND
|
||||
FOUND = True
|
||||
easterEgg = EasterEgg()
|
||||
easterEgg.openTray()
|
||||
self.finish()
|
||||
|
||||
|
||||
def traitementResponse(self,param,clientAdress):
|
||||
errorMessage = list()
|
||||
errorCode = list()
|
||||
argvArray = param.split(LAN_CONSTANTS.MESSAGE_SPECIAL_CHAR.SEPARATOR.value)
|
||||
for object in argvArray:
|
||||
key,value = BF_Utils.getValueWithKey(object)
|
||||
if key == LAN_CONSTANTS.MESSAGE_KEY.MESSAGE_TYPE.value:
|
||||
self.messageType = value
|
||||
elif key == LAN_CONSTANTS.MESSAGE_KEY.RETURN_STATE.value :
|
||||
self.messageState = value
|
||||
elif key == LAN_CONSTANTS.MESSAGE_KEY.WORD.value :
|
||||
self.word = value
|
||||
|
||||
class InterfaceServer(Thread):
|
||||
def __init__(self,port):
|
||||
Thread.__init__(self)
|
||||
self.port = port
|
||||
|
||||
def run(self):
|
||||
server = socketserver.TCPServer(('', self.port), InterfaceServerHandler)
|
||||
while not FOUND:
|
||||
server.handle_request()
|
@ -0,0 +1,12 @@
|
||||
#!/usr/bin/python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from threding import Thread,queue
|
||||
|
||||
class DisplayThread(Threadin.thread):
|
||||
def __init__(self,queue)
|
||||
super.__init__()
|
||||
self.queue = queue
|
||||
|
||||
def run(self):
|
||||
pass
|
@ -0,0 +1,328 @@
|
||||
#!/usr/bin/python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
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):
|
||||
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()
|
@ -0,0 +1,124 @@
|
||||
#!/usr/bin/python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import socket
|
||||
import sys
|
||||
import time
|
||||
import BF_Utils
|
||||
from BF_Constants import *
|
||||
|
||||
|
||||
class MultyStationClient:
|
||||
def __init__(self, serverAdress, serveurPort):
|
||||
super().__init__()
|
||||
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
self.serverAdress = serverAdress
|
||||
self.serveurPort = serveurPort
|
||||
|
||||
def connect(self):
|
||||
self.sock.connect((self.serverAdress, self.serveurPort))
|
||||
|
||||
def listen(self):
|
||||
newSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
newSocket.bind(('',self.serveurPort + 1))
|
||||
newSocket.listen(1)
|
||||
|
||||
chunks = []
|
||||
bytes_recd = 0
|
||||
#newSocket.connect(('', self.serveurPort + 1))
|
||||
while bytes_recd < 5:
|
||||
conn, addr = newSocket.accept()
|
||||
#print("test addr: "+ str(addr))
|
||||
chunk = conn.recv(min(2048 - bytes_recd, 2048))
|
||||
#if chunk == b'':
|
||||
# raise RuntimeError("socket connection broken")
|
||||
chunks.append(chunk)
|
||||
bytes_recd = bytes_recd + len(chunk)
|
||||
data = b''.join(chunks).decode("UTF-8")
|
||||
conn.sendall(bytes(data,"UTF-8"))
|
||||
if data:
|
||||
break
|
||||
return data
|
||||
|
||||
def initParamProcessing(self, param):
|
||||
errorMessage = list()
|
||||
errorCode = list()
|
||||
argvArray = param.split(LAN_CONSTANTS.MESSAGE_SPECIAL_CHAR.SEPARATOR.value)
|
||||
for object in argvArray:
|
||||
key, value = BF_Utils.getValueWithKey(object)
|
||||
if key == LAN_CONSTANTS.MESSAGE_KEY.NB_CORE_TOTAL.value:
|
||||
nbCoreTotal = int(value)
|
||||
elif key == LAN_CONSTANTS.MESSAGE_KEY.INDEX_CORE_MIN.value:
|
||||
indexCoreMin = int(value)
|
||||
elif key == LAN_CONSTANTS.MESSAGE_KEY.CRYPTED_PASSWORD.value:
|
||||
cryptedPassword = value
|
||||
elif key == LAN_CONSTANTS.MESSAGE_KEY.ENCRYPTION_KEY.value:
|
||||
encryptionKey = value
|
||||
elif key == LAN_CONSTANTS.MESSAGE_KEY.PASSWORD_MAX_LENGTH.value:
|
||||
passwordMaxLength = int(value)
|
||||
elif key == LAN_CONSTANTS.MESSAGE_KEY.HASH_METHOD.value:
|
||||
hashMethod = value
|
||||
|
||||
return nbCoreTotal, indexCoreMin, cryptedPassword, encryptionKey, passwordMaxLength,hashMethod
|
||||
|
||||
def send(self, msg):
|
||||
totalsent = 0
|
||||
while totalsent < 5:
|
||||
sent = self.sock.send(msg[totalsent:])
|
||||
if sent == 0:
|
||||
raise RuntimeError("socket connection broken")
|
||||
totalsent = totalsent + sent
|
||||
sent = sent +1
|
||||
|
||||
def configToServer(self,nbProcess):
|
||||
self.connect()
|
||||
msg = BF_Utils.createMessage(LAN_CONSTANTS.MESSAGE_KEY.MESSAGE_TYPE.value,LAN_CONSTANTS.MESSAGE_VALUE.TYPE_CONFIG.value,True)
|
||||
msg = msg + BF_Utils.createMessage(LAN_CONSTANTS.MESSAGE_KEY.NB_CORE_CLIENT.value,nbProcess,False)
|
||||
self.send(bytes(msg,"utf-8"))
|
||||
|
||||
def infoToServer(self,nbWord,processTime,word,threadName):
|
||||
self.connect()
|
||||
msg = BF_Utils.createMessage(LAN_CONSTANTS.MESSAGE_KEY.MESSAGE_TYPE.value,LAN_CONSTANTS.MESSAGE_VALUE.TYPE_INFO.value,True)
|
||||
msg = msg + BF_Utils.createMessage(LAN_CONSTANTS.MESSAGE_KEY.NB_WORDS.value,nbWord,True)
|
||||
msg = msg + BF_Utils.createMessage(LAN_CONSTANTS.MESSAGE_KEY.PROCESS_TIME.value,processTime,True)
|
||||
msg = msg + BF_Utils.createMessage(LAN_CONSTANTS.MESSAGE_KEY.WORD.value,word,True)
|
||||
msg = msg + BF_Utils.createMessage(LAN_CONSTANTS.MESSAGE_KEY.LOCAL_THREAD_NAME.value,threadName,False)
|
||||
self.send(bytes(msg,"utf-8"))
|
||||
|
||||
def infoToServerList(self,nbWord,processTime,word,threadName):
|
||||
self.connect()
|
||||
msg = BF_Utils.createMessage(LAN_CONSTANTS.MESSAGE_KEY.MESSAGE_TYPE.value,LAN_CONSTANTS.MESSAGE_VALUE.TYPE_INFO.value,True)
|
||||
msg = msg + BF_Utils.createMessageList(LAN_CONSTANTS.MESSAGE_KEY.NB_WORDS.value,nbWord,True)
|
||||
msg = msg + BF_Utils.createMessageList(LAN_CONSTANTS.MESSAGE_KEY.PROCESS_TIME.value,processTime,True)
|
||||
msg = msg + BF_Utils.createMessageList(LAN_CONSTANTS.MESSAGE_KEY.WORD.value,word,True)
|
||||
msg = msg + BF_Utils.createMessageList(LAN_CONSTANTS.MESSAGE_KEY.LOCAL_THREAD_NAME.value,threadName,False)
|
||||
self.send(bytes(msg,"utf-8"))
|
||||
|
||||
#time.sleep(0.1)
|
||||
#self.receive()
|
||||
|
||||
def resultToServer(self,word):
|
||||
self.connect()
|
||||
msg = BF_Utils.createMessage(LAN_CONSTANTS.MESSAGE_KEY.MESSAGE_TYPE.value,LAN_CONSTANTS.MESSAGE_VALUE.TYPE_RESULT.value,True)
|
||||
msg = msg + BF_Utils.createMessage(LAN_CONSTANTS.MESSAGE_KEY.RETURN_STATE.value,LAN_CONSTANTS.MESSAGE_VALUE.STATE_OK.value,True)
|
||||
msg = msg + BF_Utils.createMessage(LAN_CONSTANTS.MESSAGE_KEY.WORD.value,word,False)
|
||||
self.send(bytes(msg,"utf-8"))
|
||||
|
||||
def receive(self):
|
||||
chunks = []
|
||||
bytes_recd = 0
|
||||
while bytes_recd < 5:
|
||||
chunk = self.sock.recv(min(2048 - bytes_recd, 2048))
|
||||
#if chunk == b'':
|
||||
# raise RuntimeError("socket connection broken")
|
||||
chunks.append(chunk)
|
||||
bytes_recd = bytes_recd + len(chunk)
|
||||
return b''.join(chunks).decode("UTF-8")
|
||||
|
||||
if __name__ == '__main__' :
|
||||
client = MultyStationClient('127.0.0.1',2323)
|
||||
client.connect()
|
||||
client.send(bytes('nbCore:4','UTF-8'))
|
||||
print(client.receive())
|
||||
|
||||
sys.exit()
|
@ -0,0 +1,265 @@
|
||||
#!/usr/bin/python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import socketserver
|
||||
import socket
|
||||
import sys
|
||||
import time
|
||||
import signal
|
||||
import BF_Utils
|
||||
from BF_Constants import *
|
||||
from BF_GUI import *
|
||||
|
||||
COEUR_CONNECTE = 0
|
||||
IP_CONNECTE = list()
|
||||
CLIENT = list()
|
||||
NB_COEUR = 0
|
||||
PASSWORD_FOUND = ""
|
||||
FOUND = False
|
||||
|
||||
class MultyStationServerHandler(socketserver.BaseRequestHandler):
|
||||
"""
|
||||
The RequestHandler class for our server.
|
||||
|
||||
It is instantiated once per connection to the server, and must
|
||||
override the handle() method to implement communication to the
|
||||
client.
|
||||
"""
|
||||
|
||||
|
||||
def __init__(self, request, client_address, server):
|
||||
self.request = request
|
||||
self.client_address = client_address
|
||||
self.server = server
|
||||
self.setup()
|
||||
self.coreClient = 0
|
||||
self.client = list()
|
||||
self.GUI = GUI()
|
||||
self.messageType = LAN_CONSTANTS.MESSAGE_VALUE.TYPE_DEFAULT.value
|
||||
|
||||
global COEUR_CONNECTE
|
||||
global CLIENT
|
||||
try:
|
||||
self.handle()
|
||||
COEUR_CONNECTE = COEUR_CONNECTE + self.coreClient
|
||||
CLIENT = CLIENT + self.client
|
||||
finally:
|
||||
self.finish()
|
||||
|
||||
def handle(self):
|
||||
# self.request is the TCP socket connected to the client
|
||||
self.data = self.request.recv(1024).strip()
|
||||
#self.GUI.displayMessage("".join(self.client_address[0]),self.data.decode('utf-8'))
|
||||
|
||||
errorCode, errorMessage = self.traitementResponse(self.data.decode('utf-8'),self.client_address[0])
|
||||
if self.messageType == LAN_CONSTANTS.MESSAGE_VALUE.TYPE_CONFIG.value:
|
||||
self.sendResponse(errorCode, errorMessage)
|
||||
elif self.messageType == LAN_CONSTANTS.MESSAGE_VALUE.TYPE_INFO.value:
|
||||
self.managmentInfo(self.data.decode('utf-8'),"".join(self.client_address[0]))
|
||||
elif self.messageType == LAN_CONSTANTS.MESSAGE_VALUE.TYPE_RESULT.value:
|
||||
if self.messageState == LAN_CONSTANTS.MESSAGE_VALUE.STATE_OK.value:
|
||||
#print(self.data.decode('utf-8'))
|
||||
global FOUND
|
||||
FOUND = True
|
||||
#self.finish()
|
||||
return
|
||||
|
||||
def setup(self):
|
||||
pass
|
||||
|
||||
def finish(self):
|
||||
pass
|
||||
|
||||
def managmentInfo(self,data,clientAdress):
|
||||
argvArray = data.split(LAN_CONSTANTS.MESSAGE_SPECIAL_CHAR.SEPARATOR.value)
|
||||
processName = list()
|
||||
WordsSeconds = list()
|
||||
curentWord = list()
|
||||
processTime = list()
|
||||
nbWord = list()
|
||||
for object in argvArray:
|
||||
key,value = BF_Utils.getValueWithKey(object)
|
||||
if LAN_CONSTANTS.MESSAGE_SPECIAL_CHAR.SAME_VALUE_SEPRATOR.value in value:
|
||||
|
||||
contentList = value.split(LAN_CONSTANTS.MESSAGE_SPECIAL_CHAR.SAME_VALUE_SEPRATOR.value)
|
||||
if key == LAN_CONSTANTS.MESSAGE_KEY.LOCAL_THREAD_NAME.value :
|
||||
for content in contentList:
|
||||
processName.append(content)
|
||||
elif key == LAN_CONSTANTS.MESSAGE_KEY.WORD.value:
|
||||
for content in contentList:
|
||||
curentWord.append(content)
|
||||
elif key == LAN_CONSTANTS.MESSAGE_KEY.PROCESS_TIME.value:
|
||||
for content in contentList:
|
||||
processTime.append(float(content))
|
||||
elif key == LAN_CONSTANTS.MESSAGE_KEY.NB_WORDS.value:
|
||||
for content in contentList:
|
||||
nbWord.append(int(content))
|
||||
|
||||
for i in range(0,len(nbWord)):
|
||||
WordsSeconds.append(round(nbWord[i]/processTime[i]))
|
||||
self.GUI.displayProcessPerfsList( clientAdress, processName, WordsSeconds, curentWord)
|
||||
"""else:
|
||||
if key == LAN_CONSTANTS.MESSAGE_KEY.LOCAL_THREAD_NAME.value :
|
||||
processName = value
|
||||
elif key == LAN_CONSTANTS.MESSAGE_KEY.WORD.value:
|
||||
curentWord = value
|
||||
elif key == LAN_CONSTANTS.MESSAGE_KEY.PROCESS_TIME.value:
|
||||
processTime = float(value)
|
||||
elif key == LAN_CONSTANTS.MESSAGE_KEY.NB_WORDS.value:
|
||||
nbWord = int(value)
|
||||
WordsSeconds = round(nbWord/processTime)
|
||||
self.GUI.displayProcessPerfs( clientAdress, processName, WordsSeconds, curentWord)"""
|
||||
|
||||
|
||||
def sendResponse(self, errorCode, errorMessage):
|
||||
message = list()
|
||||
for i in range(0,len(errorCode)):
|
||||
if not i == (len(errorCode) -1):
|
||||
message.append(errorCode[i]+':'+errorMessage[i]+',')
|
||||
else:
|
||||
message.append(errorCode[i]+':'+errorMessage[i])
|
||||
self.request.sendall(bytes("".join(message),'utf-8'))
|
||||
|
||||
|
||||
def traitementResponse(self,param,clientAdress):
|
||||
errorMessage = list()
|
||||
errorCode = list()
|
||||
argvArray = param.split(LAN_CONSTANTS.MESSAGE_SPECIAL_CHAR.SEPARATOR.value)
|
||||
for object in argvArray:
|
||||
key,value = BF_Utils.getValueWithKey(object)
|
||||
if key == LAN_CONSTANTS.MESSAGE_KEY.NB_CORE_CLIENT.value :
|
||||
code, message = self.coreProcessing(value,clientAdress)
|
||||
errorCode = errorCode + code
|
||||
errorMessage = errorMessage + message
|
||||
elif key == LAN_CONSTANTS.MESSAGE_KEY.MESSAGE_TYPE.value:
|
||||
self.messageType = value
|
||||
elif key == LAN_CONSTANTS.MESSAGE_KEY.RETURN_STATE.value:
|
||||
self.messageState = value
|
||||
elif key == LAN_CONSTANTS.MESSAGE_KEY.WORD.value:
|
||||
global PASSWORD_FOUND
|
||||
PASSWORD_FOUND = value
|
||||
else:
|
||||
errorCode.append(ANSWER_STATES.MESSAGE_STATE.STATE_KO.value)
|
||||
errorMessage.append('protocol key not recognize')
|
||||
return errorCode,errorMessage
|
||||
|
||||
def coreProcessing(self,value,clientAdress):
|
||||
global IP_CONNECTE
|
||||
|
||||
errorMessage = list()
|
||||
errorCode = list()
|
||||
if BF_Utils.is_int(value):
|
||||
if clientAdress not in IP_CONNECTE:
|
||||
coeurClient = int(value)
|
||||
if coeurClient > 0:
|
||||
if coeurClient <= NB_COEUR:
|
||||
self.coreClient = coeurClient
|
||||
IP_CONNECTE.append(clientAdress)
|
||||
self.client.append((clientAdress,coeurClient))
|
||||
errorMessage.append("core added")
|
||||
errorCode.append(ANSWER_STATES.MESSAGE_STATE.STATE_OK.value)
|
||||
else:
|
||||
errorCode.append(ANSWER_STATES.MESSAGE_STATE.STATE_KO.value)
|
||||
errorMessage.append("Please insert " + str(NB_COEUR - self.coreClient)+ " core max")
|
||||
else:
|
||||
errorCode.append(ANSWER_STATES.MESSAGE_STATE.STATE_KO.value)
|
||||
errorMessage.append("Please insert at least 1 core")
|
||||
else:
|
||||
errorCode.append(ANSWER_STATES.MESSAGE_STATE.STATE_KO.value)
|
||||
errorMessage.append("client already conected")
|
||||
else:
|
||||
errorCode.append(ANSWER_STATES.MESSAGE_STATE.STATE_KO.value)
|
||||
errorMessage.append("Value is not integer")
|
||||
|
||||
return errorCode,errorMessage
|
||||
|
||||
|
||||
class MultyStationServer():
|
||||
def __init__(self,host,port,nbCoeur,password,key,passwordLength,hashMethod):
|
||||
global NB_COEUR
|
||||
self.nbCoeur=nbCoeur
|
||||
NB_COEUR = nbCoeur
|
||||
self.serverTime = time.time()
|
||||
self.host = host
|
||||
self.port = port
|
||||
self.coreConnected = 0
|
||||
self.password = password
|
||||
self.passwordLength = passwordLength
|
||||
self.hashMethod=hashMethod
|
||||
self.key = key
|
||||
self.GUI = GUI()
|
||||
signal.signal(signal.SIGINT, self.signal_handler)
|
||||
return
|
||||
|
||||
|
||||
def signal_handler(self, signal, frame):
|
||||
self.serverHandler.shutdown()
|
||||
sys.exit(0)
|
||||
|
||||
def connect(self):
|
||||
self.serverHandler = socketserver.TCPServer((self.host, self.port ), MultyStationServerHandler)
|
||||
return
|
||||
|
||||
|
||||
def run(self):
|
||||
global IP_CONNECTE
|
||||
global FOUND
|
||||
if NB_COEUR < 1:
|
||||
self.GUI.displayError("127.0.0.1","INIT","too low processor core")
|
||||
sys.exit()
|
||||
while COEUR_CONNECTE < NB_COEUR:
|
||||
self.serverHandler.handle_request()
|
||||
|
||||
self.GUI.displayMessage(IP_CONNECTE[len(IP_CONNECTE) -1],str(COEUR_CONNECTE) +"/" +str(NB_COEUR))
|
||||
time.sleep(0.1)
|
||||
|
||||
indexCore = 0
|
||||
for pc in CLIENT:
|
||||
#print("ip : " + pc[0] + "\t Nombre de core offert : " + str(pc[1]))
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
sock.connect((pc[0],self.port+1))
|
||||
msg = BF_Utils.createMessage(LAN_CONSTANTS.MESSAGE_KEY.MESSAGE_TYPE.value,LAN_CONSTANTS.MESSAGE_VALUE.TYPE_CONFIG.value,True)
|
||||
msg = msg + BF_Utils.createMessage(LAN_CONSTANTS.MESSAGE_KEY.NB_CORE_TOTAL.value, str(self.nbCoeur),True)
|
||||
msg = msg + BF_Utils.createMessage(LAN_CONSTANTS.MESSAGE_KEY.INDEX_CORE_MIN.value, str(indexCore),True)
|
||||
msg = msg + BF_Utils.createMessage(LAN_CONSTANTS.MESSAGE_KEY.CRYPTED_PASSWORD.value, str(self.password),True)
|
||||
msg = msg + BF_Utils.createMessage(LAN_CONSTANTS.MESSAGE_KEY.ENCRYPTION_KEY.value, str(self.key),True)
|
||||
msg = msg + BF_Utils.createMessage(LAN_CONSTANTS.MESSAGE_KEY.HASH_METHOD.value, str(self.hashMethod),True)
|
||||
msg = msg + BF_Utils.createMessage(LAN_CONSTANTS.MESSAGE_KEY.PASSWORD_MAX_LENGTH.value, str(self.passwordLength),False)
|
||||
#self.GUI.displayMessage("127.0.0.1","Message envoyé : "+msg)
|
||||
sock.send(bytes(msg,"UTF-8"))
|
||||
indexCore = indexCore +pc[1]
|
||||
sock.recv(min(2048, 2048))
|
||||
sock.close()
|
||||
|
||||
self.serverTime = time.time()
|
||||
self.GUI.displayMessage("SERVER","Start ! ")
|
||||
global FOUND
|
||||
while not FOUND:
|
||||
self.serverHandler.handle_request()
|
||||
|
||||
self.GUI.displayMessage("SERVER","Found ! ")
|
||||
self.GUI.displayResult(PASSWORD_FOUND,self.serverTime )
|
||||
|
||||
for pc in CLIENT:
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
sock.connect((pc[0],self.port+1))
|
||||
msg = BF_Utils.createMessage(LAN_CONSTANTS.MESSAGE_KEY.MESSAGE_TYPE.value,LAN_CONSTANTS.MESSAGE_VALUE.TYPE_RESULT.value,True)
|
||||
msg = msg + BF_Utils.createMessage(LAN_CONSTANTS.MESSAGE_KEY.RETURN_STATE.value,LAN_CONSTANTS.MESSAGE_VALUE.STATE_OK.value,True)
|
||||
msg = msg + BF_Utils.createMessage(LAN_CONSTANTS.MESSAGE_KEY.WORD.value,PASSWORD_FOUND,False)
|
||||
sock.send(bytes(msg,"utf-8"))
|
||||
sock.recv(min(2048, 2048))
|
||||
sock.close()
|
||||
|
||||
for pc in range(0,len(CLIENT)-1):
|
||||
self.serverHandler.handle_request()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
HOST = ''
|
||||
PORT = 2323
|
||||
nbCoeur = 8
|
||||
server = MultyStationServer(HOST,PORT,nbCoeur,"azert","",6)
|
||||
server.connect()
|
||||
server.run()
|
||||
sys.exit()
|
||||
|
@ -0,0 +1,109 @@
|
||||
#!/usr/bin/python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import multiprocessing
|
||||
import sys
|
||||
import time
|
||||
import os
|
||||
|
||||
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()
|
@ -0,0 +1,46 @@
|
||||
#!/usr/bin/python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from BF_Constants import *
|
||||
|
||||
def is_int(stringInteger):
|
||||
try:
|
||||
int(stringInteger)
|
||||
return True
|
||||
except ValueError:
|
||||
return False
|
||||
|
||||
def is_float(stringFloat):
|
||||
try:
|
||||
float(stringFloat)
|
||||
return True
|
||||
except ValueError:
|
||||
return False
|
||||
|
||||
def getValueWithKey(value):
|
||||
value = str(value)
|
||||
argvArray = value.split(LAN_CONSTANTS.MESSAGE_SPECIAL_CHAR.SEPARATOR.value)
|
||||
for argv in argvArray:
|
||||
key = argv.split(LAN_CONSTANTS.MESSAGE_SPECIAL_CHAR.ASIGNATOR.value)
|
||||
key = key[0]
|
||||
value = argv.split(LAN_CONSTANTS.MESSAGE_SPECIAL_CHAR.ASIGNATOR.value)
|
||||
value = value[1]
|
||||
return key, value
|
||||
|
||||
def createMessage(key,value,isNotLast):
|
||||
value = str(value)
|
||||
message = key + LAN_CONSTANTS.MESSAGE_SPECIAL_CHAR.ASIGNATOR.value + value
|
||||
if isNotLast:
|
||||
message = message + LAN_CONSTANTS.MESSAGE_SPECIAL_CHAR.SEPARATOR.value
|
||||
return message
|
||||
|
||||
def createMessageList(key,content,isNotLast):
|
||||
message = key + LAN_CONSTANTS.MESSAGE_SPECIAL_CHAR.ASIGNATOR.value
|
||||
for i in range(0,len(content)):
|
||||
message = message + str(content[i])
|
||||
if i < len(content) -1:
|
||||
message = message + LAN_CONSTANTS.MESSAGE_SPECIAL_CHAR.SAME_VALUE_SEPRATOR.value
|
||||
if isNotLast:
|
||||
message = message + LAN_CONSTANTS.MESSAGE_SPECIAL_CHAR.SEPARATOR.value
|
||||
return message
|
||||
|
@ -1,88 +0,0 @@
|
||||
#!/usr/bin/python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import multiprocessing
|
||||
import sys
|
||||
import time
|
||||
import locale
|
||||
from ProcessBruteForce import *
|
||||
|
||||
nbProcess = 4
|
||||
verbose = False
|
||||
|
||||
class App():
|
||||
def __init__(self):
|
||||
|
||||
## La liste contenant nos object Processe
|
||||
self.processes = list()
|
||||
self.queue = multiprocessing.Queue()
|
||||
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 , "azerty","",6,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)
|
||||
h, m = divmod(m, 60)
|
||||
d ,h = divmod(h, 24)
|
||||
if d != 0:
|
||||
print("Found ! : " + passTrouve +" en " + "%d:%02d:%02d:%02d" % (d,h, m, s))
|
||||
elif h != 0 :
|
||||
print("Found ! : " + passTrouve +" en " + "%d:%02d:%02d" % (h, m, s))
|
||||
else:
|
||||
print("Found ! : " + passTrouve +" en " + "%d:%02d" % (m, s))
|
||||
else:
|
||||
print("Found ! : " + passTrouve +" en " + str(time.time() - self.appTime) + " secondes")
|
||||
|
||||
#si le fichier est lancé seul
|
||||
if __name__ == '__main__' :
|
||||
application = App()
|
||||
application.run()
|
||||
sys.exit()
|
@ -1,96 +0,0 @@
|
||||
#!/usr/bin/python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import multiprocessing
|
||||
import sys
|
||||
import time
|
||||
|
||||
tabChar = list("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ")
|
||||
|
||||
class ProcessBrurteForce(multiprocessing.Process):
|
||||
def __init__(self,queue, idx, nbInstence,password, clef, limite, verbose):
|
||||
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.password = password
|
||||
self.clef = clef
|
||||
self.limite = limite
|
||||
self.tabPass = list("a")
|
||||
self.isFound = False
|
||||
return
|
||||
|
||||
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.tabPass),multiprocessing.current_process().name])
|
||||
self.nbMot = 0
|
||||
self.procTime = time.time()
|
||||
|
||||
def run(self):
|
||||
#print(multiprocessing.current_process().name + "\tStart")
|
||||
found , passTrouve = self.checkChar(0)
|
||||
if not found:
|
||||
|
||||
while not found and len(self.tabPass) < self.limite:
|
||||
indexMin = round((len(tabChar)/self.nbInstence)*self.idx)
|
||||
indexMax = round(indexMin + (len(tabChar)/self.nbInstence))
|
||||
self.tabPass = self.tabPass + list(tabChar[indexMin])
|
||||
if( self.idx == self.nbInstence - 1 ):
|
||||
indexMax = len(tabChar)
|
||||
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
|
||||
|
||||
print(multiprocessing.current_process().name + "\tStop")
|
||||
#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
|
||||
|
||||
def recursiveFunction(self,index):
|
||||
found , passTrouve = self.checkChar(index)
|
||||
if index > 0 and not found:
|
||||
for char in tabChar :
|
||||
self.tabPass[index] = char
|
||||
found, passTrouve =self.recursiveFunction(index-1)
|
||||
if found == True :
|
||||
passTrouve = "".join(self.tabPass)
|
||||
return found, passTrouve
|
||||
|
||||
return found, passTrouve
|
||||
|
||||
#Cette fonction permet de replacer le dernier caractère de la Chaine
|
||||
def checkChar(self,index):
|
||||
found = False
|
||||
passTrouve = ""
|
||||
for char in tabChar:
|
||||
if self.verbose:
|
||||
self.testSpeed()
|
||||
self.tabPass[index] = char
|
||||
if "".join(self.tabPass) == self.password:
|
||||
found=True
|
||||
passTrouve = "".join(self.tabPass)
|
||||
return found, passTrouve
|
||||
#print("".join(self.tabPass))
|
||||
return found, passTrouve
|
||||
|
||||
|
||||
#si le fichier est lancé seul
|
||||
if __name__ == '__main__' :
|
||||
sys.exit()
|
@ -0,0 +1,39 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import hashlib
|
||||
import random
|
||||
import sys
|
||||
|
||||
tabChar = list("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
|
||||
|
||||
class CryptPass():
|
||||
def __init__(self):
|
||||
self.passwordNonCrypte = ""
|
||||
self.key = ""
|
||||
self.typeCryptage = ""
|
||||
self.passwordCrypte = ""
|
||||
return None
|
||||
|
||||
def getHash(self, passwordNonCrypteWithKey, typeCryptage):
|
||||
self.passwordCrypte = ""
|
||||
passwordNonCrypteWithKey = passwordNonCrypteWithKey.encode()
|
||||
if typeCryptage == "md5":
|
||||
passwordCrypte = hashlib.md5(passwordNonCrypteWithKey).hexdigest()
|
||||
elif typeCryptage == "sha1":
|
||||
passwordCrypte = hashlib.sha1(passwordNonCrypteWithKey).hexdigest()
|
||||
elif typeCryptage == "sha224":
|
||||
passwordCrypte = hashlib.sha224(passwordNonCrypteWithKey).hexdigest()
|
||||
elif typeCryptage == "sha256":
|
||||
passwordCrypte = hashlib.sha256(passwordNonCrypteWithKey).hexdigest()
|
||||
elif typeCryptage == "sha384":
|
||||
passwordCrypte = hashlib.sha384(passwordNonCrypteWithKey).hexdigest()
|
||||
elif typeCryptage == "sha512":
|
||||
passwordCrypte = hashlib.sha512(passwordNonCrypteWithKey).hexdigest()
|
||||
self.passwordCrypte = passwordCrypte
|
||||
return self.passwordCrypte
|
||||
|
||||
|
||||
#si le fichier est lancé seul
|
||||
if __name__ == '__main__' :
|
||||
app = CryptPass()
|
||||
print(app.getHash(sys.argv[1],"md5"))
|
||||
sys.exit()
|
Loading…
Reference in new issue