-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
96 lines (82 loc) · 3.34 KB
/
main.py
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import os
import json
from modules.hash_utils import calculate_hashes
from modules.strings_utils import extract_strings
from modules.yara_utils import compile_yara_rules
from modules.virustotal_utils import scan_file_with_virustotal
from modules.extract_iocs import extract_iocs
from modules.entropy_utils import calculate_entropy
from modules.metadata_utils import analyze_metadata
from modules.pe_utils import analyze_pe_imports
def save_report(file_path, data):
report_dir = "reports"
os.makedirs(report_dir, exist_ok=True)
# Preguntar si quiere personalizar el nombre del reporte
custom_name = input("\n¿Quieres personalizar el nombre del archivo de reporte? (s/n): ").strip().lower()
if custom_name == 's':
file_name = input("📝 Ingresa el nombre para el archivo de reporte (sin extensión): ").strip()
report_file = os.path.join(report_dir, f"{file_name}.json")
else:
base_name = os.path.basename(file_path)
report_file = os.path.join(report_dir, f"{base_name}_report.json")
with open(report_file, "w") as f:
json.dump(data, f, indent=4)
print(f"\n✅ Reporte guardado en: {report_file}")
def analyze_all(file_path):
report = {}
report['hashes'] = calculate_hashes(file_path)
report['strings'] = extract_strings(file_path)
report['yara'] = compile_yara_rules(file_path)
report['virustotal'] = scan_file_with_virustotal(file_path)
report['iocs'] = extract_iocs(file_path)
report['entropy'] = calculate_entropy(file_path)
report['metadata'] = analyze_metadata(file_path)
report['pefile'] = analyze_pe_imports(file_path)
save_report(file_path, report)
def main():
print("=== Malware Analyzer ===")
file_path = input("📂 Ingresa la ruta del archivo a analizar: ")
if not os.path.isfile(file_path):
print("❌ Archivo no encontrado. Verifica la ruta.")
return
while True:
print("\nOpciones:")
print("[1] Calcular hashes")
print("[2] Extraer strings")
print("[3] Analizar con YARA")
print("[4] Escanear con VirusTotal")
print("[5] Extraer IOCs")
print("[6] Analizar entropía")
print("[7] Extraer metadatos")
print("[8] Analizar archivo PE")
print("[9] Ejecutar todas las técnicas")
print("[0] Salir")
choice = input("Selecciona una opción: ")
if choice == "1":
report = calculate_hashes(file_path)
elif choice == "2":
report = extract_strings(file_path)
elif choice == "3":
report = compile_yara_rules(file_path)
elif choice == "4":
report = scan_file_with_virustotal(file_path)
elif choice == "5":
report = extract_iocs(file_path)
elif choice == "6":
report = calculate_entropy(file_path)
elif choice == "7":
report = analyze_metadata(file_path)
elif choice == "8":
report = analyze_pe_imports(file_path)
elif choice == "9":
analyze_all(file_path)
continue # Ya guarda el reporte dentro de la función
elif choice == "0":
print("👋 Saliendo...")
break
else:
print("⚠️ Opción no válida. Intenta de nuevo.")
continue
save_report(file_path, report)
if __name__ == "__main__":
main()