UE2.24 TP1
This commit is contained in:
@@ -11,6 +11,4 @@ Mr Kalonji Jean.Claude - jean-claude.kalonji@seineetmarne.cci.fr</pre>
|
|||||||
|
|
||||||
> Etude de marché, offre et demande
|
> Etude de marché, offre et demande
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## 24 06 2026
|
## 24 06 2026
|
||||||
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
@@ -0,0 +1,4 @@
|
|||||||
|
import xmlrpc.client
|
||||||
|
proxy = xmlrpc.client.ServerProxy("http://192.168.1.210:9000/")
|
||||||
|
num = int(input("Entrez un nombre : "))
|
||||||
|
print("Résultat : ", proxy.square(num))
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
from xmlrpc.server import SimpleXMLRPCServer
|
||||||
|
def square(x):
|
||||||
|
return x * x
|
||||||
|
server = SimpleXMLRPCServer(("0.0.0.0", 9000))
|
||||||
|
print("Server listening on port 9000...")
|
||||||
|
server.register_function(square, "square")
|
||||||
|
server.serve_forever()
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
from xmlrpc.server import SimpleXMLRPCServer
|
||||||
|
import itertools
|
||||||
|
import string
|
||||||
|
|
||||||
|
class HashCrackerServer:
|
||||||
|
def __init__(self, target_hash, algo):
|
||||||
|
self.target_hash = target_hash
|
||||||
|
self.algo = algo
|
||||||
|
self.workers = []
|
||||||
|
self.password_found = False
|
||||||
|
|
||||||
|
print("Génération de l'espace de recherche (1 à 4 lettres)...")
|
||||||
|
self.blocks = self._generate_blocks()
|
||||||
|
print(f"Espace divisé en {len(self.blocks)} blocs de travail.")
|
||||||
|
|
||||||
|
def _generate_blocks(self, block_size=5000):
|
||||||
|
chars = string.ascii_lowercase
|
||||||
|
all_combinations = []
|
||||||
|
# Génère les mots de 1 à 4 lettres
|
||||||
|
for length in range(1, 5):
|
||||||
|
for p in itertools.product(chars, repeat=length):
|
||||||
|
all_combinations.append("".join(p))
|
||||||
|
|
||||||
|
# Découpage de la liste globale en sous-listes (blocs)
|
||||||
|
return [all_combinations[i:i + block_size] for i in range(0, len(all_combinations), block_size)]
|
||||||
|
|
||||||
|
def register_worker(self, worker_name):
|
||||||
|
if worker_name not in self.workers:
|
||||||
|
self.workers.append(worker_name)
|
||||||
|
print(f"[INFO] Nouveau Worker enregistré : {worker_name}")
|
||||||
|
return True
|
||||||
|
|
||||||
|
def get_work_block(self):
|
||||||
|
if self.password_found:
|
||||||
|
return {"status": "STOP"} # Quelqu'un a déjà trouvé
|
||||||
|
if not self.blocks:
|
||||||
|
return {"status": "DONE"} # Plus de travail disponible
|
||||||
|
|
||||||
|
# On retire le premier bloc de la liste et on l'envoie
|
||||||
|
return {
|
||||||
|
"status": "WORK",
|
||||||
|
"algo": self.algo,
|
||||||
|
"target": self.target_hash,
|
||||||
|
"words": self.blocks.pop(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
def submit_result(self, worker_name, password):
|
||||||
|
if password:
|
||||||
|
self.password_found = True
|
||||||
|
print(f"\n[SUCCÈS] Le worker '{worker_name}' a cracké le hash ! Mot de passe : {password}")
|
||||||
|
return True
|
||||||
|
|
||||||
|
# Hash MD5 pour le mot "toto"
|
||||||
|
TARGET_HASH = "f71dbe52628a3f83a77ab494817525c6"
|
||||||
|
ALGO = "md5"
|
||||||
|
|
||||||
|
server = SimpleXMLRPCServer(("0.0.0.0", 9000), allow_none=True)
|
||||||
|
cracker_instance = HashCrackerServer(TARGET_HASH, ALGO)
|
||||||
|
|
||||||
|
# Enregistrement de l'instance entière (expose toutes ses méthodes publiques)
|
||||||
|
server.register_instance(cracker_instance)
|
||||||
|
|
||||||
|
print("Serveur Maître RPC en écoute sur le port 9000...")
|
||||||
|
server.serve_forever()
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
import xmlrpc.client
|
||||||
|
import hashlib
|
||||||
|
import sys
|
||||||
|
|
||||||
|
# Pense à remplacer par l'IP de ta VM1
|
||||||
|
PROXY_URL = "http://192.168.1.210:9000/"
|
||||||
|
WORKER_NAME = "UE2-24-worker1"
|
||||||
|
#WORKER_NAME = "UE2-24-worker2"
|
||||||
|
|
||||||
|
try:
|
||||||
|
proxy = xmlrpc.client.ServerProxy(PROXY_URL, allow_none=True)
|
||||||
|
proxy.register_worker(WORKER_NAME)
|
||||||
|
print(f"Connecté au serveur en tant que {WORKER_NAME}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Impossible de se connecter au serveur : {e}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
job = proxy.get_work_block()
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Erreur de communication avec le serveur : {e}")
|
||||||
|
break
|
||||||
|
|
||||||
|
if job["status"] == "STOP":
|
||||||
|
print("Un autre worker a trouvé le mot de passe. Fin du programme.")
|
||||||
|
break
|
||||||
|
elif job["status"] == "DONE":
|
||||||
|
print("L'espace de recherche est épuisé. Le mot de passe n'a pas été trouvé.")
|
||||||
|
break
|
||||||
|
|
||||||
|
words = job["words"]
|
||||||
|
target = job["target"]
|
||||||
|
algo = job["algo"]
|
||||||
|
|
||||||
|
print(f"Réception d'un bloc de {len(words)} mots à tester...")
|
||||||
|
found_password = None
|
||||||
|
|
||||||
|
# Boucle de force brute sur le bloc
|
||||||
|
for word in words:
|
||||||
|
h = hashlib.new(algo)
|
||||||
|
h.update(word.encode('utf-8'))
|
||||||
|
|
||||||
|
if h.hexdigest() == target:
|
||||||
|
found_password = word
|
||||||
|
break
|
||||||
|
|
||||||
|
# Soumission du résultat (mot de passe ou None si échec sur ce bloc)
|
||||||
|
if found_password:
|
||||||
|
proxy.submit_result(WORKER_NAME, found_password)
|
||||||
|
print(f">>> MOT DE PASSE TROUVÉ : {found_password} <<<")
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
proxy.submit_result(WORKER_NAME, None)
|
||||||
Reference in New Issue
Block a user