From dfa2dbc6af10c094471bac356547c8512e0c9409 Mon Sep 17 00:00:00 2001 From: Hannah Ward Date: Wed, 23 Nov 2016 15:31:56 +0000 Subject: [PATCH] No tempfiles! --- .gitignore | 1 + README.md | 5 ++-- collections.yaml => config/collections.yaml | 0 config.yaml => config/config.default.yaml | 9 +++++++ services.yaml => config/services.yaml | 0 misp_taxii_conf.yaml | 10 ------- misp_taxii_hooks/hooks.py | 27 +++++++++---------- .../push_published_to_taxii.py | 0 .../start-misp-taxii.sh | 2 ++ setup.py | 2 +- 10 files changed, 28 insertions(+), 28 deletions(-) rename collections.yaml => config/collections.yaml (100%) rename config.yaml => config/config.default.yaml (79%) rename services.yaml => config/services.yaml (100%) delete mode 100644 misp_taxii_conf.yaml rename push_published_to_taxii.py => scripts/push_published_to_taxii.py (100%) rename start-misp-taxii.sh => scripts/start-misp-taxii.sh (99%) diff --git a/.gitignore b/.gitignore index f63128c..95604ed 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +config.yaml *.egg-info __pycache__ build diff --git a/README.md b/README.md index 9154d3a..3d7fc2e 100644 --- a/README.md +++ b/README.md @@ -47,10 +47,11 @@ Now it's time to create all your SQL tables. Luckily OpenTaxii comes with comman You're going to want to export your configuration file to a variable as well. ```bash +# An example of this config is in the config directory export OPENTAXII_CONFIG=/path/to/config.yaml -opentaxii-create-services -c services.yaml -opentaxii-create-collections -c collections.yaml +opentaxii-create-services -c config/services.yaml +opentaxii-create-collections -c config/collections.yaml # Create a user account # Set the username and password to whatever you want diff --git a/collections.yaml b/config/collections.yaml similarity index 100% rename from collections.yaml rename to config/collections.yaml diff --git a/config.yaml b/config/config.default.yaml similarity index 79% rename from config.yaml rename to config/config.default.yaml index 048c6e5..26e7dcc 100644 --- a/config.yaml +++ b/config/config.default.yaml @@ -20,3 +20,12 @@ logging: root: info hooks: misp_taxii_hooks.hooks +# Sample configuration for misp_taxii_server + +zmq: + host: localhost + port: 50000 + +misp: + url: "http://localhost" + api: KEY diff --git a/services.yaml b/config/services.yaml similarity index 100% rename from services.yaml rename to config/services.yaml diff --git a/misp_taxii_conf.yaml b/misp_taxii_conf.yaml deleted file mode 100644 index 734ac4f..0000000 --- a/misp_taxii_conf.yaml +++ /dev/null @@ -1,10 +0,0 @@ -# Sample configuration for misp_taxii_server - -zmq: - host: localhost - port: 50000 - -taxii: - host: localhost - port: 9000 - inbox: inbox diff --git a/misp_taxii_hooks/hooks.py b/misp_taxii_hooks/hooks.py index 30addba..259daa3 100644 --- a/misp_taxii_hooks/hooks.py +++ b/misp_taxii_hooks/hooks.py @@ -14,30 +14,32 @@ from opentaxii.signals import ( ) ## CONFIG -if "MISP_TAXII_CONFIG" in os.environ: - print("Using config from {}".format(os.environ["MISP_TAXII_CONFIG"])) - CONFIG = yaml.parse(open(os.environ["MISP_TAXII_CONFIG"], "r")) +if "OPENTAXII_CONFIG" in os.environ: + print("Using config from {}".format(os.environ["OPENTAXII_CONFIG"])) + CONFIG = yaml.load(open(os.environ["OPENTAXII_CONFIG"], "r")) else: print("Trying to use env variables...") if "MISP_URL" in os.environ: misp_url = os.environ["MISP_URL"] else: - print("Unkown misp URL. Set MISP_TAXII_CONFIG or MISP_URL.") + print("Unkown misp URL. Set OPENTAXII_CONFIG or MISP_URL.") misp_url = "UNKNOWN" if "MISP_API" in os.environ: misp_api = os.environ["MISP_API"] else: - print("Unknown misp API key. Set MISP_TAXII_CONFIG or MISP_API.") + print("Unknown misp API key. Set OPENTAXII_CONFIG or MISP_API.") misp_api = "UNKNOWN" CONFIG = { - "MISP_URL" : misp_url, - "MISP_API" : misp_api, + "misp" : { + "url" : misp_url, + "api" : misp_api + } } MISP = pymisp.PyMISP( - CONFIG["MISP_URL"], - CONFIG["MISP_API"], + CONFIG["misp"]["url"], + CONFIG["misp"]["api"], ) def post_stix(manager, content_block, collection_ids, service_id): @@ -46,13 +48,8 @@ def post_stix(manager, content_block, collection_ids, service_id): Will convert it to a MISPEvent and push to the server ''' - # Create a temporary file to load STIX data from - f = tempfile.SpooledTemporaryFile(max_size=10*1024, mode="w") - f.write(content_block.content) - f.seek(0) - # Load the package - package = pymisp.tools.stix.load_stix(f) + package = pymisp.tools.stix.load_stix(content_block.content) # Check for duplicates for attrib in package.attributes: diff --git a/push_published_to_taxii.py b/scripts/push_published_to_taxii.py similarity index 100% rename from push_published_to_taxii.py rename to scripts/push_published_to_taxii.py diff --git a/start-misp-taxii.sh b/scripts/start-misp-taxii.sh similarity index 99% rename from start-misp-taxii.sh rename to scripts/start-misp-taxii.sh index 320fb3b..872743c 100755 --- a/start-misp-taxii.sh +++ b/scripts/start-misp-taxii.sh @@ -9,3 +9,5 @@ if [ -z $MISP_TAXII_CONFIG] then echo "Warning: Variable MISP_TAXII_CONFIG not set!"; fi + + diff --git a/setup.py b/setup.py index 8db1366..af383cd 100644 --- a/setup.py +++ b/setup.py @@ -13,6 +13,6 @@ setup( author_email="hannah.ward2@baesystems.com", packages=['misp_taxii_hooks'], install_requires=["zmq", "misp-stix-converter", "pymisp>=2.4.53", "pyaml>=3.11", "cabby>=0.1", "mysqlclient>=1.3.9", "nose>=1.3.7"], - scripts=["start-misp-taxii.sh", "push_published_to_taxii.py"] + scripts=["scripts/start-misp-taxii.sh", "scripts/push_published_to_taxii.py"] )