File size: 1,677 Bytes
497f2f3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import os
import json

def compile_exploits_to_json(input_dir, output_file):
    compiled_data = []

    # Iterar por todos os arquivos na pasta de exploits
    for filename in os.listdir(input_dir):
        if filename.startswith("exploit_") and filename.endswith(".txt"):
            file_path = os.path.join(input_dir, filename)
            try:
                with open(file_path, 'r', encoding='utf-8') as f:
                    content = f.read()
                # Extrair o ID do exploit do nome do arquivo
                exploit_id = filename.split('_')[1].split('.')[0]
                # Adicionar dados ao JSON
                compiled_data.append({
                    "exploit_id": int(exploit_id),
                    "content": content,
                    "vulnerable": True  # Marcar como código vulnerável
                })
            except Exception as e:
                print(f"[ERROR] Failed to process file {filename}: {e}")

    # Salvar os dados compilados no arquivo JSON
    try:
        with open(output_file, 'w', encoding='utf-8') as json_file:
            json.dump(compiled_data, json_file, indent=4)
        print(f"[SUCCESS] Exploits compiled into {output_file}")
    except Exception as e:
        print(f"[ERROR] Failed to write JSON file: {e}")

if __name__ == "__main__":
    input_directory = "exploit-analyzer/exploits"  # Pasta onde os exploits estão armazenados
    output_json_file = "exploit-analyzer/compiled_exploits.json"  # Caminho do arquivo de saída

    os.makedirs(os.path.dirname(output_json_file), exist_ok=True)
    compile_exploits_to_json(input_directory, output_json_file)