From 6dedc9832ef58b2e09a7ed496b7576209c1244f7 Mon Sep 17 00:00:00 2001 From: AbidiWael Date: Mon, 13 Jan 2025 11:18:14 +0100 Subject: [PATCH] feat: implement /bruteforce endpoint with standard API response --- backend/app.py | 45 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/backend/app.py b/backend/app.py index a266c8c..f3cd5a6 100644 --- a/backend/app.py +++ b/backend/app.py @@ -1,10 +1,47 @@ -from flask import Flask, jsonify +from flask import Flask, request, jsonify +import hashlib +import itertools app = Flask(__name__) -@app.route("/", methods=["GET"]) -def index(): - return jsonify({"message": "Hello, Flask!"}) +@app.route("/bruteforce", methods=["POST"]) +def bruteforce(): + # Vérifier si le payload contient un hash + data = request.json + if not data or "hash" not in data: + return jsonify({ + "status": "fail", + "data": None, + "errors": { + "message": "Invalid payload. Please provide a valid hash." + } + }), 400 + + target_hash = data["hash"] + + # Logique de bruteforce + charset = "abcdefghijklmnopqrstuvwxyz0123456789" + for length in range(1, 8): # Limite la longueur des combinaisons pour les performances + for guess in itertools.product(charset, repeat=length): + guess_str = ''.join(guess) + if hashlib.md5(guess_str.encode()).hexdigest() == target_hash: + return jsonify({ + "status": "success", + "data": { + "hash": target_hash, + "original": guess_str + }, + "errors": None + }), 200 + + # Si aucune correspondance n'est trouvée + return jsonify({ + "status": "fail", + "data": None, + "errors": { + "message": "No match found for the provided hash." + } + }), 404 if __name__ == "__main__": app.run(host="0.0.0.0", port=5000) -- GitLab