mirror of https://github.com/MISP/misp-modules
Merge pull request #40 from Rafiot/master
Remove bin script, use cleaner way. Fix last commit.pull/44/head
commit
d0cdd7de7b
|
@ -10,3 +10,5 @@ pyeupi
|
||||||
ipasn-redis
|
ipasn-redis
|
||||||
asnhistory
|
asnhistory
|
||||||
git+https://github.com/Rafiot/uwhoisd.git@testing#egg=uwhois&subdirectory=client
|
git+https://github.com/Rafiot/uwhoisd.git@testing#egg=uwhois&subdirectory=client
|
||||||
|
pillow
|
||||||
|
pytesseract
|
||||||
|
|
|
@ -1,26 +0,0 @@
|
||||||
#!/usr/bin/env python3
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
#
|
|
||||||
# Core MISP expansion modules loader and web service
|
|
||||||
#
|
|
||||||
# Copyright (C) 2016 Alexandre Dulaunoy
|
|
||||||
# Copyright (C) 2016 CIRCL - Computer Incident Response Center Luxembourg
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU Affero General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU Affero General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
import sys
|
|
||||||
from misp_modules import main
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
sys.exit(main())
|
|
|
@ -32,7 +32,7 @@ import argparse
|
||||||
import re
|
import re
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from . import modules
|
from .modules import *
|
||||||
HAS_PACKAGE_MODULES = True
|
HAS_PACKAGE_MODULES = True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
@ -47,6 +47,7 @@ except Exception as e:
|
||||||
|
|
||||||
log = logging.getLogger('misp-modules')
|
log = logging.getLogger('misp-modules')
|
||||||
|
|
||||||
|
|
||||||
def handle_signal(sig, frame):
|
def handle_signal(sig, frame):
|
||||||
IOLoop.instance().add_callback(IOLoop.instance().stop)
|
IOLoop.instance().add_callback(IOLoop.instance().stop)
|
||||||
|
|
||||||
|
@ -95,8 +96,12 @@ def load_package_helpers():
|
||||||
continue
|
continue
|
||||||
helpername = path.replace('misp_modules.helpers.', '')
|
helpername = path.replace('misp_modules.helpers.', '')
|
||||||
mhandlers[helpername] = helper
|
mhandlers[helpername] = helper
|
||||||
helpers.append(helpername)
|
selftest = mhandlers[helpername].selftest()
|
||||||
log.info('Helper loaded {}'.format(helpername))
|
if selftest is None:
|
||||||
|
helpers.append(helpername)
|
||||||
|
log.info('Helper loaded {}'.format(helpername))
|
||||||
|
else:
|
||||||
|
log.info('Helpers failed {} due to {}'.format(helpername, selftest))
|
||||||
return mhandlers, helpers
|
return mhandlers, helpers
|
||||||
|
|
||||||
|
|
||||||
|
@ -113,7 +118,7 @@ def load_modules(mod_dir):
|
||||||
if filename == '__init__.py':
|
if filename == '__init__.py':
|
||||||
continue
|
continue
|
||||||
modulename = filename.split(".")[0]
|
modulename = filename.split(".")[0]
|
||||||
moduletype = os.path.split(modulesdir)[1]
|
moduletype = os.path.split(mod_dir)[1]
|
||||||
try:
|
try:
|
||||||
mhandlers[modulename] = importlib.import_module(os.path.basename(root) + '.' + modulename)
|
mhandlers[modulename] = importlib.import_module(os.path.basename(root) + '.' + modulename)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -144,8 +149,10 @@ def load_package_modules():
|
||||||
|
|
||||||
class ListModules(tornado.web.RequestHandler):
|
class ListModules(tornado.web.RequestHandler):
|
||||||
def get(self):
|
def get(self):
|
||||||
|
global mhandlers
|
||||||
|
global loaded_modules
|
||||||
ret = []
|
ret = []
|
||||||
for module in modules:
|
for module in loaded_modules:
|
||||||
x = {}
|
x = {}
|
||||||
x['name'] = module
|
x['name'] = module
|
||||||
x['type'] = mhandlers['type:' + module]
|
x['type'] = mhandlers['type:' + module]
|
||||||
|
@ -158,17 +165,19 @@ class ListModules(tornado.web.RequestHandler):
|
||||||
|
|
||||||
class QueryModule(tornado.web.RequestHandler):
|
class QueryModule(tornado.web.RequestHandler):
|
||||||
def post(self):
|
def post(self):
|
||||||
|
global mhandlers
|
||||||
jsonpayload = self.request.body.decode('utf-8')
|
jsonpayload = self.request.body.decode('utf-8')
|
||||||
x = json.loads(jsonpayload)
|
x = json.loads(jsonpayload)
|
||||||
log.debug('MISP QueryModule request {0}'.format(jsonpayload))
|
log.debug('MISP QueryModule request {0}'.format(jsonpayload))
|
||||||
ret = mhandlers[x['module']].handler(q=jsonpayload)
|
ret = mhandlers[x['module']].handler(q=jsonpayload)
|
||||||
self.write(json.dumps(ret))
|
self.write(json.dumps(ret))
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
global mhandlers
|
||||||
|
global loaded_modules
|
||||||
signal.signal(signal.SIGINT, handle_signal)
|
signal.signal(signal.SIGINT, handle_signal)
|
||||||
signal.signal(signal.SIGTERM, handle_signal)
|
signal.signal(signal.SIGTERM, handle_signal)
|
||||||
if os.path.dirname(__file__) in ['.', '']:
|
|
||||||
os.chdir('../')
|
|
||||||
argParser = argparse.ArgumentParser(description='misp-modules server')
|
argParser = argparse.ArgumentParser(description='misp-modules server')
|
||||||
argParser.add_argument('-t', default=False, action='store_true', help='Test mode')
|
argParser.add_argument('-t', default=False, action='store_true', help='Test mode')
|
||||||
argParser.add_argument('-s', default=False, action='store_true', help='Run a system install (package installed via pip)')
|
argParser.add_argument('-s', default=False, action='store_true', help='Run a system install (package installed via pip)')
|
||||||
|
@ -180,12 +189,13 @@ def main():
|
||||||
log = init_logger()
|
log = init_logger()
|
||||||
if args.s:
|
if args.s:
|
||||||
load_package_helpers()
|
load_package_helpers()
|
||||||
mhandlers, modules = load_package_modules()
|
mhandlers, loaded_modules = load_package_modules()
|
||||||
else:
|
else:
|
||||||
modulesdir = 'misp_modules/modules'
|
os.chdir(os.path.dirname(__file__))
|
||||||
helpersdir = 'misp_modules/helpers'
|
modulesdir = 'modules'
|
||||||
|
helpersdir = 'helpers'
|
||||||
load_helpers(helpersdir=helpersdir)
|
load_helpers(helpersdir=helpersdir)
|
||||||
mhandlers, modules = load_modules(modulesdir)
|
mhandlers, loaded_modules = load_modules(modulesdir)
|
||||||
service = [(r'/modules', ListModules), (r'/query', QueryModule)]
|
service = [(r'/modules', ListModules), (r'/query', QueryModule)]
|
||||||
|
|
||||||
application = tornado.web.Application(service)
|
application = tornado.web.Application(service)
|
||||||
|
|
|
@ -1 +1,3 @@
|
||||||
from .expansion import *
|
from .expansion import *
|
||||||
|
from .import_mod import *
|
||||||
|
from .export_mod import *
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
__all__ = ['asn_history', 'circl_passivedns', 'circl_passivessl', 'cve', 'dns',
|
__all__ = ['asn_history', 'circl_passivedns', 'circl_passivessl', 'cve', 'dns',
|
||||||
'eupi', 'ipasn', 'passivetotal', 'sourcecache']
|
'eupi', 'ipasn', 'passivetotal', 'sourcecache', 'whois']
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import json
|
import json
|
||||||
from uwhois import Uwhois
|
try:
|
||||||
|
from uwhois import Uwhois
|
||||||
|
except ImportError:
|
||||||
|
print("uwhois module not installed.")
|
||||||
|
|
||||||
misperrors = {'error': 'Error'}
|
misperrors = {'error': 'Error'}
|
||||||
mispattributes = {'input': ['domain', 'ip-src', 'ip-dst'], 'output': ['freetext']}
|
mispattributes = {'input': ['domain', 'ip-src', 'ip-dst'], 'output': ['freetext']}
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
__all__ = ['testexport']
|
|
@ -0,0 +1 @@
|
||||||
|
__all__ = ['testimport', 'ocr']
|
Loading…
Reference in New Issue