From 7196b821e522af11533b13c5cb512995b5e87c25 Mon Sep 17 00:00:00 2001 From: Jerome Leonard Date: Wed, 3 May 2017 14:48:45 +0200 Subject: [PATCH] #21 use misp_modules builtin functions to list and get information from modules (need to install misp_modules) --- contrib/misp-modules-loader.py | 40 +++++++++++++++++----------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/contrib/misp-modules-loader.py b/contrib/misp-modules-loader.py index 48d3bb079..d3bfdcc77 100644 --- a/contrib/misp-modules-loader.py +++ b/contrib/misp-modules-loader.py @@ -7,16 +7,21 @@ import getopt import json +import misp_modules -def mod(path): - dirname = os.path.dirname(path) - name = os.path.basename(path).split('.')[0] - return [dirname, name] +""" +git clone https://github.com/MISP/misp-modules.git +cd misp_modules +pip3 -r REQUIREMENTS +pip3 install . +""" def run(argv): + + mhandlers, modules = misp_modules.load_package_modules() try: - opts, args = getopt.getopt(argv, 'hp:i:r:', ["help", "info=","run="]) + opts, args = getopt.getopt(argv, 'lh:i:r:', ["list", "help", "info=","run="]) except getopt.GetoptError as err: print(__file__ + " --info ") print(__file__ + " --run ") @@ -33,26 +38,21 @@ def run(argv): print(__file__ + " --run ") sys.exit() - elif opt in ('-r', '--run'): - path = arg - if path: - sys.path.append(mod(path)[0]) - m = __import__(mod(path)[1]) + elif opt in ('-l', '--list'): + print(modules) + sys.exit(0) + elif opt in ('-r', '--run'): + module = arg data = json.load(sys.stdin) - print(json.dumps(m.handler(json.dumps(data)))) + print(json.dumps(mhandlers[module].handler(json.dumps(data)))) sys.exit(0) - else: - print("add module path") - elif opt in ('-i','--info'): - path = arg - if path: - sys.path.append(mod(path)[0]) - m = __import__(mod(path)[1]) - print(({'name': module, 'mispattributes': m.mispattributes, - 'moduleinfo':m.moduleinfo})) + module = arg + + print(({'name': module, 'mispattributes': mhandlers[module].mispattributes, + 'moduleinfo':mhandlers[module].moduleinfo}))