From 60749f6828d3495dc3cad6fde0f049167d803d29 Mon Sep 17 00:00:00 2001 From: gpkvt Date: Fri, 19 Aug 2022 03:09:53 +0200 Subject: [PATCH] Check until results are in completed state --- build.py | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/build.py b/build.py index c5c337d..0def228 100644 --- a/build.py +++ b/build.py @@ -6,6 +6,7 @@ from pprint import pprint import time +import os import yaml import requests @@ -19,34 +20,48 @@ 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) +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 = { + 'X-Apikey': apikey + } + req = requests.get(api_endpoint, headers=headers) + data = req.json() + print(" [OK]") -data = req.json() -api_endpoint = f"https://www.virustotal.com/api/v3/analyses/{data['data']['id']}" -headers = { - 'X-Apikey': apikey -} -req = requests.get(api_endpoint, headers=headers) -data = req.json() 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'])) -if data['data']['attributes']['results']['Microsoft']['category'] != "undetected": - print('FILE WILL BE DETECTED AS MALICIOUS. PLEASE RECOMPILE!') +try: + if data['data']['attributes']['results']['Microsoft']['category'] != "undetected": + print('FILE WILL BE DETECTED AS MALICIOUS. PLEASE RECOMPILE!') +except KeyError: + pass