mirror of https://github.com/MISP/misp-modules
Merge pull request #393 from vmray-labs/update-vmray-module
Update vmray_submit modulepull/402/head
commit
97bcc550a7
|
@ -14,6 +14,7 @@ as a cron job
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import base64
|
import base64
|
||||||
|
from distutils.util import strtobool
|
||||||
|
|
||||||
import io
|
import io
|
||||||
import zipfile
|
import zipfile
|
||||||
|
@ -22,7 +23,7 @@ from ._vmray.vmray_rest_api import VMRayRESTAPI
|
||||||
|
|
||||||
misperrors = {'error': 'Error'}
|
misperrors = {'error': 'Error'}
|
||||||
mispattributes = {'input': ['attachment', 'malware-sample'], 'output': ['text', 'sha1', 'sha256', 'md5', 'link']}
|
mispattributes = {'input': ['attachment', 'malware-sample'], 'output': ['text', 'sha1', 'sha256', 'md5', 'link']}
|
||||||
moduleinfo = {'version': '0.2', 'author': 'Koen Van Impe',
|
moduleinfo = {'version': '0.3', 'author': 'Koen Van Impe',
|
||||||
'description': 'Submit a sample to VMRay',
|
'description': 'Submit a sample to VMRay',
|
||||||
'module-type': ['expansion']}
|
'module-type': ['expansion']}
|
||||||
moduleconfig = ['apikey', 'url', 'shareable', 'do_not_reanalyze', 'do_not_include_vmrayjobids']
|
moduleconfig = ['apikey', 'url', 'shareable', 'do_not_reanalyze', 'do_not_include_vmrayjobids']
|
||||||
|
@ -71,25 +72,13 @@ def handler(q=False):
|
||||||
do_not_reanalyze = request["config"].get("do_not_reanalyze")
|
do_not_reanalyze = request["config"].get("do_not_reanalyze")
|
||||||
do_not_include_vmrayjobids = request["config"].get("do_not_include_vmrayjobids")
|
do_not_include_vmrayjobids = request["config"].get("do_not_include_vmrayjobids")
|
||||||
|
|
||||||
# Do we want the sample to be shared?
|
try:
|
||||||
if shareable == "True":
|
shareable = bool(strtobool(shareable)) # Do we want the sample to be shared?
|
||||||
shareable = True
|
reanalyze = not bool(strtobool(do_not_reanalyze)) # Always reanalyze the sample?
|
||||||
else:
|
include_vmrayjobids = not bool(strtobool(do_not_include_vmrayjobids)) # Include the references to VMRay job IDs
|
||||||
shareable = False
|
except ValueError:
|
||||||
|
misperrors["error"] = "Error while processing settings. Please double-check your values."
|
||||||
# Always reanalyze the sample?
|
return misperrors
|
||||||
if do_not_reanalyze == "True":
|
|
||||||
do_not_reanalyze = True
|
|
||||||
else:
|
|
||||||
do_not_reanalyze = False
|
|
||||||
reanalyze = not do_not_reanalyze
|
|
||||||
|
|
||||||
# Include the references to VMRay job IDs
|
|
||||||
if do_not_include_vmrayjobids == "True":
|
|
||||||
do_not_include_vmrayjobids = True
|
|
||||||
else:
|
|
||||||
do_not_include_vmrayjobids = False
|
|
||||||
include_vmrayjobids = not do_not_include_vmrayjobids
|
|
||||||
|
|
||||||
if data and sample_filename:
|
if data and sample_filename:
|
||||||
args = {}
|
args = {}
|
||||||
|
@ -99,7 +88,7 @@ def handler(q=False):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
vmraydata = vmraySubmit(api, args)
|
vmraydata = vmraySubmit(api, args)
|
||||||
if vmraydata["errors"]:
|
if vmraydata["errors"] and "Submission not stored" not in vmraydata["errors"][0]["error_msg"]:
|
||||||
misperrors['error'] = "VMRay: %s" % vmraydata["errors"][0]["error_msg"]
|
misperrors['error'] = "VMRay: %s" % vmraydata["errors"][0]["error_msg"]
|
||||||
return misperrors
|
return misperrors
|
||||||
else:
|
else:
|
||||||
|
@ -125,22 +114,20 @@ def vmrayProcess(vmraydata):
|
||||||
''' Process the JSON file returned by vmray'''
|
''' Process the JSON file returned by vmray'''
|
||||||
if vmraydata:
|
if vmraydata:
|
||||||
try:
|
try:
|
||||||
submissions = vmraydata["submissions"][0]
|
sample = vmraydata["samples"][0]
|
||||||
jobs = vmraydata["jobs"]
|
jobs = vmraydata["jobs"]
|
||||||
|
|
||||||
# Result received?
|
# Result received?
|
||||||
if submissions and jobs:
|
if sample:
|
||||||
r = {'results': []}
|
r = {'results': []}
|
||||||
r['results'].append({'types': 'md5', 'values': submissions['submission_sample_md5']})
|
r['results'].append({'types': 'md5', 'values': sample['sample_md5hash']})
|
||||||
r['results'].append({'types': 'sha1', 'values': submissions['submission_sample_sha1']})
|
r['results'].append({'types': 'sha1', 'values': sample['sample_sha1hash']})
|
||||||
r['results'].append({'types': 'sha256', 'values': submissions['submission_sample_sha256']})
|
r['results'].append({'types': 'sha256', 'values': sample['sample_sha256hash']})
|
||||||
r['results'].append({'types': 'text', 'values': 'VMRay Sample ID: %s' % submissions['submission_sample_id'], 'tags': 'workflow:state="incomplete"'})
|
r['results'].append({'types': 'text', 'values': 'VMRay Sample ID: %s' % sample['sample_id'], 'tags': 'workflow:state="incomplete"'})
|
||||||
r['results'].append({'types': 'text', 'values': 'VMRay Submission ID: %s' % submissions['submission_id']})
|
r['results'].append({'types': 'link', 'values': sample['sample_webif_url']})
|
||||||
r['results'].append({'types': 'text', 'values': 'VMRay Submission Sample IP: %s' % submissions['submission_ip_ip']})
|
|
||||||
r['results'].append({'types': 'link', 'values': submissions['submission_webif_url']})
|
|
||||||
|
|
||||||
# Include data from different jobs
|
# Include data from different jobs
|
||||||
if include_vmrayjobids:
|
if include_vmrayjobids and len(jobs) > 0:
|
||||||
for job in jobs:
|
for job in jobs:
|
||||||
job_id = job["job_id"]
|
job_id = job["job_id"]
|
||||||
job_vm_name = job["job_vm_name"]
|
job_vm_name = job["job_vm_name"]
|
||||||
|
|
Loading…
Reference in New Issue