Skip to content

Commit

Permalink
#21 use misp_modules builtin functions to list and get information fr…
Browse files Browse the repository at this point in the history
…om modules (need to install misp_modules)
  • Loading branch information
jeromeleonard committed May 3, 2017
1 parent c042bc6 commit 7196b82
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions contrib/misp-modules-loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <misp-module>")
print(__file__ + " --run <misp-module>")
Expand All @@ -33,26 +38,21 @@ def run(argv):
print(__file__ + " --run <misp-module>")
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}))



Expand Down

0 comments on commit 7196b82

Please sign in to comment.