mirror of https://github.com/MISP/misp-modules
commit
b83b841074
|
@ -0,0 +1,3 @@
|
||||||
|
*.pyc
|
||||||
|
*.swp
|
||||||
|
__pycache__
|
|
@ -25,36 +25,40 @@ import tornado.web
|
||||||
import importlib
|
import importlib
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import re
|
import fnmatch
|
||||||
|
|
||||||
runPath = os.path.dirname(os.path.realpath(__file__))
|
|
||||||
sys.path.append(os.path.join(runPath, '..'))
|
|
||||||
port = 6666
|
port = 6666
|
||||||
|
|
||||||
log = logging.getLogger('misp-modules')
|
|
||||||
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
|
||||||
handler = logging.StreamHandler(stream=sys.stdout)
|
|
||||||
handler.setFormatter(formatter)
|
|
||||||
handler.setLevel(logging.INFO)
|
|
||||||
|
|
||||||
log.addHandler(handler)
|
def init_logger():
|
||||||
log.setLevel(logging.INFO)
|
log = logging.getLogger('misp-modules')
|
||||||
|
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||||
|
handler = logging.StreamHandler(stream=sys.stdout)
|
||||||
|
handler.setFormatter(formatter)
|
||||||
|
handler.setLevel(logging.INFO)
|
||||||
|
|
||||||
modulesdir = '../modules/expansion'
|
log.addHandler(handler)
|
||||||
|
log.setLevel(logging.INFO)
|
||||||
|
return log
|
||||||
|
|
||||||
mhandlers = {}
|
|
||||||
modules = []
|
def load_modules(mod_dir):
|
||||||
for module in os.listdir(modulesdir):
|
sys.path.append(mod_dir)
|
||||||
if ".py" not in module or ".pyc" in module or ".py~" in module:
|
mhandlers = {}
|
||||||
|
modules = []
|
||||||
|
for root, dirnames, filenames in os.walk(mod_dir):
|
||||||
|
if os.path.basename(root) == '__pycache__':
|
||||||
continue
|
continue
|
||||||
if re.match("^\.", module):
|
for filename in fnmatch.filter(filenames, '*.py'):
|
||||||
|
if filename == '__init__.py':
|
||||||
continue
|
continue
|
||||||
modulename = module.split(".")[0]
|
modulename = filename.split(".")[0]
|
||||||
moduletype = os.path.split(modulesdir)[1]
|
moduletype = os.path.split(modulesdir)[1]
|
||||||
modules.append(modulename)
|
modules.append(modulename)
|
||||||
log.info('MISP modules {0} imported'.format(modulename))
|
log.info('MISP modules {0} imported'.format(modulename))
|
||||||
mhandlers[modulename] = importlib.import_module('modules.expansion.' + modulename)
|
mhandlers[modulename] = importlib.import_module(os.path.basename(root) + '.' + modulename)
|
||||||
mhandlers['type:' + modulename] = moduletype
|
mhandlers['type:' + modulename] = moduletype
|
||||||
|
return mhandlers, modules
|
||||||
|
|
||||||
|
|
||||||
class ListModules(tornado.web.RequestHandler):
|
class ListModules(tornado.web.RequestHandler):
|
||||||
|
@ -80,9 +84,13 @@ class QueryModule(tornado.web.RequestHandler):
|
||||||
self.write(json.dumps(ret))
|
self.write(json.dumps(ret))
|
||||||
|
|
||||||
|
|
||||||
service = [(r'/modules', ListModules), (r'/query', QueryModule)]
|
if __name__ == '__main__':
|
||||||
|
modulesdir = '../modules'
|
||||||
|
log = init_logger()
|
||||||
|
mhandlers, modules = load_modules(modulesdir)
|
||||||
|
service = [(r'/modules', ListModules), (r'/query', QueryModule)]
|
||||||
|
|
||||||
application = tornado.web.Application(service)
|
application = tornado.web.Application(service)
|
||||||
log.info('MISP modules server started on TCP port {0}'.format(port))
|
log.info('MISP modules server started on TCP port {0}'.format(port))
|
||||||
application.listen(port)
|
application.listen(port)
|
||||||
tornado.ioloop.IOLoop.instance().start()
|
tornado.ioloop.IOLoop.instance().start()
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
import json
|
||||||
|
import pypssl
|
||||||
|
|
||||||
|
misperrors = {'error': 'Error'}
|
||||||
|
mispattributes = {'input': ['ip-src', 'ip-dst'], 'output': ['freetext']}
|
||||||
|
moduleinfo = {'version': '0.1', 'author': 'Raphaël Vinot', 'description': 'Module to access CIRCL Passive SSL', 'module-type': ['expansion', 'hover']}
|
||||||
|
moduleconfig = ['username', 'password']
|
||||||
|
|
||||||
|
|
||||||
|
def handler(q=False):
|
||||||
|
if q is False:
|
||||||
|
return False
|
||||||
|
request = json.loads(q)
|
||||||
|
if request.get('ip-src'):
|
||||||
|
toquery = request['ip-src']
|
||||||
|
elif request.get('ip-dst'):
|
||||||
|
toquery = request['ip-dst']
|
||||||
|
else:
|
||||||
|
misperrors['error'] = "Unsupported attributes type"
|
||||||
|
return misperrors
|
||||||
|
|
||||||
|
if request.get('config'):
|
||||||
|
if (request['config'].get('username') is None) or (request['config'].get('password') is None):
|
||||||
|
misperrors['error'] = 'CIRCL Passive SSL authentication is missing'
|
||||||
|
return misperrors
|
||||||
|
|
||||||
|
x = pypssl.PyPSSL(basic_auth=(request['config']['username'], request['config']['password']))
|
||||||
|
res = x.query(toquery)
|
||||||
|
out = res.get(toquery)
|
||||||
|
|
||||||
|
r = {'results': [{'types': mispattributes['output'], 'values': out}]}
|
||||||
|
return r
|
||||||
|
|
||||||
|
|
||||||
|
def introspection():
|
||||||
|
return mispattributes
|
||||||
|
|
||||||
|
|
||||||
|
def version():
|
||||||
|
moduleinfo['config'] = moduleconfig
|
||||||
|
return moduleinfo
|
|
@ -0,0 +1 @@
|
||||||
|
{"module": "circl_passivessl", "ip-src": "149.13.33.14", "config": {"username": "auser", "password": "somepass"} }
|
|
@ -0,0 +1 @@
|
||||||
|
curl -s http://127.0.0.1:6666/query -H "Content-Type: application/json" --data @bodycircl_passivessl.json -X POST
|
Loading…
Reference in New Issue