Skip to main content

A Pydantic-based Python library for parsing, validating, and creating STIX 2.1 cyber threat intelligence data.

Project description

stidantic [WIP]

This is work in progress, compliant but untested.

A Pydantic-based Python library for parsing, validating, and creating STIX 2.1 cyber threat intelligence data.

Python 3.12+ Pydantic v2 STIX v2.1

Overview

stidantic provides a type-safe, Pythonic way to work with STIX 2.1 (Structured Threat Information Expression) objects.

This library leverages Pydantic to provide:

  • 🔒 Strong type validation for all STIX objects
  • 📝 IDE auto-completion and type hints
  • Automatic validation of STIX specification constraints
  • 🔄 Easy JSON serialization/deserialization
  • ❄️ Immutable models with frozen Pydantic configurations
  • 🎯 Discriminated unions for polymorphic STIX object handling

Installation

Requirements

  • Python 3.12 or later (uses PEP 695 type statements)
  • Pydantic >= 2.12

Quick Start

Parsing a STIX Bundle

from stidantic.bundle import StixBundle

# Load from JSON file
with open("threat_data.json", "r") as f:
    bundle = StixBundle.model_validate_json(f.read())

# Access objects
print(f"Bundle contains {len(bundle.objects)} objects")
for obj in bundle.objects:
    print(f"- {obj.type}: {obj.id}")

Creating STIX Objects

from datetime import datetime
from stidantic.sdo import Campaign
from stidantic.types import Identifier

campaign = Campaign(
    id=Identifier("campaign--8e2e2d2b-17d4-4cbf-938f-98ee46b3cd3f"),
    created=datetime.now(),
    modified=datetime.now(),
    name="Operation Stealth",
    description="A sophisticated campaign targeting financial institutions",
    objective="Financial gain through wire fraud"
)

# Export to JSON
json_output = campaign.model_dump_json(indent=2, exclude_none=True, by_alias=True)
print(json_output)

Handling property extensions

from stidantic.marking import MarkingDefinition
from stidantic.extensions.pap import PAPExtensionDefinition, PAPExtension

MarkingDefinition.register_new_extension(PAPExtensionDefinition, PAPExtension)
data = {
    "id": "marking-definition--c43594d1-4b11-4c59-93ab-1c9b14d53ce9",
    "type": "marking-definition",
    "spec_version": "2.1",
    "extensions": {
        "extension-definition--f8d78575-edfd-406e-8e84-6162a8450f5b": {
            "extension_type": "property-extension",
            "pap": "green",
        }
    },
    "created": "2022-10-01T00:00:00Z",
    "name": "PAP:GREEN",
}

pap_green = MarkingDefinition.model_validate(data)
if isinstance(pap_green.extensions[PAPExtensionDefinition.id], PAPExtension):
    print("Extension was parsed & validated by Pydantic.")

Implemented STIX Objects

STIX Domain Objects (SDOs)

  • AttackPattern - Ways adversaries attempt to compromise targets
  • Campaign - Grouping of adversarial behaviors over time
  • Course of Action - Action taken to prevent or respond to an attack
  • Grouping - Explicitly asserts that STIX Objects have a shared context
  • Identity - Actual individuals, organizations, or groups
  • Incident - A stub object representing a security incident
  • Indicator - Pattern that can be used to detect suspicious or malicious activity
  • Infrastructure - Systems, software services, and associated resources
  • Intrusion Set - A grouped set of adversarial behaviors and resources
  • Location - A geographic location
  • Malware - A type of TTP that represents malicious code
  • Malware Analysis - The results of a malware analysis
  • Note - Analyst-created content and context
  • Observed Data - Information about cyber security related entities
  • Opinion - An assessment of the correctness of a STIX Object
  • Report - Collections of threat intelligence
  • Threat Actor - Actual individuals, groups, or organizations
  • Tool - Legitimate software that can be used by threat actors
  • Vulnerability - A mistake in software that can be used to compromise a system

STIX Cyber-observable Objects (SCOs)

  • Artifact - Binary or file-like objects
  • AutonomousSystem - Autonomous System (AS) information
  • Directory - A directory on a file system
  • Domain Name - A network domain name
  • Email Address - An email address
  • Email Message - An email message
  • File - A computer file
  • IPv4 Address - An IPv4 address
  • IPv6 Address - An IPv6 address
  • MAC Address - A Media Access Control (MAC) address
  • Mutex - A mutual exclusion object
  • Network Traffic - A network traffic flow
  • Process - A running process
  • Software - A software product
  • URL - A Uniform Resource Locator (URL)
  • User Account - A user account on a system
  • Windows Registry Key - A key in the Windows registry
  • X.509 Certificate - An X.509 certificate

STIX Relationship Objects (SROs)

  • Relationship - Connections between STIX objects
  • Sighting - Observations of threat intelligence in the wild

Meta Objects

  • MarkingDefinition - Data markings (includes TLP)
  • LanguageContent - Translations and internationalization
  • ExtensionDefinition - Custom STIX extensions

Bundle

  • StixBundle - Container for STIX objects

Extensions

  • PAP - Permissible Actions Protocol (PAP) extension from Oasis

Roadmap

  • Full STIX 2.1 Compliance
  • Python packaging
  • Extensive Testing
  • Mind the datetime datatype serializer to follow the specification (convert to UTC).
  • Implement auto deterministic UUIv5 generation for STIX Identifiers.
  • Implement a Indicator to Observable export method (and the other way round ?).
  • Add Generics validation for Identifier properties that must be of some type.
  • Better STIX Extension Support: Develop a robust and user-friendly mechanism for defining, parsing, and validating custom STIX extensions.
  • TAXII 2.1 Server: Build a TAXII 2.1 compliant server using FastAPI.
  • OCA Standard Extensions: Implement STIX extensions from the Open Cybersecurity Alliance (OCA) and stix-common-objects repositories.
  • Performance Tuning: Profile and optimize parsing and serialization.

Resources

License

stidantic is released under the MIT License.

Acknowledgments

This project implements the STIX 2.1 specification edited by Bret Jordan, Rich Piazza, and Trey Darley, published by the OASIS Cyber Threat Intelligence (CTI) Technical Committee.

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

stidantic-0.1.5.tar.gz (53.3 kB view details)

Uploaded Source

Built Distribution

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

stidantic-0.1.5-py3-none-any.whl (57.9 kB view details)

Uploaded Python 3

File details

Details for the file stidantic-0.1.5.tar.gz.

File metadata

  • Download URL: stidantic-0.1.5.tar.gz
  • Upload date:
  • Size: 53.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for stidantic-0.1.5.tar.gz
Algorithm Hash digest
SHA256 8bf5fbe13b4851400f5017592d53236bd3dfacfedb10cc65a2f263c6f1694eaa
MD5 57b259d704006bf4f0c10f1e62afd9e3
BLAKE2b-256 926b51043ff65032736d381ea69033f067d6160d96bec418c20c074b5e45d535

See more details on using hashes here.

Provenance

The following attestation bundles were made for stidantic-0.1.5.tar.gz:

Publisher: publish.yml on nicocti/stidantic

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file stidantic-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: stidantic-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 57.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for stidantic-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 86c3e3b4003c146cf9d313189c4b7c4999ecb47e5049fdcca2745a90007abe78
MD5 61c8bca442c7aba21905160c5d386763
BLAKE2b-256 bf1dab4698f4e07b8276bccc89b9466bc12cb75b8f07f2bdf32157aa329daf9a

See more details on using hashes here.

Provenance

The following attestation bundles were made for stidantic-0.1.5-py3-none-any.whl:

Publisher: publish.yml on nicocti/stidantic

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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