mirror of https://github.com/MISP/misp-modules
Make it a package
parent
f592fd785a
commit
0752c5e3f4
|
@ -1,3 +1,6 @@
|
||||||
*.pyc
|
*.pyc
|
||||||
*.swp
|
*.swp
|
||||||
__pycache__
|
__pycache__
|
||||||
|
build/
|
||||||
|
dist/
|
||||||
|
misp_modules.egg-info/
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
README.md
|
|
@ -29,6 +29,7 @@ import fnmatch
|
||||||
import argparse
|
import argparse
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
||||||
def init_logger():
|
def init_logger():
|
||||||
log = logging.getLogger('misp-modules')
|
log = logging.getLogger('misp-modules')
|
||||||
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||||
|
@ -41,7 +42,7 @@ def init_logger():
|
||||||
return log
|
return log
|
||||||
|
|
||||||
|
|
||||||
def load_helpers(helpersdir='../helpers'):
|
def load_helpers(helpersdir):
|
||||||
sys.path.append(helpersdir)
|
sys.path.append(helpersdir)
|
||||||
hhandlers = {}
|
hhandlers = {}
|
||||||
helpers = []
|
helpers = []
|
||||||
|
@ -51,9 +52,11 @@ def load_helpers(helpersdir='../helpers'):
|
||||||
if re.match(r'^\.', os.path.basename(root)):
|
if re.match(r'^\.', os.path.basename(root)):
|
||||||
continue
|
continue
|
||||||
for filename in fnmatch.filter(filenames, '*.py'):
|
for filename in fnmatch.filter(filenames, '*.py'):
|
||||||
|
if filename == '__init__.py':
|
||||||
|
continue
|
||||||
helpername = filename.split(".")[0]
|
helpername = filename.split(".")[0]
|
||||||
hhandlers[helpername] = importlib.import_module(helpername)
|
hhandlers[helpername] = importlib.import_module(helpername)
|
||||||
selftest= hhandlers[helpername].selftest()
|
selftest = hhandlers[helpername].selftest()
|
||||||
if selftest is None:
|
if selftest is None:
|
||||||
helpers.append(helpername)
|
helpers.append(helpername)
|
||||||
log.info('Helpers loaded {} '.format(filename))
|
log.info('Helpers loaded {} '.format(filename))
|
||||||
|
@ -110,8 +113,8 @@ class QueryModule(tornado.web.RequestHandler):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
if os.path.dirname(__file__) is not '':
|
if os.path.dirname(__file__) is '.':
|
||||||
os.chdir(os.path.dirname(__file__))
|
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('-p', default=6666, help='misp-modules TCP port (default 6666)')
|
argParser.add_argument('-p', default=6666, help='misp-modules TCP port (default 6666)')
|
||||||
|
@ -119,8 +122,8 @@ if __name__ == '__main__':
|
||||||
args = argParser.parse_args()
|
args = argParser.parse_args()
|
||||||
port = args.p
|
port = args.p
|
||||||
listen = args.l
|
listen = args.l
|
||||||
modulesdir = '../modules'
|
modulesdir = 'modules'
|
||||||
helpersdir = '../helpers'
|
helpersdir = 'helpers'
|
||||||
log = init_logger()
|
log = init_logger()
|
||||||
load_helpers(helpersdir=helpersdir)
|
load_helpers(helpersdir=helpersdir)
|
||||||
mhandlers, modules = load_modules(modulesdir)
|
mhandlers, modules = load_modules(modulesdir)
|
||||||
|
|
|
@ -32,7 +32,7 @@ def selftest(enable=True):
|
||||||
return False
|
return False
|
||||||
r = redis.StrictRedis(host=hostname, port=port, db=db)
|
r = redis.StrictRedis(host=hostname, port=port, db=db)
|
||||||
try:
|
try:
|
||||||
r.set('test', 'selftest')
|
r.ping()
|
||||||
except:
|
except:
|
||||||
return 'Redis not running or not installed. Helper will be disabled.'
|
return 'Redis not running or not installed. Helper will be disabled.'
|
||||||
|
|
||||||
|
@ -44,16 +44,15 @@ def get(modulename=None, query=None, value=None, debug=False):
|
||||||
h = hashlib.sha1()
|
h = hashlib.sha1()
|
||||||
h.update(query.encode('UTF-8'))
|
h.update(query.encode('UTF-8'))
|
||||||
hv = h.hexdigest()
|
hv = h.hexdigest()
|
||||||
key = "m:"+modulename+":"+hv
|
key = "m:" + modulename + ":" + hv
|
||||||
|
|
||||||
if not r.exists(key):
|
if not r.exists(key):
|
||||||
if debug:
|
if debug:
|
||||||
print ("Key {} added in cache".format(key))
|
print("Key {} added in cache".format(key))
|
||||||
r.set(key, value)
|
r.setex(key, 86400, value)
|
||||||
r.expire(key, 86400)
|
|
||||||
else:
|
else:
|
||||||
if debug:
|
if debug:
|
||||||
print ("Cache hit with Key {}".format(key))
|
print("Cache hit with Key {}".format(key))
|
||||||
|
|
||||||
return r.get(key)
|
return r.get(key)
|
||||||
|
|
||||||
|
@ -68,14 +67,14 @@ if __name__ == "__main__":
|
||||||
if selftest() is not None:
|
if selftest() is not None:
|
||||||
sys.exit()
|
sys.exit()
|
||||||
else:
|
else:
|
||||||
print ("Selftest ok")
|
print("Selftest ok")
|
||||||
v = get(modulename="testmodule", query="abcdef", value="barfoo", debug=True)
|
v = get(modulename="testmodule", query="abcdef", value="barfoo", debug=True)
|
||||||
if v == b'barfoo':
|
if v == b'barfoo':
|
||||||
print ("Cache ok")
|
print("Cache ok")
|
||||||
v = get(modulename="testmodule", query="abcdef")
|
v = get(modulename="testmodule", query="abcdef")
|
||||||
print (v)
|
print(v)
|
||||||
v = get(modulename="testmodule")
|
v = get(modulename="testmodule")
|
||||||
if (not v):
|
if (not v):
|
||||||
print ("Failed ok")
|
print("Failed ok")
|
||||||
if flush():
|
if flush():
|
||||||
print ("Cache flushed ok")
|
print("Cache flushed ok")
|
||||||
|
|
|
@ -11,7 +11,6 @@ cveapi_url = 'https://cve.circl.lu/api/cve/'
|
||||||
def handler(q=False):
|
def handler(q=False):
|
||||||
if q is False:
|
if q is False:
|
||||||
return False
|
return False
|
||||||
print (q)
|
|
||||||
request = json.loads(q)
|
request = json.loads(q)
|
||||||
if not request.get('vulnerability'):
|
if not request.get('vulnerability'):
|
||||||
misperrors['error'] = 'Vulnerability id missing'
|
misperrors['error'] = 'Vulnerability id missing'
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from setuptools import setup
|
||||||
|
|
||||||
|
setup(
|
||||||
|
name='misp-modules',
|
||||||
|
version='1.0',
|
||||||
|
author='Alexandre Dulaunoy',
|
||||||
|
author_email='alexandre.dulaunoy@circl.lu',
|
||||||
|
maintainer='Alexandre Dulaunoy',
|
||||||
|
url='https://github.com/MISP/misp-modules',
|
||||||
|
description='MISP modules are autonomous modules that can be used for expansion and other services in MISP',
|
||||||
|
packages=['modules', 'helpers'],
|
||||||
|
scripts=['bin/misp-modules.py'],
|
||||||
|
test_suite="tests",
|
||||||
|
classifiers=[
|
||||||
|
'License :: OSI Approved :: GNU Affero General Public License v3',
|
||||||
|
'Development Status :: 5 - Production/Stable',
|
||||||
|
'Environment :: Console',
|
||||||
|
'Intended Audience :: Science/Research',
|
||||||
|
'Programming Language :: Python :: 3',
|
||||||
|
'Topic :: Security',
|
||||||
|
],
|
||||||
|
install_requires=[
|
||||||
|
'tornado',
|
||||||
|
'dnspython3',
|
||||||
|
'requests',
|
||||||
|
'urlarchiver',
|
||||||
|
'passivetotal',
|
||||||
|
'PyPDNS',
|
||||||
|
'pypssl',
|
||||||
|
'redis',
|
||||||
|
'pyeupi',
|
||||||
|
'ipasn-redis',
|
||||||
|
'asnhistory',
|
||||||
|
]
|
||||||
|
)
|
Loading…
Reference in New Issue