Download scripts/compile_exploits_to_json.py from lilbool/vuln-code-analysis: direct link, hf CLI and curl.
- Browser
- Download file 1.68 kB
-
https://huggingface.co/lilbool/vuln-code-analysis/resolve/main/scripts/compile_exploits_to_json.py
- Command line
-
hf download hf://lilbool/vuln-code-analysis/scripts/compile_exploits_to_json.py
-
curl -L -o compile_exploits_to_json.py https://huggingface.co/lilbool/vuln-code-analysis/resolve/main/scripts/compile_exploits_to_json.py
1.68 kB
| 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) | |