stidantic 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- stidantic-0.1.0/.gitignore +207 -0
- stidantic-0.1.0/LICENSE +21 -0
- stidantic-0.1.0/PKG-INFO +173 -0
- stidantic-0.1.0/README.md +145 -0
- stidantic-0.1.0/pyproject.toml +56 -0
- stidantic-0.1.0/stidantic/__init__.py +23 -0
- stidantic-0.1.0/stidantic/__init__.pyi +14 -0
- stidantic-0.1.0/stidantic/bundle.py +29 -0
- stidantic-0.1.0/stidantic/extension.py +115 -0
- stidantic-0.1.0/stidantic/language.py +35 -0
- stidantic-0.1.0/stidantic/marking.py +118 -0
- stidantic-0.1.0/stidantic/sco.py +91 -0
- stidantic-0.1.0/stidantic/sdo.py +87 -0
- stidantic-0.1.0/stidantic/sro.py +159 -0
- stidantic-0.1.0/stidantic/types.py +409 -0
- stidantic-0.1.0/stidantic/validators.py +20 -0
- stidantic-0.1.0/stidantic/vocab.py +512 -0
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# UV
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
#uv.lock
|
|
102
|
+
|
|
103
|
+
# poetry
|
|
104
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
105
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
106
|
+
# commonly ignored for libraries.
|
|
107
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
108
|
+
#poetry.lock
|
|
109
|
+
#poetry.toml
|
|
110
|
+
|
|
111
|
+
# pdm
|
|
112
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
113
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
114
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
115
|
+
#pdm.lock
|
|
116
|
+
#pdm.toml
|
|
117
|
+
.pdm-python
|
|
118
|
+
.pdm-build/
|
|
119
|
+
|
|
120
|
+
# pixi
|
|
121
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
122
|
+
#pixi.lock
|
|
123
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
124
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
125
|
+
.pixi
|
|
126
|
+
|
|
127
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
128
|
+
__pypackages__/
|
|
129
|
+
|
|
130
|
+
# Celery stuff
|
|
131
|
+
celerybeat-schedule
|
|
132
|
+
celerybeat.pid
|
|
133
|
+
|
|
134
|
+
# SageMath parsed files
|
|
135
|
+
*.sage.py
|
|
136
|
+
|
|
137
|
+
# Environments
|
|
138
|
+
.env
|
|
139
|
+
.envrc
|
|
140
|
+
.venv
|
|
141
|
+
env/
|
|
142
|
+
venv/
|
|
143
|
+
ENV/
|
|
144
|
+
env.bak/
|
|
145
|
+
venv.bak/
|
|
146
|
+
|
|
147
|
+
# Spyder project settings
|
|
148
|
+
.spyderproject
|
|
149
|
+
.spyproject
|
|
150
|
+
|
|
151
|
+
# Rope project settings
|
|
152
|
+
.ropeproject
|
|
153
|
+
|
|
154
|
+
# mkdocs documentation
|
|
155
|
+
/site
|
|
156
|
+
|
|
157
|
+
# mypy
|
|
158
|
+
.mypy_cache/
|
|
159
|
+
.dmypy.json
|
|
160
|
+
dmypy.json
|
|
161
|
+
|
|
162
|
+
# Pyre type checker
|
|
163
|
+
.pyre/
|
|
164
|
+
|
|
165
|
+
# pytype static type analyzer
|
|
166
|
+
.pytype/
|
|
167
|
+
|
|
168
|
+
# Cython debug symbols
|
|
169
|
+
cython_debug/
|
|
170
|
+
|
|
171
|
+
# PyCharm
|
|
172
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
173
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
174
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
175
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
176
|
+
#.idea/
|
|
177
|
+
|
|
178
|
+
# Abstra
|
|
179
|
+
# Abstra is an AI-powered process automation framework.
|
|
180
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
181
|
+
# Learn more at https://abstra.io/docs
|
|
182
|
+
.abstra/
|
|
183
|
+
|
|
184
|
+
# Visual Studio Code
|
|
185
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
186
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
187
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
188
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
189
|
+
# .vscode/
|
|
190
|
+
|
|
191
|
+
# Ruff stuff:
|
|
192
|
+
.ruff_cache/
|
|
193
|
+
|
|
194
|
+
# PyPI configuration file
|
|
195
|
+
.pypirc
|
|
196
|
+
|
|
197
|
+
# Cursor
|
|
198
|
+
# Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
|
|
199
|
+
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
|
|
200
|
+
# refer to https://docs.cursor.com/context/ignore-files
|
|
201
|
+
.cursorignore
|
|
202
|
+
.cursorindexingignore
|
|
203
|
+
|
|
204
|
+
# Marimo
|
|
205
|
+
marimo/_static/
|
|
206
|
+
marimo/_lsp/
|
|
207
|
+
__marimo__/
|
stidantic-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 nicocti
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
stidantic-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: stidantic
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Pydantic-based Python library for parsing, validating, and creating STIX 2.1 cyber threat intelligence data
|
|
5
|
+
Project-URL: Homepage, https://github.com/nicocti/stidantic
|
|
6
|
+
Project-URL: Repository, https://github.com/nicocti/stidantic
|
|
7
|
+
Project-URL: Issues, https://github.com/nicocti/stidantic/issues
|
|
8
|
+
Project-URL: Documentation, https://github.com/nicocti/stidantic#readme
|
|
9
|
+
Author-email: nicocti <your.email@example.com>
|
|
10
|
+
Maintainer-email: nicocti <your.email@example.com>
|
|
11
|
+
License: MIT
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: cti,pydantic,stix,stix2,stix2.1
|
|
14
|
+
Classifier: Development Status :: 3 - Alpha
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Intended Audience :: Information Technology
|
|
17
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Classifier: Programming Language :: Python :: 3
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Topic :: Security
|
|
23
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
|
+
Classifier: Typing :: Typed
|
|
25
|
+
Requires-Python: >=3.12
|
|
26
|
+
Requires-Dist: pydantic>=2.12
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# stidantic [WIP]
|
|
30
|
+
|
|
31
|
+
**This is work in progress, not compliant yet.**
|
|
32
|
+
|
|
33
|
+
A Pydantic-based Python library for parsing, validating, and creating STIX 2.1 cyber threat intelligence data.
|
|
34
|
+
|
|
35
|
+
[](https://www.python.org/downloads/)
|
|
36
|
+
[](https://docs.pydantic.dev/)
|
|
37
|
+
|
|
38
|
+
## Overview
|
|
39
|
+
|
|
40
|
+
**stidantic** provides a type-safe, Pythonic way to work with [STIX 2.1](https://oasis-open.github.io/cti-documentation/stix/intro) (Structured Threat Information Expression) objects.
|
|
41
|
+
|
|
42
|
+
This library leverages [Pydantic](https://docs.pydantic.dev/) to provide:
|
|
43
|
+
|
|
44
|
+
- 🔒 **Strong type validation** for all STIX objects
|
|
45
|
+
- 📝 **IDE auto-completion** and type hints
|
|
46
|
+
- ✅ **Automatic validation** of STIX specification constraints
|
|
47
|
+
- 🔄 **Easy JSON serialization/deserialization**
|
|
48
|
+
- ❄️ **Immutable models** with frozen Pydantic configurations
|
|
49
|
+
- 🎯 **Discriminated unions** for polymorphic STIX object handling
|
|
50
|
+
|
|
51
|
+
## Installation
|
|
52
|
+
|
|
53
|
+
### Requirements
|
|
54
|
+
|
|
55
|
+
- Python 3.12 or later (uses PEP 695 type statements)
|
|
56
|
+
- Pydantic > 2.10
|
|
57
|
+
|
|
58
|
+
## Quick Start
|
|
59
|
+
|
|
60
|
+
### Parsing a STIX Bundle
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
from stidantic.bundle import StixBundle
|
|
64
|
+
|
|
65
|
+
# Load from JSON file
|
|
66
|
+
with open("threat_data.json", "r") as f:
|
|
67
|
+
bundle = StixBundle.model_validate_json(f.read())
|
|
68
|
+
|
|
69
|
+
# Access objects
|
|
70
|
+
print(f"Bundle contains {len(bundle.objects)} objects")
|
|
71
|
+
for obj in bundle.objects:
|
|
72
|
+
print(f"- {obj.type}: {obj.id}")
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Creating STIX Objects
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
from datetime import datetime
|
|
79
|
+
from stidantic.sdo import Campaign
|
|
80
|
+
from stidantic.types import Identifier
|
|
81
|
+
|
|
82
|
+
campaign = Campaign(
|
|
83
|
+
id=Identifier("campaign--8e2e2d2b-17d4-4cbf-938f-98ee46b3cd3f"),
|
|
84
|
+
created=datetime.now(),
|
|
85
|
+
modified=datetime.now(),
|
|
86
|
+
name="Operation Stealth",
|
|
87
|
+
description="A sophisticated campaign targeting financial institutions",
|
|
88
|
+
objective="Financial gain through wire fraud"
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
# Export to JSON
|
|
92
|
+
json_output = campaign.model_dump_json(indent=2, exclude_none=True, by_alias=True)
|
|
93
|
+
print(json_output)
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Implemented STIX Objects
|
|
97
|
+
|
|
98
|
+
### STIX Domain Objects (SDOs)
|
|
99
|
+
- ✅ `AttackPattern` - Ways adversaries attempt to compromise targets
|
|
100
|
+
- ✅ `Campaign` - Grouping of adversarial behaviors over time
|
|
101
|
+
- 🚧 `Course of Action` - Action taken to prevent or respond to an attack
|
|
102
|
+
- 🚧 `Grouping` - Explicitly asserts that STIX Objects have a shared context
|
|
103
|
+
- 🚧 `Identity` - Actual individuals, organizations, or groups
|
|
104
|
+
- 🚧 `Incident` - A stub object representing a security incident
|
|
105
|
+
- 🚧 `Indicator` - Pattern that can be used to detect suspicious or malicious activity
|
|
106
|
+
- 🚧 `Infrastructure` - Systems, software services, and associated resources
|
|
107
|
+
- 🚧 `Intrusion Set` - A grouped set of adversarial behaviors and resources
|
|
108
|
+
- 🚧 `Location` - A geographic location
|
|
109
|
+
- 🚧 `Malware` - A type of TTP that represents malicious code
|
|
110
|
+
- 🚧 `Malware Analysis` - The results of a malware analysis
|
|
111
|
+
- 🚧 `Note` - Analyst-created content and context
|
|
112
|
+
- 🚧 `Observed Data` - Information about cyber security related entities
|
|
113
|
+
- 🚧 `Opinion` - An assessment of the correctness of a STIX Object
|
|
114
|
+
- 🚧 `Report` - Collections of threat intelligence
|
|
115
|
+
- 🚧 `Threat Actor` - Actual individuals, groups, or organizations
|
|
116
|
+
- 🚧 `Tool` - Legitimate software that can be used by threat actors
|
|
117
|
+
- 🚧 `Vulnerability` - A mistake in software that can be used to compromise a system
|
|
118
|
+
|
|
119
|
+
### STIX Cyber-observable Objects (SCOs)
|
|
120
|
+
- ✅ `Artifact` - Binary or file-like objects
|
|
121
|
+
- ✅ `AutonomousSystem` - Autonomous System (AS) information
|
|
122
|
+
- 🚧 `Directory` - A directory on a file system
|
|
123
|
+
- 🚧 `Domain Name` - A network domain name
|
|
124
|
+
- 🚧 `Email Address` - An email address
|
|
125
|
+
- 🚧 `Email Message` - An email message
|
|
126
|
+
- 🚧 `File` - A computer file
|
|
127
|
+
- 🚧 `IPv4 Address` - An IPv4 address
|
|
128
|
+
- 🚧 `IPv6 Address` - An IPv6 address
|
|
129
|
+
- 🚧 `MAC Address` - A Media Access Control (MAC) address
|
|
130
|
+
- 🚧 `Mutex` - A mutual exclusion object
|
|
131
|
+
- 🚧 `Network Traffic` - A network traffic flow
|
|
132
|
+
- 🚧 `Process` - A running process
|
|
133
|
+
- 🚧 `Software` - A software product
|
|
134
|
+
- 🚧 `URL` - A Uniform Resource Locator (URL)
|
|
135
|
+
- 🚧 `User Account` - A user account on a system
|
|
136
|
+
- 🚧 `Windows Registry Key` - A key in the Windows registry
|
|
137
|
+
- 🚧 `X.509 Certificate` - An X.509 certificate
|
|
138
|
+
|
|
139
|
+
### STIX Relationship Objects (SROs)
|
|
140
|
+
- ✅ `Relationship` - Connections between STIX objects
|
|
141
|
+
- ✅ `Sighting` - Observations of threat intelligence in the wild
|
|
142
|
+
|
|
143
|
+
### Meta Objects
|
|
144
|
+
- ✅ `MarkingDefinition` - Data markings (includes TLP)
|
|
145
|
+
- ✅ `LanguageContent` - Translations and internationalization
|
|
146
|
+
- ✅ `ExtensionDefinition` - Custom STIX extensions
|
|
147
|
+
|
|
148
|
+
### Bundle
|
|
149
|
+
- ✅ `StixBundle` - Container for STIX objects
|
|
150
|
+
|
|
151
|
+
## Roadmap
|
|
152
|
+
|
|
153
|
+
- **Full STIX 2.1 Compliance**
|
|
154
|
+
- **Python packaging**
|
|
155
|
+
- **Extensive Testing**
|
|
156
|
+
- Better STIX Extension Support: Develop a robust and user-friendly mechanism for defining, parsing, and validating custom STIX extensions.
|
|
157
|
+
- TAXII 2.1 Server: Build a TAXII 2.1 compliant server using FastAPI.
|
|
158
|
+
- OCA Standard Extensions: Implement STIX extensions from the [Open Cybersecurity Alliance (OCA)](https://github.com/opencybersecurityalliance/stix-extensions) repository.
|
|
159
|
+
- Performance Tuning: Profile and optimize parsing and serialization.
|
|
160
|
+
|
|
161
|
+
## Resources
|
|
162
|
+
|
|
163
|
+
- [STIX 2.1 Specification](https://docs.oasis-open.org/cti/stix/v2.1/stix-v2.1.html)
|
|
164
|
+
- [STIX 2.1 Introduction](https://oasis-open.github.io/cti-documentation/stix/intro)
|
|
165
|
+
- [Pydantic Documentation](https://docs.pydantic.dev/)
|
|
166
|
+
|
|
167
|
+
## License
|
|
168
|
+
|
|
169
|
+
stidantic is released under the [MIT License](https://opensource.org/licenses/MIT).
|
|
170
|
+
|
|
171
|
+
## Acknowledgments
|
|
172
|
+
|
|
173
|
+
This project implements the STIX 2.1 specification published by the OASIS Cyber Threat Intelligence (CTI) Technical Committee.
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# stidantic [WIP]
|
|
2
|
+
|
|
3
|
+
**This is work in progress, not compliant yet.**
|
|
4
|
+
|
|
5
|
+
A Pydantic-based Python library for parsing, validating, and creating STIX 2.1 cyber threat intelligence data.
|
|
6
|
+
|
|
7
|
+
[](https://www.python.org/downloads/)
|
|
8
|
+
[](https://docs.pydantic.dev/)
|
|
9
|
+
|
|
10
|
+
## Overview
|
|
11
|
+
|
|
12
|
+
**stidantic** provides a type-safe, Pythonic way to work with [STIX 2.1](https://oasis-open.github.io/cti-documentation/stix/intro) (Structured Threat Information Expression) objects.
|
|
13
|
+
|
|
14
|
+
This library leverages [Pydantic](https://docs.pydantic.dev/) to provide:
|
|
15
|
+
|
|
16
|
+
- 🔒 **Strong type validation** for all STIX objects
|
|
17
|
+
- 📝 **IDE auto-completion** and type hints
|
|
18
|
+
- ✅ **Automatic validation** of STIX specification constraints
|
|
19
|
+
- 🔄 **Easy JSON serialization/deserialization**
|
|
20
|
+
- ❄️ **Immutable models** with frozen Pydantic configurations
|
|
21
|
+
- 🎯 **Discriminated unions** for polymorphic STIX object handling
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
### Requirements
|
|
26
|
+
|
|
27
|
+
- Python 3.12 or later (uses PEP 695 type statements)
|
|
28
|
+
- Pydantic > 2.10
|
|
29
|
+
|
|
30
|
+
## Quick Start
|
|
31
|
+
|
|
32
|
+
### Parsing a STIX Bundle
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from stidantic.bundle import StixBundle
|
|
36
|
+
|
|
37
|
+
# Load from JSON file
|
|
38
|
+
with open("threat_data.json", "r") as f:
|
|
39
|
+
bundle = StixBundle.model_validate_json(f.read())
|
|
40
|
+
|
|
41
|
+
# Access objects
|
|
42
|
+
print(f"Bundle contains {len(bundle.objects)} objects")
|
|
43
|
+
for obj in bundle.objects:
|
|
44
|
+
print(f"- {obj.type}: {obj.id}")
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Creating STIX Objects
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
from datetime import datetime
|
|
51
|
+
from stidantic.sdo import Campaign
|
|
52
|
+
from stidantic.types import Identifier
|
|
53
|
+
|
|
54
|
+
campaign = Campaign(
|
|
55
|
+
id=Identifier("campaign--8e2e2d2b-17d4-4cbf-938f-98ee46b3cd3f"),
|
|
56
|
+
created=datetime.now(),
|
|
57
|
+
modified=datetime.now(),
|
|
58
|
+
name="Operation Stealth",
|
|
59
|
+
description="A sophisticated campaign targeting financial institutions",
|
|
60
|
+
objective="Financial gain through wire fraud"
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
# Export to JSON
|
|
64
|
+
json_output = campaign.model_dump_json(indent=2, exclude_none=True, by_alias=True)
|
|
65
|
+
print(json_output)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Implemented STIX Objects
|
|
69
|
+
|
|
70
|
+
### STIX Domain Objects (SDOs)
|
|
71
|
+
- ✅ `AttackPattern` - Ways adversaries attempt to compromise targets
|
|
72
|
+
- ✅ `Campaign` - Grouping of adversarial behaviors over time
|
|
73
|
+
- 🚧 `Course of Action` - Action taken to prevent or respond to an attack
|
|
74
|
+
- 🚧 `Grouping` - Explicitly asserts that STIX Objects have a shared context
|
|
75
|
+
- 🚧 `Identity` - Actual individuals, organizations, or groups
|
|
76
|
+
- 🚧 `Incident` - A stub object representing a security incident
|
|
77
|
+
- 🚧 `Indicator` - Pattern that can be used to detect suspicious or malicious activity
|
|
78
|
+
- 🚧 `Infrastructure` - Systems, software services, and associated resources
|
|
79
|
+
- 🚧 `Intrusion Set` - A grouped set of adversarial behaviors and resources
|
|
80
|
+
- 🚧 `Location` - A geographic location
|
|
81
|
+
- 🚧 `Malware` - A type of TTP that represents malicious code
|
|
82
|
+
- 🚧 `Malware Analysis` - The results of a malware analysis
|
|
83
|
+
- 🚧 `Note` - Analyst-created content and context
|
|
84
|
+
- 🚧 `Observed Data` - Information about cyber security related entities
|
|
85
|
+
- 🚧 `Opinion` - An assessment of the correctness of a STIX Object
|
|
86
|
+
- 🚧 `Report` - Collections of threat intelligence
|
|
87
|
+
- 🚧 `Threat Actor` - Actual individuals, groups, or organizations
|
|
88
|
+
- 🚧 `Tool` - Legitimate software that can be used by threat actors
|
|
89
|
+
- 🚧 `Vulnerability` - A mistake in software that can be used to compromise a system
|
|
90
|
+
|
|
91
|
+
### STIX Cyber-observable Objects (SCOs)
|
|
92
|
+
- ✅ `Artifact` - Binary or file-like objects
|
|
93
|
+
- ✅ `AutonomousSystem` - Autonomous System (AS) information
|
|
94
|
+
- 🚧 `Directory` - A directory on a file system
|
|
95
|
+
- 🚧 `Domain Name` - A network domain name
|
|
96
|
+
- 🚧 `Email Address` - An email address
|
|
97
|
+
- 🚧 `Email Message` - An email message
|
|
98
|
+
- 🚧 `File` - A computer file
|
|
99
|
+
- 🚧 `IPv4 Address` - An IPv4 address
|
|
100
|
+
- 🚧 `IPv6 Address` - An IPv6 address
|
|
101
|
+
- 🚧 `MAC Address` - A Media Access Control (MAC) address
|
|
102
|
+
- 🚧 `Mutex` - A mutual exclusion object
|
|
103
|
+
- 🚧 `Network Traffic` - A network traffic flow
|
|
104
|
+
- 🚧 `Process` - A running process
|
|
105
|
+
- 🚧 `Software` - A software product
|
|
106
|
+
- 🚧 `URL` - A Uniform Resource Locator (URL)
|
|
107
|
+
- 🚧 `User Account` - A user account on a system
|
|
108
|
+
- 🚧 `Windows Registry Key` - A key in the Windows registry
|
|
109
|
+
- 🚧 `X.509 Certificate` - An X.509 certificate
|
|
110
|
+
|
|
111
|
+
### STIX Relationship Objects (SROs)
|
|
112
|
+
- ✅ `Relationship` - Connections between STIX objects
|
|
113
|
+
- ✅ `Sighting` - Observations of threat intelligence in the wild
|
|
114
|
+
|
|
115
|
+
### Meta Objects
|
|
116
|
+
- ✅ `MarkingDefinition` - Data markings (includes TLP)
|
|
117
|
+
- ✅ `LanguageContent` - Translations and internationalization
|
|
118
|
+
- ✅ `ExtensionDefinition` - Custom STIX extensions
|
|
119
|
+
|
|
120
|
+
### Bundle
|
|
121
|
+
- ✅ `StixBundle` - Container for STIX objects
|
|
122
|
+
|
|
123
|
+
## Roadmap
|
|
124
|
+
|
|
125
|
+
- **Full STIX 2.1 Compliance**
|
|
126
|
+
- **Python packaging**
|
|
127
|
+
- **Extensive Testing**
|
|
128
|
+
- Better STIX Extension Support: Develop a robust and user-friendly mechanism for defining, parsing, and validating custom STIX extensions.
|
|
129
|
+
- TAXII 2.1 Server: Build a TAXII 2.1 compliant server using FastAPI.
|
|
130
|
+
- OCA Standard Extensions: Implement STIX extensions from the [Open Cybersecurity Alliance (OCA)](https://github.com/opencybersecurityalliance/stix-extensions) repository.
|
|
131
|
+
- Performance Tuning: Profile and optimize parsing and serialization.
|
|
132
|
+
|
|
133
|
+
## Resources
|
|
134
|
+
|
|
135
|
+
- [STIX 2.1 Specification](https://docs.oasis-open.org/cti/stix/v2.1/stix-v2.1.html)
|
|
136
|
+
- [STIX 2.1 Introduction](https://oasis-open.github.io/cti-documentation/stix/intro)
|
|
137
|
+
- [Pydantic Documentation](https://docs.pydantic.dev/)
|
|
138
|
+
|
|
139
|
+
## License
|
|
140
|
+
|
|
141
|
+
stidantic is released under the [MIT License](https://opensource.org/licenses/MIT).
|
|
142
|
+
|
|
143
|
+
## Acknowledgments
|
|
144
|
+
|
|
145
|
+
This project implements the STIX 2.1 specification published by the OASIS Cyber Threat Intelligence (CTI) Technical Committee.
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "stidantic"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "A Pydantic-based Python library for parsing, validating, and creating STIX 2.1 cyber threat intelligence data"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.12"
|
|
11
|
+
license = {text = "MIT"}
|
|
12
|
+
authors = [
|
|
13
|
+
{name = "nicocti", email = "your.email@example.com"},
|
|
14
|
+
]
|
|
15
|
+
maintainers = [
|
|
16
|
+
{name = "nicocti", email = "your.email@example.com"},
|
|
17
|
+
]
|
|
18
|
+
keywords = [
|
|
19
|
+
"stix",
|
|
20
|
+
"stix2",
|
|
21
|
+
"stix2.1",
|
|
22
|
+
"cti",
|
|
23
|
+
"pydantic",
|
|
24
|
+
]
|
|
25
|
+
classifiers = [
|
|
26
|
+
"Development Status :: 3 - Alpha",
|
|
27
|
+
"Intended Audience :: Developers",
|
|
28
|
+
"Intended Audience :: Information Technology",
|
|
29
|
+
"License :: OSI Approved :: MIT License",
|
|
30
|
+
"Operating System :: OS Independent",
|
|
31
|
+
"Programming Language :: Python :: 3",
|
|
32
|
+
"Programming Language :: Python :: 3.12",
|
|
33
|
+
"Programming Language :: Python :: 3.13",
|
|
34
|
+
"Topic :: Security",
|
|
35
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
36
|
+
"Typing :: Typed",
|
|
37
|
+
]
|
|
38
|
+
dependencies = [
|
|
39
|
+
"pydantic>=2.12",
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
[project.urls]
|
|
43
|
+
Homepage = "https://github.com/nicocti/stidantic"
|
|
44
|
+
Repository = "https://github.com/nicocti/stidantic"
|
|
45
|
+
Issues = "https://github.com/nicocti/stidantic/issues"
|
|
46
|
+
Documentation = "https://github.com/nicocti/stidantic#readme"
|
|
47
|
+
|
|
48
|
+
[tool.hatch.build.targets.wheel]
|
|
49
|
+
packages = ["stidantic"]
|
|
50
|
+
|
|
51
|
+
[tool.hatch.build.targets.sdist]
|
|
52
|
+
include = [
|
|
53
|
+
"/stidantic",
|
|
54
|
+
"/README.md",
|
|
55
|
+
"/LICENSE",
|
|
56
|
+
]
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""stidantic - A Pydantic-based STIX 2.1 library."""
|
|
2
|
+
|
|
3
|
+
__version__ = "0.1.0"
|
|
4
|
+
__author__ = "nicocti"
|
|
5
|
+
__all__ = [
|
|
6
|
+
"StixBundle",
|
|
7
|
+
"StixCore",
|
|
8
|
+
"StixCommon",
|
|
9
|
+
"StixDomain",
|
|
10
|
+
"StixRelationship",
|
|
11
|
+
"StixMeta",
|
|
12
|
+
"Identifier",
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
from stidantic.bundle import StixBundle
|
|
16
|
+
from stidantic.types import (
|
|
17
|
+
Identifier,
|
|
18
|
+
StixCommon,
|
|
19
|
+
StixCore,
|
|
20
|
+
StixDomain,
|
|
21
|
+
StixMeta,
|
|
22
|
+
StixRelationship,
|
|
23
|
+
)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"""Type stubs for stidantic."""
|
|
2
|
+
|
|
3
|
+
from stidantic.bundle import StixBundle as StixBundle
|
|
4
|
+
from stidantic.types import (
|
|
5
|
+
Identifier as Identifier,
|
|
6
|
+
StixCommon as StixCommon,
|
|
7
|
+
StixCore as StixCore,
|
|
8
|
+
StixDomain as StixDomain,
|
|
9
|
+
StixMeta as StixMeta,
|
|
10
|
+
StixRelationship as StixRelationship,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
__version__: str
|
|
14
|
+
__author__: str
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from typing import Annotated
|
|
2
|
+
from pydantic import Field
|
|
3
|
+
from stidantic.types import StixCore, Identifier, StixCommon
|
|
4
|
+
from stidantic.sdo import SDOs
|
|
5
|
+
from stidantic.sco import SCOs
|
|
6
|
+
from stidantic.sro import SROs
|
|
7
|
+
from stidantic.language import LanguageContent
|
|
8
|
+
from stidantic.marking import MarkingDefinition
|
|
9
|
+
from stidantic.extension import ExtensionDefinition
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
# 8. Stix Bundle
|
|
13
|
+
class StixBundle(StixCore):
|
|
14
|
+
id: Identifier
|
|
15
|
+
type: str = "bundle"
|
|
16
|
+
objects: list[
|
|
17
|
+
Annotated[
|
|
18
|
+
(
|
|
19
|
+
SROs
|
|
20
|
+
| SDOs
|
|
21
|
+
| SCOs
|
|
22
|
+
| MarkingDefinition
|
|
23
|
+
| LanguageContent
|
|
24
|
+
| ExtensionDefinition
|
|
25
|
+
),
|
|
26
|
+
Field(discriminator="type"),
|
|
27
|
+
]
|
|
28
|
+
| StixCommon
|
|
29
|
+
]
|