Skip to main content

Python scripts used by MISP to export MISP format into STIX and to import STIX into MISP format.

Project description

MISP-STIX - Python library to handle the conversion between MISP standard and STIX

Python version MISP-STIX version Github Actions License

MISP-STIX-converter is a Python library (>=3.7) to handle all the conversions between the MISP standard format and STIX formats.

Features

This library is used by the MISP core software to perform STIX conversion and serving as a useful tool for anyone looking for a clean way of converting between the MISP standard format and various STIX versions (1.1.1, 1.2, 2.0, 2.1).

A complete documentation is available including the mappings between the different formats.

Install from pip

It is strongly recommended to use a virtual environment

If you want to know more about virtual environments, python has you covered

From the current repository:

pip3 install misp-stix

Install the latest version from the repository for development purposes

Note: poetry is required; e.g., "pip3 install poetry"

git clone https://github.com/MISP/misp-stix.git && cd misp-stix
git submodule update --init
poetry install

Running the tests

Tests for MISP format export as STIX 1.1.1 & 1.2:

poetry run pytest tests/test_stix1_export.py

Tests for MISP format export as STIX 2.0:

poetry run pytest tests/test_stix20_export.py

Tests for MISP format export as STIX 2.1:

poetry run pytest tests/test_stix21_export.py

Usage

Command-line Usage

misp_stix_converter --version 2.1 -f tests/test_events_collection_1.json

Parameters

  • --version: STIX version
  • --file: Input file(s)

Parameters specific to the case of multiple input file(s):

  • --single_output: In case of multiple input files, save the results in on single file
  • --tmp_files: Store temporary results in files before gathering the whole conversion result, instead of keeping it on memory

Parameters specific to STIX 1 export:

  • --feature: MISP data structure level (attribute or event)
  • --namespace: Namespace to be used in the STIX 1 header
  • --org: Organisation name to be used in the STIX 1 header

In Python scripts

Given a MISP Event (with its metadata fields, attributes, objects, galaxies and tags), declared in an event variable in JSON format, you can get the result of a conversion into one of the supported STIX versions:

  • Convert a MISP Event in STIX1:
from misp_stix_converter import MISPtoSTIX1EventsParser

parser = MISPtoSTIX1EventsParser(
    'MISP-Project', # Example of Org name
    '1.1.1' # STIX1 version (1.1.1 or 1.2)
)
parser.parse_misp_event(event)

stix_package = parser.stix_package
  • Convert a MISP Event in STIX1 using directly its file name:
from misp_stix_converter import misp_to_stix1

response = misp_to_stix1(
    filename, # file name of the file containing a MISP Event
    'xml', # return format (XML or JSON)
    '1.1.1' # STIX1 version (1.1.1 or 1.2)
)
# response = 1 if everything went well

The resulting STIX1 Package is then available in a filename.out file

  • Convert a MISP Event in STIX2:
# for STIX 2.0
from misp_stix_converter import MISPtoSTIX20Parser
# for STIX 2.1
from misp_stix_converter import MISPtoSTIX21Parser

parser20 = MISPtoSTIX20Parser()
parser20.parse_misp_event(event)

parser21 = MISPtoSTIX21Parser()
parser21.parse_misp_event(event)

# To get the list of parsed STIX objects
stix_20_objects = parser20.stix_objects
stix_21_objects = parser21.stix_objects

# To get the list of parser STIX objects within a STIX 2.0 or 2.1 Bundle
bundle20 = parser20.bundle
bundle21 = parser21.bundle
  • Convert a MISP Event in STIX2 using directly its file name:
from misp_stix_converter import misp_to_stix2_0, misp_to_stix2_1

response_20 = misp_to_stix2_0(filename)
response_21 = misp_to_stix2_1(filename)
# Again response_20 & response_21 should be 1 if everything went well

The resulting STIX2 Bundle is the available in a filename.out file

If you get some MISP collection of data, it is also possible to convert it straight into some STIX format:

from misp_stix_converter import MISPtoSTIX1EventsParser, MISPtoSTIX20Parser, MISPtoSTIX21Parser

filename = _PATH_TO_YOUR_FILE_CONTAINING_MISP_FORMAT_

parser1 = MISPtoSTIX1EventsParser('MISP', '1.1.1')
parser1.parse_json_content(filename)
stix_package = parser1.stix_package

parser20 = MISPtoSTIX20Parser()
parser20.parse_json_content(filename)
stix_20_objects = parser20.stix_objects
bundle20 = parser20.bundle

parser21 = MISPtoSTIX21Parser()
parser21.parse_json_content(filename)
stix_21_objects = parser21.stix_objects
bundle21 = parser21.bundle

But in order to parse multiple data collections, you can also use the following helpers:

from misp_stix_converter import misp_event_collection_to_stix1, misp_event_collection_to_stix2_0, misp_event_collection_to_stix2_1

input_filenames = [filename for filename in Path(_PATH_TO_YOUR_MISP_FILES_).glob('*.json')]

stix1_response = misp_event_collection_to_stix1(
    output_filename, # path to the file where the results are going to be written
    'xml', # STIX1 return format (XML or JSON)
    '1.1.1', # STIX1 version (1.1.1 or 1.2)
    *input_filenames
)

stix20_response = misp_event_collection_to_stix2_0(
    output_filename, # path to the file where the results are going to be written
    *input_filenames
)

stix21_response = misp_event_collection_to_stix2_1(
    output_filename, # path to the file where the results are going to be written
    *input_filenames
)

Again, all the response variables should be 1 and the resulting STIX1 Package and STIX 2.0 & 2.1 Bundles are available in the specific output file names.

Samples and examples

Various examples are provided and used by the different tests scripts in the tests directory. Those example files are showing the results of MISP format exported in the various supported STIX formats.

MISP <--> STIX Mapping

A specific documentation concerning the mapping between MISP and the various supported STIX versions is also provided in the documentation directory. You can find there all the different cases illustrated with examples.

License

misp-stix is released under a BSD 2-Clause "Simplified" License allow easy reuse with other libraries.

Copyright 2019-2022 Christian Studer
Copyright 2019-2022 CIRCL - Computer Incident Response Center Luxembourg c/o "security made in Lëtzebuerg" (SMILE) g.i.e.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

misp-stix-2.4.161.tar.gz (17.8 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

misp_stix-2.4.161-py3-none-any.whl (34.3 MB view details)

Uploaded Python 3

File details

Details for the file misp-stix-2.4.161.tar.gz.

File metadata

  • Download URL: misp-stix-2.4.161.tar.gz
  • Upload date:
  • Size: 17.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.14 CPython/3.10.4 Linux/5.15.0-46-generic

File hashes

Hashes for misp-stix-2.4.161.tar.gz
Algorithm Hash digest
SHA256 db751bc5d1f4df2498a90827cb5893404eaabcf053df93c0ba3577f228357c73
MD5 cb0d7ea2cc4bd2a04200d227a0e384e8
BLAKE2b-256 44423bcfdbe19ff334aeef39e9267cd59968815255945fa62847f281b7ff932e

See more details on using hashes here.

File details

Details for the file misp_stix-2.4.161-py3-none-any.whl.

File metadata

  • Download URL: misp_stix-2.4.161-py3-none-any.whl
  • Upload date:
  • Size: 34.3 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.14 CPython/3.10.4 Linux/5.15.0-46-generic

File hashes

Hashes for misp_stix-2.4.161-py3-none-any.whl
Algorithm Hash digest
SHA256 c8bb10a3658a9b76f225215b2454c590b367c8d8a43503122cd62f493e32f9f1
MD5 028298b5444ce1e11ffe8068af00d4e2
BLAKE2b-256 a884641377ef7c51a0c88e0322eeeac602cf2e410ca24e1a4c789b7fbfaf5862

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page