Skip to content

Instantly share code, notes, and snippets.

@mlaferrera
Last active May 18, 2018 20:25
Show Gist options
  • Save mlaferrera/bc52d0523af209053de01750f9487aa3 to your computer and use it in GitHub Desktop.
Save mlaferrera/bc52d0523af209053de01750f9487aa3 to your computer and use it in GitHub Desktop.
Multi worker plugin
import os
import argparse
from stoq.args import StoqArgs
from stoq.plugins import StoqWorkerPlugin
class MultiWorker(StoqWorkerPlugin):
def __init__(self):
super().__init__()
self.plugins_list = ['yara', 'exif']
def activate(self, stoq):
self.stoq = stoq
parser = argparse.ArgumentParser()
parser = StoqArgs(parser)
options = parser.parse_args(self.stoq.argv[2:])
super().activate(options=options)
return True
def scan(self, payload, **kwargs):
"""
Scan a payload using multiple workers
:param bytes payload: Payload to be published
:returns: True
"""
super().scan()
results = {}
for plugin in self.plugins_list:
self.load_worker(plugin)
# If you want just the results from the payload, `scan()` can be called
result = self.workers[plugin].scan(payload)
results[plugin] = result
return results
# However, if you want the full monty... this could be pretty complicated
# self.saveresults = False # this is here to be explicit, it should be in the .stoq config instead
# self.workers[plugin].start(payload, **kwargs)
# return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment