| Crates.io | threat-intel |
| lib.rs | threat-intel |
| version | 0.1.0 |
| created_at | 2025-10-24 23:22:08.583578+00 |
| updated_at | 2025-10-24 23:22:08.583578+00 |
| description | Comprehensive threat intelligence framework with multi-source aggregation, CVE integration, and risk assessment |
| homepage | |
| repository | https://github.com/redasgard/threat-intel |
| max_upload_size | |
| id | 1899460 |
| size | 334,231 |
A comprehensive threat intelligence framework for Rust applications with multi-source aggregation, CVE integration, and risk assessment.
tracing feature[dependencies]
threat-intel = "0.1"
# With tracing support
threat-intel = { version = "0.1", features = ["tracing"] }
use threat_intel::{ThreatIntelConfig, ThreatIntelEngine};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Create config with default sources (MITRE ATT&CK, CVE, Abuse.ch)
let config = ThreatIntelConfig::default();
// Create engine
let mut engine = ThreatIntelEngine::new(config);
// Initialize (fetches from all sources)
engine.initialize().await?;
// Query for vulnerabilities
let vulns = engine.query_vulnerabilities("apache", "2.4").await?;
println!("Found {} vulnerabilities for Apache 2.4", vulns.len());
// Assess risk
let assessment = engine.assess_risk(&vulns);
println!("Risk Level: {:?}", assessment.level);
println!("Risk Score: {}", assessment.score);
for recommendation in assessment.recommendations {
println!(" - {}", recommendation);
}
// Get stats
let stats = engine.get_stats();
println!("Sources: {}", stats.sources_count);
println!("Total Vulnerabilities: {}", stats.total_vulnerabilities);
Ok(())
}
The library comes with three pre-configured sources:
Add your own threat intelligence sources:
use threat_intel::{
ThreatIntelConfig, SourceConfig, SourceType, AuthType,
UpdateFrequency, SourceCapability
};
let mut config = ThreatIntelConfig::default();
// Add custom source
let custom_source = SourceConfig {
id: "my_source".to_string(),
name: "My Threat Intel".to_string(),
source_type: SourceType::Custom,
enabled: true,
api_url: Some("https://api.example.com/threats".to_string()),
api_key: Some("your-api-key".to_string()),
auth_type: AuthType::Bearer,
update_frequency: UpdateFrequency::Hourly,
priority: 8,
capabilities: vec![
SourceCapability::Vulnerabilities,
SourceCapability::Ioc,
],
timeout_secs: 30,
retry_count: 3,
};
config.add_source(custom_source);
auth_type: AuthType::ApiKey,
api_key: Some("your-api-key".to_string()),
// Sends: X-API-Key: your-api-key
auth_type: AuthType::Bearer,
api_key: Some("your-token".to_string()),
// Sends: Authorization: Bearer your-token
auth_type: AuthType::Basic,
api_key: Some("username:password".to_string()),
// Sends: Authorization: Basic base64(username:password)
auth_type: AuthType::None,
api_key: None,
let vulns = engine.query_vulnerabilities("apache", "2.4").await?;
for vuln in vulns {
println!("CVE: {:?}", vuln.cve_id);
println!("Severity: {:?}", vuln.severity);
println!("CVSS: {:?}", vuln.cvss_score);
}
use threat_intel::IOCType;
let malicious_ips = engine.query_iocs(IOCType::IpAddress).await?;
let malicious_domains = engine.query_iocs(IOCType::Domain).await?;
let file_hashes = engine.query_iocs(IOCType::FileHash).await?;
let actors = engine.query_threat_actors("apt28").await?;
for actor in actors {
println!("Name: {}", actor.name);
println!("Aliases: {:?}", actor.aliases);
println!("Tactics: {:?}", actor.tactics);
}
let vulns = engine.query_vulnerabilities("openssl", "1.0.1").await?;
let assessment = engine.assess_risk(&vulns);
match assessment.level {
RiskLevel::Critical => println!("đ´ CRITICAL: Immediate action required!"),
RiskLevel::High => println!("đ HIGH: Address within 24-48 hours"),
RiskLevel::Medium => println!("đĄ MEDIUM: Schedule patching"),
RiskLevel::Low => println!("đĸ LOW: Include in maintenance"),
RiskLevel::Info => println!("âšī¸ INFO: No significant issues"),
}
println!("Critical: {}", assessment.critical_count);
println!("High: {}", assessment.high_count);
println!("Medium: {}", assessment.medium_count);
println!("Low: {}", assessment.low_count);
println!("Score: {:.1}", assessment.score);
config.sync_interval_hours = 6; // Sync every 6 hours
config.cache_enabled = true;
config.cache_ttl_hours = 3; // Cache expires after 3 hours
// Disable a source
config.set_source_enabled("mitre_attack", false);
// Remove a source
config.remove_source("abuse_ch");
// Get sources by capability
let vuln_sources = config.get_sources_by_capability(
SourceCapability::Vulnerabilities
);
// Force sync all sources
engine.sync().await?;
// Get last sync time
let stats = engine.get_stats();
if let Some(last_sync) = stats.last_sync {
println!("Last synced: {}", last_sync);
}
âââââââââââââââââââââââââââââââââââââââ
â ThreatIntelEngine â
â (Aggregation & Query Interface) â
âââââââââââââââââââââââââââââââââââââââ
â
âââââââââââââââŦââââââââââââââŦââââââââââââââ
âŧ âŧ âŧ âŧ
ââââââââââââ ââââââââââââ ââââââââââââ ââââââââââââ
â MITRE â â CVE â â Abuse.ch â â Custom â
â ATT&CK â â Database â â (OSINT) â â Source â
ââââââââââââ ââââââââââââ ââââââââââââ ââââââââââââ
â â â â
âââââââââââââââ´ââââââââââââââ´ââââââââââââââ
â
âŧ
ââââââââââââââââââââ
â FeedFetcher â
â (HTTP + Auth) â
ââââââââââââââââââââ
use threat_intel::ThreatIntelError;
match engine.initialize().await {
Ok(_) => println!("Initialized successfully"),
Err(e) => eprintln!("Initialization failed: {}", e),
}
// Individual source failures don't stop others
engine.sync().await?; // Continues even if one source fails
# Run tests
cargo test
# Run with tracing
cargo test --features tracing
# Run specific test
cargo test test_risk_assessment
# Run ignored network tests (requires internet)
cargo test -- --ignored
Extracted from Red Asgard, a security platform where it aggregates threat intelligence for vulnerability detection.
Licensed under the MIT License. See LICENSE for details.
Contributions welcome! Areas of interest:
To report security vulnerabilities, email hello@redasgard.com.
Do not open public GitHub issues for security bugs.