stix-rs
A complete, production-ready Rust implementation of STIX 2.1 (Structured Threat Information Expression)
stix-rs provides full support for creating, parsing, and manipulating STIX 2.1 cyber threat intelligence data. Built for performance and type safety, it's ready for use in threat intelligence platforms, TAXII servers, and security tools.
Features
100% STIX 2.1 Compliant
- ✅ All 18 STIX Domain Objects (SDOs) - Malware, Indicator, ThreatActor, Campaign, etc.
- ✅ All 17 Cyber Observable Objects (SCOs) - File, Network Traffic, Process, etc.
- ✅ All Relationship Objects (SROs) - Relationship, Sighting
- ✅ All Meta Objects - Bundle, Marking Definition, Language Content, etc.
- ✅ 17 Vocabulary Enums - Complete type-safe enumerations
Production-Ready Features
- 🔍 Bundle Query Helpers - Powerful search and filter APIs
- ✅ ID Validation - Prevent invalid STIX references
- 📡 MIME Type Constants - Standard HTTP/TAXII content types
- 🔄 Object Versioning - Proper STIX object update handling
- 🎨 Pattern Validation - STIX pattern language syntax checking
- 📦 Builder Pattern - Ergonomic object construction
🛡️ Type-Safe & Fast
- Full Rust type safety with no runtime overhead
- Comprehensive error handling with
thiserror - Efficient serialization/deserialization with
serde - Zero-copy parsing where possible
Installation
Add to your Cargo.toml:
[]
= "0.1.0"
= { = "1.0", = ["derive"] }
= "1.0"
= "0.4"
Quick Start
Creating STIX Objects
use *;
use Utc;
Working with Bundles
use *;
// Load a bundle from JSON
let bundle: Bundle = from_str?;
// Query by type
let all_malware = bundle.malware;
let all_indicators = bundle.indicators;
let all_threats = bundle.threat_actors;
// Find by ID
if let Some = bundle.get
// Filter generically
let identities = bundle.filter_by_type;
// Count objects
println!;
println!;
// Find references
let refs = bundle.find_references_to;
// Iterate
for obj in bundle.iter
Common Properties & Marking
use *;
let mut malware = builder
.name
.malware_types
.build?;
// Add common properties
malware.common.labels = Some;
malware.common.confidence = Some;
malware.common.lang = Some;
// Add external references (CVE, ATT&CK)
malware.common.external_references = Some;
// Add TLP marking
let tlp_red = tlp;
malware.common.object_marking_refs = Some;
Pattern Validation
use ;
// Validate patterns
validate_pattern?;
validate_pattern?;
// Build patterns programmatically
let pattern = new
.compare
.and
.compare
.build;
println!;
// Output: [file:name = 'malware.exe' AND file:size > 1000]
ID Validation
use *;
// Validate STIX IDs
assert!;
assert!;
// Extract type from ID
let obj_type = extract_type_from_id;
assert_eq!;
// Validate reference types
assert!;
Object Versioning
use *;
let mut threat_actor = builder
.name
.threat_actor_types
.build?;
// Make updates
threat_actor.description = Some;
// Create new version (updates modified timestamp, preserves ID)
threat_actor.common.new_version;
🌐 HTTP/TAXII Integration
MIME Type Constants
use *;
// Use standard STIX/TAXII MIME types
println!; // application/stix+json;version=2.1
println!; // application/taxii+json;version=2.1
Example TAXII Server (Axum)
use ;
use *;
async
async
Complete Object Support
Domain Objects (SDOs)
| Object | Builder | Tests | Fields |
|---|---|---|---|
| Attack Pattern | ✅ | ✅ | Complete |
| Campaign | ✅ | ✅ | Complete |
| Course of Action | ✅ | ✅ | Complete |
| Grouping | ✅ | ✅ | Complete |
| Identity | ✅ | ✅ | Complete |
| Incident | ✅ | ✅ | Complete |
| Indicator | ✅ | ✅ | Complete + Validation |
| Infrastructure | ✅ | ✅ | Complete |
| Intrusion Set | ✅ | ✅ | Complete |
| Location | ✅ | ✅ | Complete |
| Malware | ✅ | ✅ | Complete + Extended |
| Malware Analysis | ✅ | ✅ | Complete |
| Note | ✅ | ✅ | Complete |
| Observed Data | ✅ | ✅ | Complete |
| Opinion | ✅ | ✅ | Complete |
| Report | ✅ | ✅ | Complete |
| Threat Actor | ✅ | ✅ | Complete |
| Tool | ✅ | ✅ | Complete |
| Vulnerability | ✅ | ✅ | Complete |
Cyber Observables (SCOs)
| Object | Support |
|---|---|
| Artifact | ✅ |
| Autonomous System | ✅ |
| Directory | ✅ |
| Domain Name | ✅ |
| Email Address | ✅ |
| Email Message | ✅ |
| File | ✅ |
| IPv4 Address | ✅ |
| IPv6 Address | ✅ |
| MAC Address | ✅ |
| Mutex | ✅ |
| Network Traffic | ✅ |
| Process | ✅ |
| Software | ✅ |
| URL | ✅ |
| User Account | ✅ |
| Windows Registry Key | ✅ |
| X.509 Certificate | ✅ |
Relationship Objects (SROs)
| Object | Support |
|---|---|
| Relationship | ✅ |
| Sighting | ✅ |
Meta Objects
| Object | Support |
|---|---|
| Bundle | ✅ + Query Helpers |
| Marking Definition | ✅ + TLP Support |
| Language Content | ✅ |
| Extension Definition | ✅ |
| External Reference | ✅ + Builder |
| Granular Marking | ✅ |
Vocabulary Enums
All STIX 2.1 open vocabularies are implemented as type-safe enums:
MalwareType- ransomware, trojan, backdoor, etc. (20 types)ThreatActorType- nation-state, criminal, hacktivist, etc. (12 types)ThreatActorRole- director, agent, sponsor, etc. (5 roles)ThreatActorSophistication- minimal, intermediate, advanced, etc. (7 levels)AttackMotivation- ideology, dominance, personal-gain, etc. (10 types)AttackResourceLevel- individual, club, organization, government (6 levels)ToolType- exploitation, remote-access, etc. (8 types)InfrastructureType- command-and-control, botnet, etc. (11 types)ReportType- threat-report, attack-pattern, etc. (11 types)IndustrySector- financial, healthcare, government, etc. (40+ sectors)IndicatorType- malicious-activity, anomalous-activity, etc.ImplementationLanguage- Python, C++, JavaScript, etc. (20+ languages)IndicatorPatternType- stix, pcre, snort, yara, suricataIdentityClass- individual, group, organization, systemHashAlgorithm- MD5, SHA-1, SHA-256, SHA-512RelationshipType- targets, uses, indicates, etc.EncryptionAlgorithm- AES-256-GCM, ChaCha20-Poly1305
🧪 Testing
# Run all tests
# Run with output
# Run specific test
# Check for compilation issues
# Build release
Test Coverage: 78 tests passing (57 unit + 21 integration/doc tests)
Documentation
- Official STIX 2.1 Spec - OASIS specification
- STIX 2.1 Examples - Official examples
Generate API Docs
Use Cases
Threat Intelligence Platforms
Query and analyze threat data with type-safe APIs:
let apt_malware: = bundle.malware
.iter
.filter
.collect;
TAXII 2.1 Servers
Serve STIX bundles with proper MIME types:
response.header;
Security Orchestration (SOAR)
Parse and create STIX indicators programmatically:
let indicator = builder
.pattern
.valid_from
.build?;
Threat Feed Aggregators
Merge multiple STIX feeds efficiently:
let mut combined = new;
combined.objects.extend;
combined.objects.extend;
Intelligence Sharing
Exchange standardized threat intelligence:
let bundle = new;
Advanced Features
Custom Properties
let identity = builder
.name
.class
.property
.property
.build?;
Extensions
let extension = builder
.name
.version
.schema
.extension_types
.build?;
Granular Markings
malware.common.granular_markings = Some;
Development
# Clone the repository
# Run tests
# Check formatting
# Run clippy
# Build docs
📝 License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- OASIS CTI Technical Committee - STIX specification