Exemple #1
0
def analyze_binary_thr(binary_id):
    db = DB()
    binary = db.get_binary_by_id(binary_id)
    models = db.get_available_models()
    job = db.add(Job("Analyzing binary " + binary.name))

    bin_path = os.path.join(FILE_UPLOAD_FOLDER, binary.filename + ".bin")
    diss_path = os.path.join(DISS_BINARY_FOLDER, binary.filename + ".json")

    hash = get_file_sha_hash(bin_path)
    db.binary_add_hash(binary.id, hash)

    Disassembler(bin_path).disassemble_to_file(diss_path)

    for i, m in enumerate(models):
        db.job_add_log(
            job.id,
            "Testing against model {}, {}/{}".format(m.name, len(models),
                                                     i + 1))
        model_path = os.path.join(MODEL_FOLDER, m.filename)
        map_path = os.path.join(model_path, "map.json")
        model_file_path = os.path.join(model_path, "model.npz")
        rating = ModelComparator(diss_path, map_path,
                                 model_file_path).get_rating()

        db.add(Result(binary.id, m.id, rating))

    db.job_add_log(job.id, "Cleaning up the file mess")
    db.set_binary_analyzed(binary.id)
    os.system("rm {}".format(bin_path))
    db.set_job_ended(job.id)
Exemple #2
0
def get_binary(binary_id):
    try:
        db = DB()
        binary = db.get_binary_by_id(binary_id)
        if binary:
            return jsonify({"binary": binary.serialize()}), 200
        else:
            return jsonify({"error": "binary not found"}), 400
    except Exception as e:
        print(e)
        abort(500)
def get_results(binary_id):
    db = DB()
    res = []
    binary = db.get_binary_by_id(binary_id)
    results = db.get_results_by_binary_id(binary.id)

    if len(results) != 0:
        results = parse_results(results)
        for r in results:
            m = db.get_model_by_id(r.model)
            res.append({"model": m.name, "score": str(int(r.score))})

    return res
Exemple #4
0
def upload_binary_file(binary_id):
    try:
        db = DB()
        binary = db.get_binary_by_id(binary_id)
        if not binary:
            return jsonify({"error": "Binary not found"}), 400
        file = request.files['file']
        if file and file.filename:
            file.save(
                os.path.join(FILE_UPLOAD_FOLDER, binary.filename + ".bin"))
            hm.analyze_binary(binary.id)
        return jsonify({}), 200
    except Exception as e:
        print(e)
        abort(500)
Exemple #5
0
def get_results(binary_id):
    try:
        db = DB()
        rt = []
        binary = db.get_binary_by_id(binary_id)
        results = db.get_results_by_binary_id(binary.id)

        if len(results) != 0:
            results = parse_results(results)
            for r in results:
                m = db.get_model_by_id(r.model)
                rt.append({"model": m.name, "score": str(int(r.score))})

        return jsonify({"results": rt, "analyzed": binary.analyzed}), 200
    except Exception as e:
        print(e)
        abort(500)