[Python] Script to Use Virustotal to Convert SHA256 to MD5

Discussão em 'Python' iniciado por Stack, Junho 20, 2025.

  1. Stack

    Stack Membro Participativo

    I sometimes get a huge list of SHA256 hashes that I need the MD5 version of. VirustTotal contains this information but doing 200+ manually is not really feasible. I have a script cobbled together from internet sleuthing that feels like it should work, but I only get back an empty file. The goal is to take an input file that is only a list of SHA256 hashes, and output a text file that is only a list of the corresponding MD5 hashes. What am I missing?

    import requests
    import sys
    import time
    import json

    url = 'https://www.virustotal.com/api/v3/files/{}'
    headers = {"accept": "application/json",
    "x-apikey": "<key>"}

    inf = input("What hash file?")

    with open(inf, "r") as f:
    with open("hashout.txt", "w") as output:
    for line in f:
    HASH = str(line).strip()
    url = url.format("HASH")
    response = requests.get(url, headers=headers)
    data = response.json()
    md5 = data["md5"]
    output.write(md5)
    time.sleep(16) # VirusTotal Public API allows only 4 requests per minute, sleep to avoid hitting this
    print("File Complete")

    Continue reading...

Compartilhe esta Página