Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions vtdownloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@
# Retrieve only the SHA-256 of the matching files
def get_results(search, numfiles):

table = []

url = 'https://www.virustotal.com/api/v3/intelligence/search?'
headers = {'X-apikey':VT_API_KEY}
params = urllib.parse.urlencode({'query':search, 'limit':numfiles, 'descriptors_only':'true'})
Expand Down Expand Up @@ -160,15 +158,14 @@ def get_metadata(file_id):

# Retrieve desired fields
metadata.append(responseJSON['data']['attributes']['sha256'])
metadata.append(responseJSON['data']['attributes']['meaningful_name'])
metadata.append(str(responseJSON['data']['attributes']['size']) + ' bytes')
metadata.append(datetime.utcfromtimestamp(responseJSON['data']['attributes']['last_submission_date']).strftime('%Y-%m-%dT%H:%M:%SZ'))

return metadata

# Wrapper for tabulate
def print_downloads(table):
headers = ["SHA-256", "Filename", "Size", "Latest Submission"]
headers = ["SHA-256", "Size", "Latest Submission"]
print('\nFiles downloaded:\n')
print(tabulate(table, headers, showindex=True, tablefmt="grid"))
return
Expand All @@ -194,13 +191,17 @@ def main():

requests.packages.urllib3.disable_warnings()

table = []

if hashfile:
if os.path.exists(hashfile):
with open(hashfile, 'rt') as inputfile:
logging.info('[*] Now reading hashes to download from file.')
hashes = re.findall('([0-9a-fA-F]{64}|[0-9a-fA-F]{40}|[0-9a-fA-F]{32})', inputfile.read())
hash_list = list(hashes)
download_files(hash_list)
# Create a table with metadata for the hashes
table = [get_metadata(h) for h in hash_list]
download_files(hash_list, table) # Pass the table here
else:
logging.info("[-] Error: {} not found".format(hashfile))

Expand Down