-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#21 create intermediate program to load misp-modules from Cortex
- Loading branch information
1 parent
2fb0814
commit 96f44f0
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
|
||
import sys | ||
import os | ||
import getopt | ||
import json | ||
|
||
|
||
|
||
# modules_path = "./misp-modules/misp_modules/modules/expansion" | ||
# sys.path.append(modules_path) | ||
|
||
def run(argv): | ||
try: | ||
opts, args = getopt.getopt(argv, 'hp:i:r:', ["help","path=", "info=","run="]) | ||
except getopt.GetoptError as err: | ||
print(__file__ + " --info <misp-module>") | ||
print(__file__ + " --path <misp-modules path> --run <misp-module>") | ||
print(str(err)) | ||
sys.exit(2) | ||
|
||
module = None | ||
path = None | ||
for opt,arg in opts: | ||
|
||
# TODO: check if module exist else exit | ||
if opt in ('-h', '--help'): | ||
print(__file__ + " --info <misp-module>") | ||
print(__file__ + " --run <misp-module>") | ||
sys.exit() | ||
|
||
elif opt in ('-p', '--path'): | ||
path = arg | ||
sys.path.append(path) | ||
|
||
elif opt in ('-r', '--run'): | ||
module = arg | ||
if path: | ||
m = __import__(module) | ||
|
||
data = json.load(sys.stdin) | ||
print(json.dumps(m.handler(json.dumps(data)))) | ||
sys.exit(0) | ||
|
||
else: | ||
print("add module path") | ||
|
||
elif opt in ('-i','--info'): | ||
module = arg | ||
print(module) | ||
m = __import__(module) | ||
print(({'name': module, 'mispattributes': m.mispattributes, | ||
'moduleinfo':m.moduleinfo})) | ||
|
||
|
||
|
||
|
||
if __name__ == '__main__': | ||
if len(sys.argv[1:]) > 0: | ||
run(sys.argv[1:]) | ||
else: | ||
print(__file__ + " --info <misp-module>") | ||
print(__file__ + " --run <misp-module>") | ||
sys.exit(2) |