MITRE CTI

repository·master·Indexed 24 days ago

https://github.com/mitre/cti

MITRE ATT&CK and CAPEC datasets serialized in STIX 2.0 format for machine-readable exchange of cyber threat intelligence. This repository provides guidance on using the python-stix2 library to query datasets via FileSystemSource, MemoryStore, or the official ATT&CK TAXII server, including detailed mapping of CAPEC concepts to STIX 2.x objects and properties.

Tokens
5.3K
Snippets
12
Records
22
Agent score
85%

What's inside mitre-cti

  1. Combine multiple ATT&CK domains using CompositeDataSource

    master

    Since ATT&CK is split into multiple domains (enterprise, mobile, ics), you can use stix2.CompositeDataSource to merge multiple individual DataSources into a single searchable object.

    from stix2 import CompositeDataSource
    
    src = CompositeDataSource()
    src.add_data_sources([enterprise_attack_src, mobile_attack_src, ics_attack_src])
  2. Map CAPEC concepts to STIX 2.x objects and properties

    master

    CAPEC data in this repository is provided in STIX 2.0 and 2.1 JSON formats. When working with the data, use the following mapping logic:

    Object Mapping

    • CAPEC Attack Pattern $\rightarrow$ STIX attack-pattern type.
    • CAPEC Mitigations $\rightarrow$ STIX course-of-action type (connected via mitigates relationships).

    Property Mapping

    CAPEC properties are mapped to STIX properties, often using custom x_capec_ prefixes to maintain compatibility.

    Common Attack Pattern Properties:

    • name $\rightarrow$ Name
    • description $\rightarrow$ Description
    • x_capec_extended_definition $\rightarrow$ Extended Definition
    • x_capec_abstraction $\rightarrow$ Abstraction (enumeration: Meta, Standard, Detailed)
    • x_capec_consequences $\rightarrow$ Consequences (dictionary mapping enumeration High, Medium, Low to a string)
    • x_capec_skills_required $\rightarrow$ Skills Required (dictionary mapping string to enumeration High, Medium, Low)
    • external_references $\rightarrow$ Used for CAPEC ID (where source_name == "capec"), CWE ID (where source_name == "cwe"), and external references.
  3. Choosing between MITRE/CTI and attack-stix-data

    master

    This repository (MITRE/CTI) provides ATT&CK and CAPEC datasets in STIX 2.0. However, if you require ATT&CK represented in STIX 2.1, you should use the attack-stix-data repository instead.

    While both repositories are maintained, attack-stix-data includes quality-of-life improvements in its data model that are not present in this repository. For details on those improvements, consult the attack-stix-data USAGE documentation.

  4. Requirements and imports for ATT&CK Python usage

    master

    When working with ATT&CK data in Python, you must install and import the following libraries:

    • stix2: For working with STIX objects programmatically.
    • taxii2client: For accessing data via the TAXII server protocol.
  5. How to use MITRE/CTI datasets with python-stix2

    master
    The datasets in this repository (ATT&CK and CAPEC expressed in STIX 2.0) are designed to be used with the python-stix2 library. For specific implementation details and usage instructions, refer to the USAGE.md or USAGE-CAPEC.md files within this repository.
  6. Follow a 'revoked-by' relationship to find a replacement object

    master

    When an object is replaced, it is marked as revoked and a revoked-by relationship is created. The source_ref is the old (revoked) object, and the target_ref is the new (active) object. Use the following pattern to find the replacement for a given STIX ID.

    from stix2 import Filter
    
    def getRevokedBy(stix_id, thesrc):
        relations = thesrc.relationships(stix_id, 'revoked-by', source_only=True)
        revoked_by = thesrc.query([
            Filter('id', 'in', [r.target_ref for r in relations]),
            Filter('revoked', '=', False)
        ])
        if revoked_by is not None:
            revoked_by = revoked_by[0]
    
        return revoked_by
    
    getRevokedBy("attack-pattern--c16e5409-ee53-4d79-afdc-4099dc9292df", src)
  7. Query CAPEC data using Python and stix2

    master

    To query CAPEC data, use the python-stix2 library. You must initialize a FileSystemSource pointing to the cloned CAPEC corpus.

    Critical Requirement: When creating the FileSystemSource, you must set allow_custom=True. This is necessary because the CAPEC data contains custom STIX properties (e.g., x_capec_prerequisites) that are not part of the standard STIX 2.x specification.

    To perform queries, define a Filter object and pass a list of filters to the query method. Filters passed in a list are logically AND'd together.

  8. Accessing ATT&CK data in Python

    master

    To programmatically query and manipulate ATT&CK data, use Python along with the stix2 and taxii2client libraries. You can access data either from local files within this repository or by connecting to the live ATT&CK TAXII server.

    Note: ATT&CK has unified STIX 2.0 and 2.1 representations. For the most current schema details, refer to the ATT&CK Data Model Specification.

  9. Access live ATT&CK content via TAXII server

    master

    To always stay up to date with the evolving ATT&CK catalog, connect to the official ATT&CK TAXII server.

    Domain Collection IDs:

    • enterprise-attack: 95ecc380-afe9-11e4-9b6c-751b66dd541e
    • mobile-attack: 2f669986-b40b-4423-b720-4396ca6a462b
    • ics-attack: 02c3ef24-9cd4-48f3-a99f-b74ce24f1d34

    Note: Always use taxii2client.v20 when interacting with the MITRE TAXII server.

    from stix2 import TAXIICollectionSource
    from taxii2client.v20 import Collection
    
    collections = {
        "enterprise_attack": "95ecc380-afe9-11e4-9b6c-751b66dd541e",
        "mobile_attack": "2f669986-b40b-4423-b720-4396ca6a462b",
        "ics-attack": "02c3ef24-9cd4-48f3-a99f-b74ce24f1d34"
    }
    
    collection = Collection(f"https://cti-taxii.mitre.org/stix/collections/{collections['enterprise_attack']}/")
    src = TAXIICollectionSource(collection)
  10. Set up Python environment for ATT&CK data

    master

    To work with ATT&CK data in Python, it is recommended to use a virtual environment and install the stix2 and taxii2-client libraries.

    Virtual Environment Setup:

    • macOS/Linux: python3 -m venv env then source env/bin/activate
    • Windows: py -m venv env then env/Scripts/activate.bat

    Important Import Note: When using taxii2-client (version 2.0.0+) to connect to the ATT&CK TAXII 2.0 server, you must use the v20 import to avoid 406 responses. Similarly, if you need to ensure compatibility with the STIX 2.0 API instead of 2.1, use the stix2.v20 specifier.

  11. Retrieve a single ATT&CK object by STIX ID, ATT&CK ID, name, or alias

    master

    You can query the ATT&CK dataset for specific objects using several identifiers. Using a STIX ID is the preferred method as they are guaranteed to be unique.

    By STIX ID

    Use the .get() method on your DataStore object with the full STIX ID.

    By ATT&CK ID

    Use stix2.Filter to query the external_references.external_id field.

    Note: When querying for techniques using an ATT&CK ID, you should also filter by type='attack-pattern' to avoid collisions with deprecated mitigations that previously shared technique IDs.

    By Name

    Filter by type and name using stix2.Filter.

    By Alias

    Filter by type='intrusion-set' and the aliases field to find specific groups.

    # By STIX ID
    g0075 = src.get("intrusion-set--f40eb8ce-2a74-4e56-89a1-227021410142")
    
    # By ATT&CK ID (with type safety for techniques)
    from stix2 import Filter
    t1134 = src.query([ 
        Filter("external_references.external_id", "=", "T1134"), 
        Filter("type", "=", "attack-pattern")
    ])[0]
    
    # By name
    def get_technique_by_name(thesrc, name):
        filt = [
            Filter('type', '=', 'attack-pattern'),
            Filter('name', '=', name)
        ]
        return thesrc.query(filt)
    
    # By alias
    def get_group_by_alias(thesrc, alias):
        return thesrc.query([
            Filter('type', '=', 'intrusion-set'),
            Filter('aliases', '=', alias)
        ])[0]