From 707233b940471b339ac5ea15bcdface09292e047 Mon Sep 17 00:00:00 2001 From: Alexandre Dulaunoy Date: Wed, 17 Feb 2016 16:04:08 +0100 Subject: [PATCH] First version of a web services to provide ReST API to MISP expansion services. --- bin/misp-modules.py | 65 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 bin/misp-modules.py diff --git a/bin/misp-modules.py b/bin/misp-modules.py new file mode 100644 index 0000000..0d38136 --- /dev/null +++ b/bin/misp-modules.py @@ -0,0 +1,65 @@ +#!/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 . + +import os +import sys +import tornado.web +import importlib +import json + +runPath = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(runPath, '..')) + +modulesdir = '../modules/expansion' + +mhandlers = {} +modules = [] +for module in os.listdir(modulesdir): + if ".py" not in module or ".pyc" in module: + continue + modulename = module.split(".")[0] + modules.append(modulename) + mhandlers[modulename] = importlib.import_module('modules.expansion.'+modulename) + print (module) + +class ListModules(tornado.web.RequestHandler): + def get(self): + ret = [] + for module in modules: + x = {} + x['name'] = module + x['mispattributes'] = mhandlers[module].introspection() + print (x['mispattributes']) + ret.append(x) + self.write(json.dumps(ret)) +class QueryModule(tornado.web.RequestHandler): + def post(self): + jsonpayload = self.request.body.decode('utf-8') + x=json.loads(jsonpayload) + ret = mhandlers[x['module']].handler(q=jsonpayload) + self.write(json.dumps(ret)) + + +service = [(r'/modules',ListModules), (r'/query',QueryModule)] + +application = tornado.web.Application(service) +application.listen(6666) +tornado.ioloop.IOLoop.instance().start()