Check until results are in completed state

This commit is contained in:
gpkvt 2022-08-19 03:09:53 +02:00
parent f11b03507b
commit 9fd8c17889
1 changed files with 29 additions and 14 deletions

View File

@ -6,6 +6,7 @@
from pprint import pprint from pprint import pprint
import time import time
import os
import yaml import yaml
import requests import requests
@ -19,34 +20,48 @@ apikey = cfg['virustotal']
PyInstaller.__main__.run(['tts.py', '--onefile',]) PyInstaller.__main__.run(['tts.py', '--onefile',])
print("Uploading file", end="") os.replace("./dist/tts.exe", "./tts.exe")
print("Uploading file")
api_endpoint = "https://www.virustotal.com/api/v3/files" # pylint: disable=invalid-name api_endpoint = "https://www.virustotal.com/api/v3/files" # pylint: disable=invalid-name
headers = { headers = {
"Accept": "application/json", "Accept": "application/json",
"X-Apikey": apikey "X-Apikey": apikey
} }
files = {"file": open("./dist/tts.exe", "rb")} files = {"file": open("./tts.exe", "rb")}
req = requests.post(api_endpoint, headers=headers, files=files) req = requests.post(api_endpoint, headers=headers, files=files)
print(" [OK]") print(" [OK]")
print("Waiting for results", end="") data = {}
time.sleep(30) data['data'] = {}
print(" [OK]") data['data']['attributes'] = {}
data = req.json() data['data']['attributes']['status'] = "incomplete"
api_endpoint = f"https://www.virustotal.com/api/v3/analyses/{data['data']['id']}"
headers = { print("Waiting for results")
while data['data']['attributes']['status'] != "completed":
time.sleep(10)
print( "[CHK]")
data = req.json()
api_endpoint = f"https://www.virustotal.com/api/v3/analyses/{data['data']['id']}"
headers = {
'X-Apikey': apikey 'X-Apikey': apikey
} }
req = requests.get(api_endpoint, headers=headers) req = requests.get(api_endpoint, headers=headers)
data = req.json() data = req.json()
print(" [OK]")
try: try:
pprint(data['data']['attributes']['results']['Microsoft']) pprint(data['data']['attributes']['results']['Microsoft'])
except KeyError: except KeyError:
pass pass
pprint(data['data']['attributes']['stats']) pprint(data['data']['attributes']['stats'])
print(data['data']['attributes']['status'])
print("https://www.virustotal.com/gui/file/"+str(data['meta']['file_info']['sha256'])) print("https://www.virustotal.com/gui/file/"+str(data['meta']['file_info']['sha256']))
if data['data']['attributes']['results']['Microsoft']['category'] != "undetected": try:
if data['data']['attributes']['results']['Microsoft']['category'] != "undetected":
print('FILE WILL BE DETECTED AS MALICIOUS. PLEASE RECOMPILE!') print('FILE WILL BE DETECTED AS MALICIOUS. PLEASE RECOMPILE!')
except KeyError:
pass