From c4d14635770befdc5e87f959e2f06e37c2b0146c Mon Sep 17 00:00:00 2001 From: Hannah Ward Date: Thu, 30 Mar 2017 16:26:46 +0100 Subject: [PATCH] new: added basic auth, polling --- scripts/install-remote-server.sh | 7 +++-- scripts/run-taxii-poll.py | 45 ++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 scripts/run-taxii-poll.py diff --git a/scripts/install-remote-server.sh b/scripts/install-remote-server.sh index 57a0c66..363e0c5 100644 --- a/scripts/install-remote-server.sh +++ b/scripts/install-remote-server.sh @@ -13,13 +13,16 @@ echo "FRIENDLY SERVER NAME:" read SNAME cat >> $CONFIGDIR/servers.yml << EOF -- name: '$SNAME': +- name: '$SNAME' host: localhost port: 9000 discovery_path: use_https: False - taxii_version: 1.1 + taxii_version: '1.1' headers: + auth: + username: + password: EOF echo "New server added to $CONFIGDIR/servers.yml - please go change the settings" diff --git a/scripts/run-taxii-poll.py b/scripts/run-taxii-poll.py new file mode 100644 index 0000000..d356d06 --- /dev/null +++ b/scripts/run-taxii-poll.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 + +from cabby import create_client +from pyaml import yaml +import argparse +import os +import logging +import sys + +parser = argparse.ArgumentParser(description='Run MISP taxii pull.') + +parser.add_argument('-c', "--configdir", default="~/.misptaxii", help='Config directory') +parser.add_argument("-v", "--verbose", action="store_true", help="More verbose logging") +parser.add_argument("-s", "--stdout", action="store_true", help="Log to STDOUT") + +args = parser.parse_args() +log = logging.getLogger(__name__) +log.setLevel(logging.DEBUG if args.verbose else logging.INFO) + +if args.stdout: + formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s") + ch = logging.StreamHandler(sys.stdout) + ch.setFormatter(formatter) + log.addHandler(ch) + +configFile = "{}/servers.yml".format(os.path.expanduser(args.configdir)) +log.debug("Opening config file %s", configFile) +with open(configFile, "r") as f: + config = yaml.load(f.read()) + +log.debug("Config read %s", config) + +for server in config: + log.info("== %s ==", server["name"]) + cli = create_client(host = server["host"], + port = server["port"], + discovery_path = server["discovery_path"], + use_https = server["use_https"], + version = server["taxii_version"], + headers = server["headers"]) + + cli.username = server["auth"]["username"] + cli.password = server["auth"]["password"] + + log.info(list(cli.poll("collection")))