-
Notifications
You must be signed in to change notification settings - Fork 0
/
VT_Uploader.py
67 lines (42 loc) · 1.67 KB
/
VT_Uploader.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
#!/usr/bin/env python3
import requests
import os
import json
def post_sample(file_name, API_KEY):
base_dir = "/media/cape/Malware/Nico/Dataset_Resized_Malicious_Binaries/wastedlocker"
samples = os.listdir(base_dir)
for sample in samples:
SAMPLE = os.path.join(base_dir, sample)
if get_file_size_mb(SAMPLE) < 32:
url = "https://www.virustotal.com/api/v3/files"
files = { "file": (SAMPLE, open(SAMPLE, "rb"), "application/x-ms-dos-executable") }
headers = {
"accept": "application/json",
"x-apikey": API_KEY
}
response = requests.post(url, files=files, headers=headers)
print("Upload done.")
else:
url = get_large_url(API_KEY)
files = { "file": (SAMPLE, open(SAMPLE, "rb"), "application/x-ms-dos-executable") }
headers = {
"accept": "application/json",
"x-apikey": API_KEY
}
response = requests.post(url, files=files, headers=headers)
print("Upload done.")
# Returns a custom URL since some executables are larger than 32 Mb
def get_large_url(API_KEY):
url = "https://www.virustotal.com/api/v3/files/upload_url"
headers = {
"accept": "application/json",
"x-apikey": API_KEY
}
response = requests.get(url, headers=headers)
return json.loads(response.text)['data']
# Returns the size of the file in megabytes.
def get_file_size_mb(file_path):
file_size_bytes = os.path.getsize(file_path)
file_size_mb = file_size_bytes / (1024 * 1024)
return file_size_mb
post_sample("a", "PUT_HERE_THE_API_KEY")