app.py 1,4 ko
Newer Older
from flask import Flask, request, jsonify
import hashlib
import itertools

app = Flask(__name__)

@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)