Check until results are in completed state

This commit is contained in:
gpkvt 2022-08-19 03:09:53 +02:00
parent 54ecaea5b0
commit 60749f6828
1 changed files with 29 additions and 14 deletions

View File

@ -6,6 +6,7 @@
from pprint import pprint
import time
import os
import yaml
import requests
@ -19,19 +20,28 @@ apikey = cfg['virustotal']
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
headers = {
"Accept": "application/json",
"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)
print(" [OK]")
print("Waiting for results", end="")
time.sleep(30)
print(" [OK]")
data = {}
data['data'] = {}
data['data']['attributes'] = {}
data['data']['attributes']['status'] = "incomplete"
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 = {
@ -40,13 +50,18 @@ headers = {
req = requests.get(api_endpoint, headers=headers)
data = req.json()
print(" [OK]")
try:
pprint(data['data']['attributes']['results']['Microsoft'])
except KeyError:
pass
pprint(data['data']['attributes']['stats'])
print(data['data']['attributes']['status'])
print("https://www.virustotal.com/gui/file/"+str(data['meta']['file_info']['sha256']))
try:
if data['data']['attributes']['results']['Microsoft']['category'] != "undetected":
print('FILE WILL BE DETECTED AS MALICIOUS. PLEASE RECOMPILE!')
except KeyError:
pass