-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvirustotal.py
60 lines (45 loc) · 1.72 KB
/
virustotal.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
import subprocess
import sys
import os
import re
from vt_api_state import *
from vt_api_json_print import *
from vt_api_call import *
from vt_api_key import *
program_files_path = os.path.join(os.path.expanduser("~"), "vt_api_files/")
if not os.path.exists(program_files_path):
os.makedirs(program_files_path)
def main():
api_key = check_api_key(program_files_path)
input_argv = sys.argv[1]
if input_argv == "" or input_argv.lower() == "-h" or input_argv.lower() == "-help":
print("Usage: python3 virustotal.py <md5sum_hash or file_path>")
exit(0)
hash_or_file = input_argv
if len(hash_or_file) != 32 and bool(re.fullmatch(r'^[\w]*$', hash_or_file)) == False:
if os.name == 'nt':
print("Windows is not available yet!")
exit(1)
# temp_dir = "..."
# output = subprocess.run(["powershell.exe", f'$(certutil -hashfile {input_argv} md5)[1] -replace " ",""'], shell=True, capture_output=True, text=True)
# output = output.stdout
# print(output)
else:
hash_filter = '{print $1}'
try:
hash_output = subprocess.getoutput(f'md5sum {hash_or_file} | awk \'{hash_filter}\'')
except subprocess.CalledProcessError as err:
print(f"Error: {err}")
exit(1)
print("File hash:", hash_output)
hash_or_file = hash_output
if len(hash_or_file) == 32:
url = f'https://www.virustotal.com/api/v3/files/{hash_or_file}'
call_vt_api(url, api_key, program_files_path)
exit(0)
else:
print("MD5 hash only!")
exit(1)
if __name__ == "__main__":
main()
exit(0)