Browse Source

Remove bin script, use cleaner way. Fix last commit.

pull/40/head
Raphaël Vinot 6 years ago
parent
commit
59b16950f7
  1. 2
      REQUIREMENTS
  2. 26
      bin/misp-modules
  3. 32
      misp_modules/__init__.py
  4. 2
      misp_modules/modules/__init__.py
  5. 2
      misp_modules/modules/expansion/__init__.py
  6. 5
      misp_modules/modules/expansion/whois.py
  7. 1
      misp_modules/modules/export_mod/__init__.py
  8. 0
      misp_modules/modules/export_mod/testexport.py
  9. 1
      misp_modules/modules/import_mod/__init__.py
  10. 0
      misp_modules/modules/import_mod/ocr.py
  11. 0
      misp_modules/modules/import_mod/testimport.py
  12. 2
      setup.py

2
REQUIREMENTS

@ -10,3 +10,5 @@ pyeupi @@ -10,3 +10,5 @@ pyeupi
ipasn-redis
asnhistory
git+https://github.com/Rafiot/uwhoisd.git@testing#egg=uwhois&subdirectory=client
pillow
pytesseract

26
bin/misp-modules

@ -1,26 +0,0 @@ @@ -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
misp_modules/__init__.py

@ -32,7 +32,7 @@ import argparse @@ -32,7 +32,7 @@ import argparse
import re
try:
from . import modules
from .modules import *
HAS_PACKAGE_MODULES = True
except Exception as e:
print(e)
@ -47,6 +47,7 @@ except Exception as e: @@ -47,6 +47,7 @@ except Exception as e:
log = logging.getLogger('misp-modules')
def handle_signal(sig, frame):
IOLoop.instance().add_callback(IOLoop.instance().stop)
@ -95,8 +96,12 @@ def load_package_helpers(): @@ -95,8 +96,12 @@ def load_package_helpers():
continue
helpername = path.replace('misp_modules.helpers.', '')
mhandlers[helpername] = helper
helpers.append(helpername)
log.info('Helper loaded {}'.format(helpername))
selftest = mhandlers[helpername].selftest()
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
@ -113,7 +118,7 @@ def load_modules(mod_dir): @@ -113,7 +118,7 @@ def load_modules(mod_dir):
if filename == '__init__.py':
continue
modulename = filename.split(".")[0]
moduletype = os.path.split(modulesdir)[1]
moduletype = os.path.split(mod_dir)[1]
try:
mhandlers[modulename] = importlib.import_module(os.path.basename(root) + '.' + modulename)
except Exception as e:
@ -144,8 +149,10 @@ def load_package_modules(): @@ -144,8 +149,10 @@ def load_package_modules():
class ListModules(tornado.web.RequestHandler):
def get(self):
global mhandlers
global loaded_modules
ret = []
for module in modules:
for module in loaded_modules:
x = {}
x['name'] = module
x['type'] = mhandlers['type:' + module]
@ -158,17 +165,19 @@ class ListModules(tornado.web.RequestHandler): @@ -158,17 +165,19 @@ class ListModules(tornado.web.RequestHandler):
class QueryModule(tornado.web.RequestHandler):
def post(self):
global mhandlers
jsonpayload = self.request.body.decode('utf-8')
x = json.loads(jsonpayload)
log.debug('MISP QueryModule request {0}'.format(jsonpayload))
ret = mhandlers[x['module']].handler(q=jsonpayload)
self.write(json.dumps(ret))
def main():
global mhandlers
global loaded_modules
signal.signal(signal.SIGINT, handle_signal)
signal.signal(signal.SIGTERM, handle_signal)
if os.path.dirname(__file__) in ['.', '']:
os.chdir('../')
argParser = argparse.ArgumentParser(description='misp-modules server')
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)')
@ -180,12 +189,13 @@ def main(): @@ -180,12 +189,13 @@ def main():
log = init_logger()
if args.s:
load_package_helpers()
mhandlers, modules = load_package_modules()
mhandlers, loaded_modules = load_package_modules()
else:
modulesdir = 'misp_modules/modules'
helpersdir = 'misp_modules/helpers'
os.chdir(os.path.dirname(__file__))
modulesdir = 'modules'
helpersdir = 'helpers'
load_helpers(helpersdir=helpersdir)
mhandlers, modules = load_modules(modulesdir)
mhandlers, loaded_modules = load_modules(modulesdir)
service = [(r'/modules', ListModules), (r'/query', QueryModule)]
application = tornado.web.Application(service)

2
misp_modules/modules/__init__.py

@ -1 +1,3 @@ @@ -1 +1,3 @@
from .expansion import *
from .import_mod import *
from .export_mod import *

2
misp_modules/modules/expansion/__init__.py

@ -1,2 +1,2 @@ @@ -1,2 +1,2 @@
__all__ = ['asn_history', 'circl_passivedns', 'circl_passivessl', 'cve', 'dns',
'eupi', 'ipasn', 'passivetotal', 'sourcecache']
'eupi', 'ipasn', 'passivetotal', 'sourcecache', 'whois']

5
misp_modules/modules/expansion/whois.py

@ -1,7 +1,10 @@ @@ -1,7 +1,10 @@
# -*- coding: utf-8 -*-
import json
from uwhois import Uwhois
try:
from uwhois import Uwhois
except ImportError:
print("uwhois module not installed.")
misperrors = {'error': 'Error'}
mispattributes = {'input': ['domain', 'ip-src', 'ip-dst'], 'output': ['freetext']}

1
misp_modules/modules/export_mod/__init__.py

@ -0,0 +1 @@ @@ -0,0 +1 @@
__all__ = ['testexport']

0
misp_modules/modules/export/testexport.py → misp_modules/modules/export_mod/testexport.py

1
misp_modules/modules/import_mod/__init__.py

@ -0,0 +1 @@ @@ -0,0 +1 @@
__all__ = ['testimport', 'ocr']

0
misp_modules/modules/import/ocr.py → misp_modules/modules/import_mod/ocr.py

0
misp_modules/modules/import/testimport.py → misp_modules/modules/import_mod/testimport.py

2
setup.py

@ -33,5 +33,7 @@ setup( @@ -33,5 +33,7 @@ setup(
'pyeupi',
'ipasn-redis',
'asnhistory',
'pillow',
'pytesseract',
]
)

Loading…
Cancel
Save