chg: PEP8 push script
parent
a84e728b14
commit
2e2081ec48
|
@ -3,7 +3,6 @@ import zmq
|
||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
import pymisp
|
import pymisp
|
||||||
import warnings
|
|
||||||
from pyaml import yaml
|
from pyaml import yaml
|
||||||
from cabby import create_client
|
from cabby import create_client
|
||||||
from misp_stix_converter.converters import lint_roller
|
from misp_stix_converter.converters import lint_roller
|
||||||
|
@ -11,7 +10,8 @@ import logging
|
||||||
|
|
||||||
# Set up logger
|
# Set up logger
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
|
formatter = logging.Formatter(
|
||||||
|
"%(asctime)s - %(name)s - %(levelname)s - %(message)s")
|
||||||
ch = logging.FileHandler("push.log")
|
ch = logging.FileHandler("push.log")
|
||||||
ch.setFormatter(formatter)
|
ch.setFormatter(formatter)
|
||||||
log.addHandler(ch)
|
log.addHandler(ch)
|
||||||
|
@ -22,9 +22,8 @@ log.info("Starting...")
|
||||||
if "OPENTAXII_CONFIG" in os.environ:
|
if "OPENTAXII_CONFIG" in os.environ:
|
||||||
config = yaml.load(open(os.environ["OPENTAXII_CONFIG"], "r"))
|
config = yaml.load(open(os.environ["OPENTAXII_CONFIG"], "r"))
|
||||||
else:
|
else:
|
||||||
config = { "domain" : "127.0.0.1:9000" ,
|
print("OPENTAXII CONFIG NOT EXPORTED")
|
||||||
"zmq" : { "host" : "127.0.0.1", "port" : 50000 }
|
sys.exit()
|
||||||
}
|
|
||||||
|
|
||||||
# Set up our ZMQ socket to recieve MISP JSON on publish
|
# Set up our ZMQ socket to recieve MISP JSON on publish
|
||||||
context = zmq.Context()
|
context = zmq.Context()
|
||||||
|
@ -44,22 +43,28 @@ socket.connect("tcp://{}:{}".format(
|
||||||
socket.setsockopt_string(zmq.SUBSCRIBE, '')
|
socket.setsockopt_string(zmq.SUBSCRIBE, '')
|
||||||
|
|
||||||
# Connct to TAXII as well
|
# Connct to TAXII as well
|
||||||
cli = create_client(discovery_path="{}://{}/services/discovery".format(config.get("protocol", "http"), config["domain"]))
|
cli = create_client(
|
||||||
cli.set_auth(username = config["taxii"]["auth"]["username"],
|
discovery_path="{}://{}/services/discovery".format(
|
||||||
password = config["taxii"]["auth"]["password"]
|
config.get("protocol", "http"),
|
||||||
)
|
config["domain"])
|
||||||
|
)
|
||||||
|
|
||||||
|
cli.set_auth(username=config["taxii"]["auth"]["username"],
|
||||||
|
password=config["taxii"]["auth"]["password"])
|
||||||
|
|
||||||
if not config.get("verify_ssl", True):
|
if not config.get("verify_ssl", True):
|
||||||
cli.verify_ssl = False
|
cli.verify_ssl = False
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
# Wait for something to come in on the ZMQ socket
|
# Wait for something to come in on the ZMQ socket
|
||||||
|
log.info("Waiting...")
|
||||||
message = socket.recv().decode("utf-8")
|
message = socket.recv().decode("utf-8")
|
||||||
log.info("Recieved a message!")
|
log.info("Recieved a message!")
|
||||||
topic = message.split(' ', 1)[0]
|
topic = message.split(' ', 1)[0]
|
||||||
|
|
||||||
if topic != 'misp_json':
|
if topic != 'misp_json':
|
||||||
log.info("Ignoring " + topic + "...")
|
log.info("Ignoring " + topic + "...")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Process the JSON payload
|
# Process the JSON payload
|
||||||
log.debug("Processing...")
|
log.debug("Processing...")
|
||||||
|
@ -76,12 +81,10 @@ while True:
|
||||||
|
|
||||||
# Convert to STIX
|
# Convert to STIX
|
||||||
pkg = pymisp.tools.stix.make_stix_package(ev)
|
pkg = pymisp.tools.stix.make_stix_package(ev)
|
||||||
|
|
||||||
log.debug("Loaded successfully!")
|
log.debug("Loaded successfully!")
|
||||||
|
|
||||||
# Push the package to TAXII
|
# Push the package to TAXII
|
||||||
for version in config.get("stix_versions", ["1.1.1"]):
|
for version in config.get("stix_versions", ["1.1.1"]):
|
||||||
# Convert to that version
|
# Convert to that version
|
||||||
objs = lint_roller.lintRoll(pkg)
|
objs = lint_roller.lintRoll(pkg)
|
||||||
for i in objs:
|
for i in objs:
|
||||||
# Set the object's version
|
# Set the object's version
|
||||||
|
@ -92,15 +95,20 @@ while True:
|
||||||
pkg.version = version
|
pkg.version = version
|
||||||
|
|
||||||
try:
|
try:
|
||||||
log.info("Using binding %s", "urn:stix.mitre.org:xml:{}".format(version))
|
binding = "urn:stix.mitre.org:xml:{}".format(version)
|
||||||
cli.push(content=pkg.to_xml().decode("utf-8"),
|
uri = "{}://{}/services/inbox".format(
|
||||||
content_binding="urn:stix.mitre.org:xml:{}".format(version),
|
config.get("protocol", "http"),
|
||||||
uri="{}://{}/services/inbox".format(config.get("protocol", "http"),
|
config["domain"])
|
||||||
config["domain"]),
|
log.info("Using binding %s", binding)
|
||||||
collection_names=config["taxii"].get("collections", ["collection"]))
|
|
||||||
|
cli.push(content=pkg.to_xml().decode("utf-8"),
|
||||||
|
content_binding=binding,
|
||||||
|
uri=uri,
|
||||||
|
collection_names=config["taxii"].get(
|
||||||
|
"collections", ["collection"]))
|
||||||
|
|
||||||
|
log.info("Pushed! (%s)", version)
|
||||||
|
|
||||||
log.info("Pushed! (%s)", version)
|
|
||||||
|
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
logging.fatal("COULD NOT PUSH")
|
logging.fatal("COULD NOT PUSH")
|
||||||
logging.exception(ex)
|
logging.exception(ex)
|
||||||
|
|
Loading…
Reference in New Issue