Malware Analysis with VirusTotal
Script con colores:
pip install colorama
import requests
import argparse
import sys
from colorama import init, Fore
init(autoreset=True)
API_KEY = 'TU_API_KEY_AQUI' # Sustituye con tu clave API de VirusTotal
API_URL = 'https://www.virustotal.com/api/v3/files/'
def verificar_hash(archivo_hash):
headers = {
"x-apikey": API_KEY
}
url = API_URL + archivo_hash
response = requests.get(url, headers=headers)
if response.status_code == 200:
data = response.json()
stats = data["data"]["attributes"]["last_analysis_stats"]
detections = data["data"]["attributes"]["last_analysis_results"]
print(f"\n🔍 Hash: {archivo_hash}")
print(f"{Fore.GREEN} ✔️ Detecciones - Malicioso: {stats['malicious']}, Sospechoso: {stats['suspicious']}, Limpio: {stats['undetected']}")
# Mostrar motores que detectaron como malicioso
print(Fore.CYAN + "\n🧪 Motores que detectaron como MALICIOSO:")
mal_found = False
for engine, result in detections.items():
if result["category"] == "malicious":
print(f"{Fore.RED} - {engine}: {result['result']}")
mal_found = True
if not mal_found:
print(Fore.GREEN + " - Ninguno.")
# Mostrar motores que lo marcaron como sospechoso
print(Fore.CYAN + "\n⚠️ Motores que detectaron como SOSPECHOSO:")
susp_found = False
for engine, result in detections.items():
if result["category"] == "suspicious":
print(f"{Fore.YELLOW} - {engine}: {result['result']}")
susp_found = True
if not susp_found:
print(Fore.GREEN + " - Ninguno.")
elif response.status_code == 404:
print(f"\n{Fore.RED} ❌ Hash no encontrado en VirusTotal: {archivo_hash}")
else:
print(f"\n{Fore.YELLOW}⚠️ Error al consultar {archivo_hash} - Código: {response.status_code}")
def main():
parser = argparse.ArgumentParser(description="Consulta la reputación de hashes en VirusTotal")
parser.add_argument("hashes", metavar="HASH", nargs="+", help="Hash(es) a consultar (MD5, SHA-1 o SHA-256)")
args = parser.parse_args()
for h in args.hashes:
if len(h) not in [32, 40, 64]:
print(f"{Fore.RED}❗ Hash inválido (no tiene longitud típica de MD5, SHA-1 o SHA-256): {h}")
continue
verificar_hash(h)
if __name__ == "__main__":
if API_KEY == 'TU_API_KEY_AQUI':
print(Fore.YELLOW + "⚠️ Debes introducir tu clave API de VirusTotal en el script antes de ejecutarlo.")
sys.exit(1)
main()
Script sin colores:
import requests
import argparse
import sys
API_KEY = 'TU_API_KEY_AQUI' # Sustituye con tu clave API de VirusTotal
API_URL = 'https://www.virustotal.com/api/v3/files/'
def verificar_hash(archivo_hash):
headers = {
"x-apikey": API_KEY
}
url = API_URL + archivo_hash
response = requests.get(url, headers=headers)
if response.status_code == 200:
data = response.json()
stats = data["data"]["attributes"]["last_analysis_stats"]
detections = data["data"]["attributes"]["last_analysis_results"]
print(f"\n🔍 Hash: {archivo_hash}")
print(f"✔️ Detecciones - Malicioso: {stats['malicious']}, Sospechoso: {stats['suspicious']}, Limpio: {stats['undetected']}")
# Mostrar motores que detectaron como malicioso
print("\n🧪 Motores que detectaron como MALICIOSO:")
mal_found = False
for engine, result in detections.items():
if result["category"] == "malicious":
print(f"- {engine}: {result['result']}")
mal_found = True
if not mal_found:
print(" - Ninguno.")
# Mostrar motores que lo marcaron como sospechoso
print("\n⚠️ Motores que detectaron como SOSPECHOSO:")
susp_found = False
for engine, result in detections.items():
if result["category"] == "suspicious":
print(f"- {engine}: {result['result']}")
susp_found = True
if not susp_found:
print(" - Ninguno.")
elif response.status_code == 404:
print(f"\n❌ Hash no encontrado en VirusTotal: {archivo_hash}")
else:
print(f"\n⚠️ Error al consultar {archivo_hash} - Código: {response.status_code}")
def main():
parser = argparse.ArgumentParser(description="Consulta la reputación de hashes en VirusTotal")
parser.add_argument("hashes", metavar="HASH", nargs="+", help="Hash(es) a consultar (MD5, SHA-1 o SHA-256)")
args = parser.parse_args()
for h in args.hashes:
if len(h) not in [32, 40, 64]:
print(f"❗ Hash inválido (no tiene longitud típica de MD5, SHA-1 o SHA-256): {h}")
continue
verificar_hash(h)
if __name__ == "__main__":
if API_KEY == 'TU_API_KEY_AQUI':
print("⚠️ Debes introducir tu clave API de VirusTotal en el script antes de ejecutarlo.")
sys.exit(1)
main()
Uso:
python3 hash.py <hash>
Last updated