feat(virustotal): complete v3 command coverage (script-based)

Expand the VirusTotal integration from 3 form-based commands to 15 script-based
commands covering the v3 API: ip/domain/file/url reputation (existing
get_ip_report/get_domain_report ids preserved), file rescan, URL scan,
analysis-get, intelligence search, file sandbox (behaviour) report, passive DNS,
and comments get/add/get-by-id/delete. Scripts handle URL base64 ids,
form-encoded URL submission and comment resource routing.

File-content upload (file-scan) and private scanning are intentionally omitted:
they require an XSOAR-style war-room file entry system Riposte does not have.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Guillaume BOURGEOIS
2026-06-27 15:53:22 +02:00
parent 70dffb3b0a
commit 934f2c52d7
16 changed files with 753 additions and 35 deletions
@@ -0,0 +1,35 @@
import json, os, sys, urllib.request, urllib.parse, urllib.error
def _cfg():
s = json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
base = str(s.get("base_url") or "https://www.virustotal.com/api/v3").rstrip("/")
headers = {"x-apikey": s.get("api_key", ""), "Accept": "application/json"}
return base, headers
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def request(path):
base, headers = _cfg()
req = urllib.request.Request(base + "/" + path.lstrip("/"), headers=headers, method="GET")
with urllib.request.urlopen(req, timeout=90) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def run():
analysis_id = urllib.parse.quote(str(_inputs().get("id", "")), safe="")
print(json.dumps(request("analyses/" + analysis_id)))
try:
run()
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
@@ -0,0 +1,65 @@
import json, os, sys, base64, ipaddress, urllib.request, urllib.parse, urllib.error
def _cfg():
s = json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
base = str(s.get("base_url") or "https://www.virustotal.com/api/v3").rstrip("/")
headers = {"x-apikey": s.get("api_key", ""), "Accept": "application/json"}
return base, headers
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _b64url(u):
return base64.urlsafe_b64encode(u.encode()).decode().strip("=")
def _resource_path(resource, rtype):
rtype = str(rtype or "").strip().lower()
if not rtype:
try:
ipaddress.ip_address(resource)
rtype = "ip"
except ValueError:
h = resource.strip()
if len(h) in (32, 40, 64) and all(c in "0123456789abcdefABCDEF" for c in h):
rtype = "file"
elif "://" in resource:
rtype = "url"
else:
rtype = "domain"
coll = {"ip": "ip_addresses", "domain": "domains", "file": "files", "hash": "files", "url": "urls"}.get(rtype, "files")
rid = _b64url(resource) if coll == "urls" else urllib.parse.quote(resource, safe="")
return coll + "/" + rid
def request(method, path, body=None):
base, headers = _cfg()
h = dict(headers)
data = None
if body is not None:
data = json.dumps(body).encode("utf-8")
h["Content-Type"] = "application/json"
req = urllib.request.Request(base + "/" + path.lstrip("/"), data=data, headers=h, method=method)
with urllib.request.urlopen(req, timeout=90) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def run():
inp = _inputs()
path = _resource_path(str(inp.get("resource", "")), inp.get("resource_type"))
body = {"data": {"type": "comment", "attributes": {"text": inp.get("comment", "")}}}
print(json.dumps(request("POST", path + "/comments", body=body)))
try:
run()
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
@@ -0,0 +1,35 @@
import json, os, sys, urllib.request, urllib.parse, urllib.error
def _cfg():
s = json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
base = str(s.get("base_url") or "https://www.virustotal.com/api/v3").rstrip("/")
headers = {"x-apikey": s.get("api_key", ""), "Accept": "application/json"}
return base, headers
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def request(method, path):
base, headers = _cfg()
req = urllib.request.Request(base + "/" + path.lstrip("/"), headers=headers, method=method)
with urllib.request.urlopen(req, timeout=90) as r:
return r.read().decode("utf-8", "replace")
def run():
comment_id = str(_inputs().get("id", ""))
request("DELETE", "comments/" + urllib.parse.quote(comment_id, safe=""))
print(json.dumps({"deleted": True, "id": comment_id}))
try:
run()
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
@@ -0,0 +1,69 @@
import json, os, sys, base64, ipaddress, urllib.request, urllib.parse, urllib.error
def _cfg():
s = json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
base = str(s.get("base_url") or "https://www.virustotal.com/api/v3").rstrip("/")
headers = {"x-apikey": s.get("api_key", ""), "Accept": "application/json"}
return base, headers
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _b64url(u):
return base64.urlsafe_b64encode(u.encode()).decode().strip("=")
def _resource_path(resource, rtype):
rtype = str(rtype or "").strip().lower()
if not rtype:
try:
ipaddress.ip_address(resource)
rtype = "ip"
except ValueError:
h = resource.strip()
if len(h) in (32, 40, 64) and all(c in "0123456789abcdefABCDEF" for c in h):
rtype = "file"
elif "://" in resource:
rtype = "url"
else:
rtype = "domain"
coll = {"ip": "ip_addresses", "domain": "domains", "file": "files", "hash": "files", "url": "urls"}.get(rtype, "files")
rid = _b64url(resource) if coll == "urls" else urllib.parse.quote(resource, safe="")
return coll + "/" + rid
def request(method, path, params=None, body=None):
base, headers = _cfg()
url = base + "/" + path.lstrip("/")
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean, doseq=True)
h = dict(headers)
data = None
if body is not None:
data = json.dumps(body).encode("utf-8")
h["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=h, method=method)
with urllib.request.urlopen(req, timeout=90) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def run():
inp = _inputs()
path = _resource_path(str(inp.get("resource", "")), inp.get("resource_type"))
print(json.dumps(request("GET", path + "/comments", params={"limit": int(inp.get("limit") or 10)})))
try:
run()
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
@@ -0,0 +1,35 @@
import json, os, sys, urllib.request, urllib.parse, urllib.error
def _cfg():
s = json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
base = str(s.get("base_url") or "https://www.virustotal.com/api/v3").rstrip("/")
headers = {"x-apikey": s.get("api_key", ""), "Accept": "application/json"}
return base, headers
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def request(path):
base, headers = _cfg()
req = urllib.request.Request(base + "/" + path.lstrip("/"), headers=headers, method="GET")
with urllib.request.urlopen(req, timeout=90) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def run():
comment_id = urllib.parse.quote(str(_inputs().get("id", "")), safe="")
print(json.dumps(request("comments/" + comment_id)))
try:
run()
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
+35
View File
@@ -0,0 +1,35 @@
import json, os, sys, urllib.request, urllib.parse, urllib.error
def _cfg():
s = json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
base = str(s.get("base_url") or "https://www.virustotal.com/api/v3").rstrip("/")
headers = {"x-apikey": s.get("api_key", ""), "Accept": "application/json"}
return base, headers
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def request(path):
base, headers = _cfg()
req = urllib.request.Request(base + "/" + path.lstrip("/"), headers=headers, method="GET")
with urllib.request.urlopen(req, timeout=90) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def run():
file_hash = urllib.parse.quote(str(_inputs().get("file", "")), safe="")
print(json.dumps(request("files/" + file_hash)))
try:
run()
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
@@ -0,0 +1,35 @@
import json, os, sys, urllib.request, urllib.parse, urllib.error
def _cfg():
s = json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
base = str(s.get("base_url") or "https://www.virustotal.com/api/v3").rstrip("/")
headers = {"x-apikey": s.get("api_key", ""), "Accept": "application/json"}
return base, headers
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def request(method, path):
base, headers = _cfg()
req = urllib.request.Request(base + "/" + path.lstrip("/"), headers=headers, method=method)
with urllib.request.urlopen(req, timeout=90) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def run():
file_hash = urllib.parse.quote(str(_inputs().get("file", "")), safe="")
print(json.dumps(request("POST", "files/" + file_hash + "/analyse")))
try:
run()
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
@@ -0,0 +1,38 @@
import json, os, sys, urllib.request, urllib.parse, urllib.error
def _cfg():
s = json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
base = str(s.get("base_url") or "https://www.virustotal.com/api/v3").rstrip("/")
headers = {"x-apikey": s.get("api_key", ""), "Accept": "application/json"}
return base, headers
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def request(path, params):
base, headers = _cfg()
clean = {k: v for k, v in params.items() if v not in (None, "")}
url = base + "/" + path.lstrip("/") + ("?" + urllib.parse.urlencode(clean, doseq=True) if clean else "")
req = urllib.request.Request(url, headers=headers, method="GET")
with urllib.request.urlopen(req, timeout=90) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def run():
inp = _inputs()
file_hash = urllib.parse.quote(str(inp.get("file", "")), safe="")
print(json.dumps(request("files/" + file_hash + "/behaviours", {"limit": int(inp.get("limit") or 10)})))
try:
run()
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
@@ -0,0 +1,35 @@
import json, os, sys, urllib.request, urllib.parse, urllib.error
def _cfg():
s = json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
base = str(s.get("base_url") or "https://www.virustotal.com/api/v3").rstrip("/")
headers = {"x-apikey": s.get("api_key", ""), "Accept": "application/json"}
return base, headers
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def request(path):
base, headers = _cfg()
req = urllib.request.Request(base + "/" + path.lstrip("/"), headers=headers, method="GET")
with urllib.request.urlopen(req, timeout=90) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def run():
domain = urllib.parse.quote(str(_inputs().get("domain", "")), safe="")
print(json.dumps(request("domains/" + domain)))
try:
run()
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
@@ -0,0 +1,35 @@
import json, os, sys, urllib.request, urllib.parse, urllib.error
def _cfg():
s = json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
base = str(s.get("base_url") or "https://www.virustotal.com/api/v3").rstrip("/")
headers = {"x-apikey": s.get("api_key", ""), "Accept": "application/json"}
return base, headers
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def request(path):
base, headers = _cfg()
req = urllib.request.Request(base + "/" + path.lstrip("/"), headers=headers, method="GET")
with urllib.request.urlopen(req, timeout=90) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def run():
ip = urllib.parse.quote(str(_inputs().get("ip", "")), safe="")
print(json.dumps(request("ip_addresses/" + ip)))
try:
run()
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
@@ -0,0 +1,44 @@
import json, os, sys, ipaddress, urllib.request, urllib.parse, urllib.error
def _cfg():
s = json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
base = str(s.get("base_url") or "https://www.virustotal.com/api/v3").rstrip("/")
headers = {"x-apikey": s.get("api_key", ""), "Accept": "application/json"}
return base, headers
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def request(path, params):
base, headers = _cfg()
clean = {k: v for k, v in params.items() if v not in (None, "")}
url = base + "/" + path.lstrip("/") + ("?" + urllib.parse.urlencode(clean, doseq=True) if clean else "")
req = urllib.request.Request(url, headers=headers, method="GET")
with urllib.request.urlopen(req, timeout=90) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def run():
inp = _inputs()
resource = str(inp.get("resource", ""))
try:
ipaddress.ip_address(resource)
collection = "ip_addresses"
except ValueError:
collection = "domains"
rid = urllib.parse.quote(resource, safe="")
print(json.dumps(request(collection + "/" + rid + "/resolutions", {"limit": int(inp.get("limit") or 10)})))
try:
run()
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
+37
View File
@@ -0,0 +1,37 @@
import json, os, sys, urllib.request, urllib.parse, urllib.error
def _cfg():
s = json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
base = str(s.get("base_url") or "https://www.virustotal.com/api/v3").rstrip("/")
headers = {"x-apikey": s.get("api_key", ""), "Accept": "application/json"}
return base, headers
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def request(path, params):
base, headers = _cfg()
clean = {k: v for k, v in params.items() if v not in (None, "")}
url = base + "/" + path.lstrip("/") + ("?" + urllib.parse.urlencode(clean, doseq=True) if clean else "")
req = urllib.request.Request(url, headers=headers, method="GET")
with urllib.request.urlopen(req, timeout=90) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def run():
inp = _inputs()
print(json.dumps(request("search", {"query": inp.get("query"), "limit": int(inp.get("limit") or 10)})))
try:
run()
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
@@ -0,0 +1,33 @@
import json, os, sys, urllib.request, urllib.parse, urllib.error
def _cfg():
s = json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
base = str(s.get("base_url") or "https://www.virustotal.com/api/v3").rstrip("/")
headers = {"x-apikey": s.get("api_key", ""), "Accept": "application/json"}
return base, headers
def request(path):
base, headers = _cfg()
req = urllib.request.Request(base + "/" + path.lstrip("/"), headers=headers, method="GET")
with urllib.request.urlopen(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def run():
request("ip_addresses/8.8.8.8")
print(json.dumps({"ok": True}))
try:
run()
except urllib.error.HTTPError as e:
detail = e.read().decode("utf-8", "replace")
msg = "API key is not valid." if e.code in (401, 403) else "HTTP " + str(e.code)
print(json.dumps({"ok": False, "error": msg, "detail": detail}))
sys.exit(1)
except Exception as e:
print(json.dumps({"ok": False, "error": str(e)}))
sys.exit(1)
+39
View File
@@ -0,0 +1,39 @@
import json, os, sys, base64, urllib.request, urllib.parse, urllib.error
def _cfg():
s = json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
base = str(s.get("base_url") or "https://www.virustotal.com/api/v3").rstrip("/")
headers = {"x-apikey": s.get("api_key", ""), "Accept": "application/json"}
return base, headers
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _b64url(u):
return base64.urlsafe_b64encode(u.encode()).decode().strip("=")
def request(path):
base, headers = _cfg()
req = urllib.request.Request(base + "/" + path.lstrip("/"), headers=headers, method="GET")
with urllib.request.urlopen(req, timeout=90) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def run():
url_value = str(_inputs().get("url", ""))
print(json.dumps(request("urls/" + _b64url(url_value))))
try:
run()
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
@@ -0,0 +1,35 @@
import json, os, sys, urllib.request, urllib.parse, urllib.error
def _cfg():
s = json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
base = str(s.get("base_url") or "https://www.virustotal.com/api/v3").rstrip("/")
headers = {"x-apikey": s.get("api_key", ""), "Accept": "application/json"}
return base, headers
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def run():
base, headers = _cfg()
url_value = str(_inputs().get("url", ""))
# VirusTotal expects the URL submission as form-encoded data.
data = urllib.parse.urlencode({"url": url_value}).encode("utf-8")
h = dict(headers)
h["Content-Type"] = "application/x-www-form-urlencoded"
req = urllib.request.Request(base + "/urls", data=data, headers=h, method="POST")
with urllib.request.urlopen(req, timeout=90) as r:
raw = r.read()
print(json.dumps(json.loads(raw) if raw else {}))
try:
run()
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)