No tempfiles!

pull/7/head
Hannah Ward 2016-11-23 15:31:56 +00:00
parent eb292b3cba
commit dfa2dbc6af
No known key found for this signature in database
GPG Key ID: 6F3BAD60DE190290
10 changed files with 28 additions and 28 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
config.yaml
*.egg-info
__pycache__
build

View File

@ -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

View File

@ -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

View File

@ -1,10 +0,0 @@
# Sample configuration for misp_taxii_server
zmq:
host: localhost
port: 50000
taxii:
host: localhost
port: 9000
inbox: inbox

View File

@ -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:

View File

@ -9,3 +9,5 @@ if [ -z $MISP_TAXII_CONFIG]
then
echo "Warning: Variable MISP_TAXII_CONFIG not set!";
fi

View File

@ -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"]
)