forked from arudmaestro/vtSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtSubmit.py
66 lines (48 loc) · 1.68 KB
/
vtSubmit.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
# Import modules
import os
import csv
import random
import requests
import json
# Generate random 3 digit number for filename
random_num = str(random.randint(100,999))
# Get API key from user input
api_key = input("Enter your VirusTotal API key: ")
# Get folder path from user input
folder_path = input("Enter folder path: ")
# Output CSV filename
output_file = 'vt_results_' + random_num + '.csv'
# Open CSV file for writing
with open(output_file, 'w', newline='') as csvfile:
# Create CSV writer
writer = csv.writer(csvfile)
# Write header row
writer.writerow(['Filename', 'Scan URL'])
# Walk through the directory tree
for root, dirs, files in os.walk(folder_path):
for filename in files:
# Construct full file path
file_path = os.path.join(root, filename)
try:
# Open file in binary mode
with open(file_path, 'rb') as f:
# Construct payload with file contents
files = {'file': (filename, f)}
# Make API request
response = requests.post(
'https://www.virustotal.com/vtapi/v2/file/scan',
files=files,
headers={'API-Key': api_key} # Note: VirusTotal uses x-apikey instead of API-Key in the header
)
# Check response status code
if response.status_code == 200:
# Extract scan URL
url = response.json()['permalink']
# Write row to CSV
writer.writerow([filename, url])
else:
print(f'Error uploading {file_path}')
except Exception as e:
print(f'An error occurred processing {file_path}: {e}')
# Print output filename
print(f'Results written to {output_file}')