mirror of https://github.com/MISP/misp-modules
Improved virustotal module
parent
917c95cad5
commit
0f9221229a
|
@ -7,7 +7,7 @@ mispattributes = {'input': ['hostname', 'domain']}
|
||||||
# possible module-types: 'expansion', 'hover' or both
|
# possible module-types: 'expansion', 'hover' or both
|
||||||
moduleinfo = {'version': '1', 'author': 'Hannah Ward',
|
moduleinfo = {'version': '1', 'author': 'Hannah Ward',
|
||||||
'description': 'Expand Country Codes',
|
'description': 'Expand Country Codes',
|
||||||
'module-type': ['expansion', 'hover']}
|
'module-type': ['hover']}
|
||||||
|
|
||||||
# config fields that your code expects from the site admin
|
# config fields that your code expects from the site admin
|
||||||
moduleconfig = []
|
moduleconfig = []
|
||||||
|
|
|
@ -3,6 +3,7 @@ import requests
|
||||||
import hashlib
|
import hashlib
|
||||||
import re
|
import re
|
||||||
import base64
|
import base64
|
||||||
|
import os
|
||||||
|
|
||||||
misperrors = {'error': 'Error'}
|
misperrors = {'error': 'Error'}
|
||||||
mispattributes = {'input': ['domain', "ip-src", "ip-dst"],
|
mispattributes = {'input': ['domain', "ip-src", "ip-dst"],
|
||||||
|
@ -12,7 +13,7 @@ mispattributes = {'input': ['domain', "ip-src", "ip-dst"],
|
||||||
# possible module-types: 'expansion', 'hover' or both
|
# possible module-types: 'expansion', 'hover' or both
|
||||||
moduleinfo = {'version': '1', 'author': 'Hannah Ward',
|
moduleinfo = {'version': '1', 'author': 'Hannah Ward',
|
||||||
'description': 'Get information from virustotal',
|
'description': 'Get information from virustotal',
|
||||||
'module-type': ['expansion', 'hover']}
|
'module-type': ['expansion']}
|
||||||
|
|
||||||
# config fields that your code expects from the site admin
|
# config fields that your code expects from the site admin
|
||||||
moduleconfig = ["apikey"]
|
moduleconfig = ["apikey"]
|
||||||
|
@ -25,7 +26,6 @@ def handler(q=False):
|
||||||
q = json.loads(q)
|
q = json.loads(q)
|
||||||
|
|
||||||
key = q["config"]["apikey"]
|
key = q["config"]["apikey"]
|
||||||
|
|
||||||
r = {"results": []}
|
r = {"results": []}
|
||||||
|
|
||||||
if "ip-src" in q:
|
if "ip-src" in q:
|
||||||
|
@ -35,10 +35,12 @@ def handler(q=False):
|
||||||
if "domain" in q:
|
if "domain" in q:
|
||||||
r["results"] += getDomain(q["domain"], key)
|
r["results"] += getDomain(q["domain"], key)
|
||||||
|
|
||||||
|
with open("/home/hward/debug.txt", "w") as f:
|
||||||
|
f.write(json.dumps(r))
|
||||||
return r
|
return r
|
||||||
|
|
||||||
def getIP(ip, key):
|
def getIP(ip, key, do_not_recurse = False):
|
||||||
|
print("Getting info for {}".format(ip))
|
||||||
toReturn = []
|
toReturn = []
|
||||||
req = requests.get("https://www.virustotal.com/vtapi/v2/ip-address/report",
|
req = requests.get("https://www.virustotal.com/vtapi/v2/ip-address/report",
|
||||||
params = {"ip":ip, "apikey":key}
|
params = {"ip":ip, "apikey":key}
|
||||||
|
@ -50,14 +52,18 @@ def getIP(ip, key):
|
||||||
if "resolutions" in req:
|
if "resolutions" in req:
|
||||||
for res in req["resolutions"]:
|
for res in req["resolutions"]:
|
||||||
toReturn.append( {"types":["domain"], "values":[res["hostname"]]})
|
toReturn.append( {"types":["domain"], "values":[res["hostname"]]})
|
||||||
|
#Pivot from here to find all domain info
|
||||||
|
if not do_not_recurse:
|
||||||
|
toReturn += getDomain(res["hostname"], key, True)
|
||||||
|
|
||||||
toReturn += getMoreInfo(req, key)
|
toReturn += getMoreInfo(req, key)
|
||||||
return toReturn
|
return toReturn
|
||||||
|
|
||||||
def getDomain(ip, key):
|
def getDomain(domain, key, do_not_recurse=False):
|
||||||
|
print("Getting info for {}".format(domain))
|
||||||
toReturn = []
|
toReturn = []
|
||||||
req = requests.get("https://www.virustotal.com/vtapi/v2/domain/report",
|
req = requests.get("https://www.virustotal.com/vtapi/v2/domain/report",
|
||||||
params = {"domain":ip, "apikey":key}
|
params = {"domain":domain, "apikey":key}
|
||||||
).json()
|
).json()
|
||||||
if req["response_code"] == 0:
|
if req["response_code"] == 0:
|
||||||
#Nothing found
|
#Nothing found
|
||||||
|
@ -66,9 +72,10 @@ def getDomain(ip, key):
|
||||||
if "resolutions" in req:
|
if "resolutions" in req:
|
||||||
for res in req["resolutions"]:
|
for res in req["resolutions"]:
|
||||||
toReturn.append( {"types":["ip-dst", "ip-src"], "values":[res["ip_address"]]})
|
toReturn.append( {"types":["ip-dst", "ip-src"], "values":[res["ip_address"]]})
|
||||||
|
#Pivot from here to find all info on IPs
|
||||||
|
if not do_not_recurse:
|
||||||
|
toReturn += getIP(res["ip_address"], key, True)
|
||||||
toReturn += getMoreInfo(req, key)
|
toReturn += getMoreInfo(req, key)
|
||||||
|
|
||||||
return toReturn
|
return toReturn
|
||||||
|
|
||||||
def findAll(data, keys):
|
def findAll(data, keys):
|
||||||
|
@ -86,33 +93,48 @@ def findAll(data, keys):
|
||||||
|
|
||||||
return a
|
return a
|
||||||
|
|
||||||
|
def isset(d, key):
|
||||||
|
if key in d:
|
||||||
|
if d[key] not in [None, '', ' ']:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def getMoreInfo(req, key):
|
def getMoreInfo(req, key):
|
||||||
|
print("Getting extra info for {}".format(req))
|
||||||
r = []
|
r = []
|
||||||
#Get all hashes first
|
#Get all hashes first
|
||||||
hashes = []
|
hashes = []
|
||||||
hashes = findAll(req, ["md5", "sha1", "sha256", "sha512"])
|
hashes = findAll(req, ["md5", "sha1", "sha256", "sha512"])
|
||||||
r.append({"types":["md5", "sha1", "sha256", "sha512"], "values":hashes})
|
r.append({"types":["md5", "sha1", "sha256", "sha512"], "values":hashes})
|
||||||
for hsh in hashes:
|
for hsh in hashes[:5]:
|
||||||
#Search VT for some juicy info
|
#Search VT for some juicy info
|
||||||
data = requests.get("http://www.virustotal.com/vtapi/v2/file/report",
|
data = requests.get("http://www.virustotal.com/vtapi/v2/file/report",
|
||||||
params={"allinfo":1, "apikey":key, "resource":hsh}
|
params={"allinfo":1, "apikey":key, "resource":hsh}
|
||||||
).json()
|
).json()
|
||||||
if "submission_names" in data:
|
if isset(data, "submission_names"):
|
||||||
r.append({'types':["filename"], "values":data["submission_names"]})
|
r.append({'types':["filename"], "values":data["submission_names"]})
|
||||||
|
|
||||||
if "ssdeep" in data:
|
if isset(data, "ssdeep"):
|
||||||
r.append({'types':["ssdeep"], "values":[data["ssdeep"]]})
|
r.append({'types':["ssdeep"], "values":[data["ssdeep"]]})
|
||||||
|
|
||||||
if "authentihash" in data:
|
if isset(data, "authentihash"):
|
||||||
r.append({"types":["authentihash"], "values":[data["authentihash"]]})
|
r.append({"types":["authentihash"], "values":[data["authentihash"]]})
|
||||||
|
|
||||||
if "ITW_urls" in data:
|
if isset(data, "ITW_urls"):
|
||||||
r.append({"types":["url"], "values":data["ITW_urls"]})
|
r.append({"types":["url"], "values":data["ITW_urls"]})
|
||||||
|
|
||||||
#Get the malware sample
|
#Get the malware sample
|
||||||
sample = requests.get("https://www.virustotal.com/vtapi/v2/file/download",
|
sample = requests.get("https://www.virustotal.com/vtapi/v2/file/download",
|
||||||
params = {"hash":hsh, "apikey":key})
|
params = {"hash":hsh, "apikey":key})
|
||||||
r.append({'types':['malware-sample'], 'values':[str(base64.b64encode(sample.content), 'utf-8')]})
|
|
||||||
|
print(sample)
|
||||||
|
malsample = sample.content
|
||||||
|
r.append({"types":["malware-sample"],
|
||||||
|
"categories":["Payload delivery"],
|
||||||
|
"values":data["submission_names"],
|
||||||
|
"data": str(base64.b64encode(malsample), 'utf-8')
|
||||||
|
}
|
||||||
|
)
|
||||||
return r
|
return r
|
||||||
|
|
||||||
def introspection():
|
def introspection():
|
||||||
|
|
Loading…
Reference in New Issue