Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
log.addHandler(handler)
log.setLevel(logging.DEBUG if args.verbose else logging.INFO)
log.info("MISP<->STIX Converter")
# Set the config file
if args.config:
configfile = args.config
else:
configfile = os.path.expanduser("~/.misptostix/misp.login")
log.debug("Using config file at %s", configfile)
try:
with open(configfile, "r") as f:
CONFIG = pyaml.yaml.load(f)
except FileNotFoundError:
print("Could not find config file {}".format(configfile))
sys.exit(1)
if args.tag and not ("{}" in args.outfile):
args.outfile += ".{}"
if args.format:
args.format = args.format.lower()
if args.format not in ["json", "xml"]:
print("Only possible output formats are JSON and XML.")
print("{} is not valid".format(args.format))
sys.exit()
else:
args.format = "json"
log.setLevel(logging.DEBUG if args.verbose else logging.INFO)
ch = logging.StreamHandler(sys.stdout)
ch.setLevel(logging.DEBUG if args.verbose else logging.INFO)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
log.addHandler(ch)
# Set the config file
if args.config:
configfile = args.config
else:
configfile = os.path.expanduser("~/.misptostix/misp.login")
try:
with open(configfile, "r") as f:
CONFIG = pyaml.yaml.load(f)
except FileNotFoundError:
log.fatal("Could not find config file %s", configfile)
sys.exit(1)
# Backwards compatability, if users haven't updated config
if "SSL" not in CONFIG["MISP"]:
log.warning("Please update your config file using the misp.login.example to include SSL")
time.sleep(1)
CONFIG["MISP"]["SSL"] = False
# This is just a file conversion
# Relatively quick and easy
MISP = misp.MISP(CONFIG["MISP"]["URL"], CONFIG["MISP"]["KEY"], CONFIG["MISP"].get("SSL", True))
# Load the package
log.info("Opening STIX file %s", args.file)
from misp_stix_converter.converters import lint_roller
import logging
# Set up logger
log = logging.getLogger(__name__)
formatter = logging.Formatter(
"%(asctime)s - %(name)s - %(levelname)s - %(message)s")
ch = logging.FileHandler("push.log")
ch.setFormatter(formatter)
log.addHandler(ch)
log.setLevel(logging.DEBUG)
log.info("Starting...")
# Try to load in config
if "OPENTAXII_CONFIG" in os.environ:
config = yaml.load(open(os.environ["OPENTAXII_CONFIG"], "r"))
else:
print("OPENTAXII CONFIG NOT EXPORTED")
sys.exit()
# Set up our ZMQ socket to recieve MISP JSON on publish
context = zmq.Context()
socket = context.socket(zmq.SUB)
log.info("Subscribing to tcp://{}:{}".format(
config["zmq"]["host"],
config["zmq"]["port"]
))
# Connect to the socket
socket.connect("tcp://{}:{}".format(
config["zmq"]["host"],
def write_recipe(package, recipe_dir, force=False):
"""Write the meta.yaml and build.sh files."""
proj = BioCProjectPage(package)
recipe_dir = os.path.join(recipe_dir, 'bioconductor-' + proj.package.lower())
if os.path.exists(recipe_dir) and not force:
raise ValueError("{0} already exists, aborting".format(recipe_dir))
else:
if not os.path.exists(recipe_dir):
print('creating %s' % recipe_dir)
os.makedirs(recipe_dir)
# If the version number has not changed but something else in the recipe
# *has* changed, then bump the version number.
meta_file = os.path.join(recipe_dir, 'meta.yaml')
if os.path.exists(meta_file):
updated_meta = pyaml.yaml.load(proj.meta_yaml)
current_meta = pyaml.yaml.load(open(meta_file))
# pop off the version and build numbers so we can compare the rest of
# the dicts
updated_version = updated_meta['package'].pop('version')
current_version = current_meta['package'].pop('version')
# updated_build_number = updated_meta['build'].pop('number') # FIXME
current_build_number = current_meta['build'].pop('number')
if (
(updated_version == current_version) and
(updated_meta != current_meta)
):
proj.build_number = int(current_build_number) + 1
with open(os.path.join(recipe_dir, 'meta.yaml'), 'w') as fout:
def process_yaml(path, yaml_content):
yaml_settings = yaml.load(yaml_content)
if not yaml_settings:
return
if 'view' in yaml_settings:
config = yaml_settings['view']
with_theme = False
if isinstance(config, dict):
id = config['id']
with_theme = config.get('with_theme', False)
else:
id = config
path = '/'.join(path[-path[::-1].index('rapido'):])
path = path.rpartition('.')[0]
view = get_block_view(path, with_theme)
provideAdapter(view, (Interface, IBrowserRequest),
Interface, name=id)
log.addHandler(ch)
# Read in the remote server configurations
config_file = "{}/remote-servers.yml".format(
os.path.expanduser(args.configdir))
log.debug("Opening config file %s", config_file)
with open(config_file, "r") as f:
config = yaml.load(f.read())
log.debug("Config read %s", config)
# Read in the local server configuration
local_config = "{}/local-server.yml".format(os.path.expanduser(args.configdir))
log.debug("Reading local server config")
with open(local_config, "r") as f:
local_config = yaml.load(f.read())
# Attempt to make contact with the local server
log.info("Connecting to local server...")
local_client = create_client(host=local_config["host"],
port=local_config["port"],
discovery_path=local_config["discovery_path"],
use_https=local_config["use_https"],
version=local_config["taxii_version"],
headers=local_config["headers"])
local_client.username = local_config["auth"]["username"]
local_client.password = local_config["auth"]["password"]
local_inbox = "{}://{}:{}{}".format(
"https" if local_config["use_https"] else "http",
# If we want, print the output to stdout
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)
# Read in the remote server configurations
config_file = "{}/remote-servers.yml".format(
os.path.expanduser(args.configdir))
log.debug("Opening config file %s", config_file)
with open(config_file, "r") as f:
config = yaml.load(f.read())
log.debug("Config read %s", config)
# Read in the local server configuration
local_config = "{}/local-server.yml".format(os.path.expanduser(args.configdir))
log.debug("Reading local server config")
with open(local_config, "r") as f:
local_config = yaml.load(f.read())
# Attempt to make contact with the local server
log.info("Connecting to local server...")
local_client = create_client(host=local_config["host"],
port=local_config["port"],
discovery_path=local_config["discovery_path"],
use_https=local_config["use_https"],
version=local_config["taxii_version"],
headers=local_config["headers"])
import pymisp
import tempfile
import logging
from pyaml import yaml
from io import StringIO
log = logging.getLogger("__main__")
from opentaxii.signals import (
CONTENT_BLOCK_CREATED, INBOX_MESSAGE_CREATED
)
## CONFIG
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 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 OPENTAXII_CONFIG or MISP_API.")
misp_api = "UNKNOWN"
CONFIG = {
"misp" : {
"url" : misp_url,
"""Write the meta.yaml and build.sh files."""
proj = BioCProjectPage(package)
recipe_dir = os.path.join(recipe_dir, 'bioconductor-' + proj.package.lower())
if os.path.exists(recipe_dir) and not force:
raise ValueError("{0} already exists, aborting".format(recipe_dir))
else:
if not os.path.exists(recipe_dir):
print('creating %s' % recipe_dir)
os.makedirs(recipe_dir)
# If the version number has not changed but something else in the recipe
# *has* changed, then bump the version number.
meta_file = os.path.join(recipe_dir, 'meta.yaml')
if os.path.exists(meta_file):
updated_meta = pyaml.yaml.load(proj.meta_yaml)
current_meta = pyaml.yaml.load(open(meta_file))
# pop off the version and build numbers so we can compare the rest of
# the dicts
updated_version = updated_meta['package'].pop('version')
current_version = current_meta['package'].pop('version')
# updated_build_number = updated_meta['build'].pop('number') # FIXME
current_build_number = current_meta['build'].pop('number')
if (
(updated_version == current_version) and
(updated_meta != current_meta)
):
proj.build_number = int(current_build_number) + 1
with open(os.path.join(recipe_dir, 'meta.yaml'), 'w') as fout:
fout.write(proj.meta_yaml)