[gimp-web] tools: add virustotal_upload.py



commit 0d18835de344adde602b9ae06af3c2914dfc5979
Author: Michael Schumacher <schumaml gmx de>
Date:   Thu Feb 18 23:34:34 2021 +0100

    tools: add virustotal_upload.py
    
    Small tool to upload large files, like our Microsoft Windows installers or Apple DMG, to VirusTotal for 
analysis.
    
    Requires a free VirusTotal API key.

 tools/downloads/virustotal-upload.py | 50 ++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)
---
diff --git a/tools/downloads/virustotal-upload.py b/tools/downloads/virustotal-upload.py
new file mode 100755
index 00000000..3ce36f6c
--- /dev/null
+++ b/tools/downloads/virustotal-upload.py
@@ -0,0 +1,50 @@
+#!/usr/bin/env python3
+
+import os
+import argparse
+import requests
+
+parser = argparse.ArgumentParser(description='Upload a large file to VirusTotal')
+parser.add_argument('apikey', metavar='<apikey>',
+                    help='Your VirusTotal API key')
+parser.add_argument(dest='file', metavar='<file>',
+                    help='The file to be uploaded')
+
+args = parser.parse_args()
+
+# get the upload url
+# see https://developers.virustotal.com/v3.0/reference#files-upload-url
+headers = { 'x-apikey' : args.apikey }
+url = 'https://www.virustotal.com/api/v3/files/upload_url'
+
+response = requests.get(url=url, timeout=10, headers=headers)
+
+# response JSON
+# {
+#  "data": "http://www.virustotal.com/_ah/upload/AMmfu6b-_DXUeFe36Sb3b0F4B8mH9Nb-CHbRoUNVOPwG/";
+# }
+
+if response.status_code == 200:
+    json = response.json()
+    upload_url = json['data']
+
+    files = {'file': open(os.path.abspath(args.file), 'rb')}
+    
+    # upload file
+    # see https://developers.virustotal.com/v3.0/reference#files-scan
+    response = requests.post(url=upload_url, headers=headers, files=files)
+
+    # response JSON
+    # {
+    #     "data": {
+    #            "type": "analysis",
+    #            "id": "NjY0MjRlOTFjMDIyYTkyNWM0NjU2NWQzYWNlMzFmZmI6MTQ3NTA0ODI3Nw=="
+    #     }
+    # }
+
+    # https://developers.virustotal.com/v3.0/reference#analysis
+    if response.status_code == 200:
+       json = response.json()
+       analysis_id = json['data']['id']
+
+       print('File analysis: https://www.virustotal.com/gui/file-analysis/' +  analysis_id)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]