| Crates.io | rust-threat-detector |
| lib.rs | rust-threat-detector |
| version | 2.0.0 |
| created_at | 2025-11-18 05:31:15.362661+00 |
| updated_at | 2025-12-11 08:21:01.272783+00 |
| description | Advanced memory-safe SIEM threat detection with ML-based scoring, automated incident response, and threat hunting capabilities |
| homepage | |
| repository | https://github.com/guardsarm/rust-threat-detector |
| max_upload_size | |
| id | 1937922 |
| size | 239,712 |
A memory-safe SIEM threat detection component for real-time security monitoring and threat analysis. Built with Rust to eliminate vulnerabilities in security monitoring systems.
Eliminates memory safety vulnerabilities in security tools themselves. Aligns with 2024 CISA/FBI guidance for memory-safe security infrastructure.
Behavioral Analytics (UEBA) - User and Entity Behavior Analytics for anomaly detection
Threat Intelligence - IOC (Indicators of Compromise) matching
Statistical Anomaly Detection - Machine learning-based anomaly detection
MITRE ATT&CK Framework - 10+ technique detection patterns
Add to your Cargo.toml:
[dependencies]
rust-threat-detector = "0.1.0"
use rust_threat_detector::{ThreatDetector, LogEntry};
use chrono::Utc;
use std::collections::HashMap;
let mut detector = ThreatDetector::new();
let log = LogEntry {
timestamp: Utc::now(),
source_ip: Some("192.168.1.100".to_string()),
user: Some("admin".to_string()),
event_type: "authentication".to_string(),
message: "Failed login attempt for user admin".to_string(),
metadata: HashMap::new(),
};
let alerts = detector.analyze(&log);
for alert in alerts {
println!("ALERT: {}", alert.description);
println!("Severity: {:?}", alert.severity);
println!("Action: {}", alert.recommended_action);
}
Detect anomalous user behavior patterns:
use rust_threat_detector::{BehavioralAnalytics, LogEntry};
use chrono::Utc;
let mut analytics = BehavioralAnalytics::new(50.0); // 50.0 = anomaly threshold
// Establish baseline with normal user activity
for _ in 0..10 {
let log = LogEntry {
timestamp: Utc::now(),
source_ip: Some("192.168.1.100".to_string()),
user: Some("alice".to_string()),
event_type: "login".to_string(),
message: "User login successful".to_string(),
metadata: HashMap::new(),
};
analytics.analyze(&log);
}
// Detect anomaly - login from unusual IP
let suspicious_log = LogEntry {
timestamp: Utc::now(),
source_ip: Some("1.2.3.4".to_string()), // Unusual IP
user: Some("alice".to_string()),
event_type: "login".to_string(),
message: "User login successful".to_string(),
metadata: HashMap::new(),
};
if let Some(alert) = analytics.analyze(&suspicious_log) {
println!("UEBA Alert: {}", alert.description);
println!("Anomaly Score: {}", alert.threat_score);
}
Match logs against known malicious indicators:
use rust_threat_detector::{ThreatIntelligence, IOC, IOCType, ThreatSeverity};
use chrono::Utc;
let mut intel = ThreatIntelligence::new();
// Add custom IOCs
intel.add_ioc(IOC {
ioc_type: IOCType::IPAddress,
value: "198.51.100.1".to_string(),
severity: ThreatSeverity::Critical,
description: "Known C2 server".to_string(),
source: "ThreatFeed-2025".to_string(),
first_seen: Utc::now(),
last_seen: Utc::now(),
confidence: 0.95,
});
// Check log for IOC matches
let log = LogEntry {
timestamp: Utc::now(),
source_ip: Some("198.51.100.1".to_string()), // Matches IOC
user: Some("admin".to_string()),
event_type: "connection".to_string(),
message: "Outbound connection established".to_string(),
metadata: HashMap::new(),
};
let alerts = intel.check_log(&log);
for alert in alerts {
println!("IOC Match: {} (confidence: {:.0}%)",
alert.description,
alert.threat_score);
}
Detect statistical anomalies in metrics:
use rust_threat_detector::{AnomalyDetector, DetectionMethod};
use chrono::Utc;
let mut detector = AnomalyDetector::new();
// Track baseline metrics
for i in 0..100 {
detector.track_metric("requests_per_second", 100.0 + i as f64, Utc::now());
}
// Detect anomaly using Z-score method
if let Some(anomaly) = detector.detect(
"requests_per_second",
10000.0, // Anomalous value
DetectionMethod::ZScore
) {
println!("Statistical Anomaly: {}", anomaly.description);
println!("Expected: {:.2}, Got: {:.2}",
anomaly.expected_value,
anomaly.current_value);
}
Export alerts to multiple SIEM formats:
use rust_threat_detector::{SIEMExporter, SIEMFormat};
let exporter = SIEMExporter::new_default();
// Export to CEF (ArcSight)
let cef = exporter.export(&alert, SIEMFormat::CEF);
send_to_arcsight(&cef);
// Export to LEEF (QRadar)
let leef = exporter.export(&alert, SIEMFormat::LEEF);
send_to_qradar(&leef);
// Export to JSON (Splunk)
let json = exporter.export(&alert, SIEMFormat::JSON);
send_to_splunk(&json);
// Batch export to CSV
let batch_exporter = BatchExporter::new(SIEMFormat::CSV);
batch_exporter.export_to_file(&alerts, "threat_report.csv")?;
Detect MITRE ATT&CK techniques:
use rust_threat_detector::{MitreAttackDetector, AttackTactic};
let mut detector = MitreAttackDetector::new();
let log = LogEntry {
timestamp: Utc::now(),
source_ip: Some("192.168.1.50".to_string()),
user: Some("admin".to_string()),
event_type: "process".to_string(),
message: "mimikatz.exe detected in process list".to_string(),
metadata: HashMap::new(),
};
let detections = detector.analyze(&log);
for detection in detections {
println!("MITRE Technique: {}", detection.technique.name);
println!("Tactic: {:?}", detection.technique.tactic);
println!("ID: {}", detection.technique.id);
}
Pattern: Failed login attempts
Severity: High
Indicators: Multiple authentication failures
Pattern: Malware signatures
Severity: Critical
Indicators: Virus, trojan, ransomware keywords
Pattern: Large data transfers
Severity: High
Indicators: Unusual download patterns
Pattern: Unauthorized access attempts
Severity: Critical
Indicators: Sudo, admin access attempts
Pattern: SQL injection attempts
Severity: Critical
Indicators: Union select, drop table, SQL keywords
Pattern: Suspicious IP addresses
Severity: Medium
Indicators: Unusual source IPs
Add organization-specific patterns:
use rust_threat_detector::{ThreatDetector, ThreatPattern, ThreatCategory, ThreatSeverity};
use regex::Regex;
let mut detector = ThreatDetector::new();
detector.add_pattern(ThreatPattern {
name: "Sensitive File Access".to_string(),
category: ThreatCategory::PolicyViolation,
severity: ThreatSeverity::High,
pattern: Regex::new(r"access to /etc/shadow").unwrap(),
description: "Unauthorized access to sensitive file".to_string(),
recommended_action: "Investigate user, review file permissions".to_string(),
});
let critical_alerts = detector.filter_by_severity(&alerts, ThreatSeverity::Critical);
for alert in critical_alerts {
// Handle critical alerts immediately
send_to_soc(&alert);
}
for alert in alerts {
let json = alert.to_json().unwrap();
send_to_siem(&json);
}
Traditional C/C++ SIEM tools are vulnerable to:
This implementation eliminates these vulnerabilities through Rust's ownership system.
See the examples/ directory:
cargo run --example detect_threats
cargo test
The threat detector provides native support for all major SIEM platforms through multiple export formats:
use rust_threat_detector::{SIEMExporter, SIEMFormat};
let exporter = SIEMExporter::new_default();
let cef_output = exporter.export(&alert, SIEMFormat::CEF);
// Output: CEF:0|GuardsArm|RustThreatDetector|1.0|BruteForce|...
// Send to ArcSight SmartConnector via syslog
send_via_syslog(&cef_output);
let leef_output = exporter.export(&alert, SIEMFormat::LEEF);
// Output: LEEF:2.0|GuardsArm|RustThreatDetector|1.0|BruteForce|...
// Send to QRadar Event Collector
send_to_qradar(&leef_output);
let json_output = exporter.export(&alert, SIEMFormat::JSON);
// Send to Splunk HTTP Event Collector
post_to_splunk_hec(&json_output);
// Or index in Elasticsearch
index_in_elasticsearch(&json_output);
let syslog_output = exporter.export(&alert, SIEMFormat::Syslog);
// Compatible with any syslog receiver
send_via_syslog(&syslog_output);
use rust_threat_detector::BatchExporter;
let batch_exporter = BatchExporter::new(SIEMFormat::CSV);
batch_exporter.export_to_file(&alerts, "daily_threats.csv")?;
// Generate reports for analysis or compliance
This detector implements requirements from:
Designed for:
Traditional C/C++ SIEM components commonly suffer from:
This Rust implementation eliminates these vulnerability classes entirely through compile-time memory safety guarantees, while maintaining comparable or superior performance.
MIT License - See LICENSE file
Tony Chuks Awunor
Contributions welcome! Please open an issue or pull request with:
If you use this detector in research or production systems, please cite:
Awunor, T.C. (2024). Rust Threat Detector: Memory-Safe SIEM Threat Detection.
https://github.com/guardsarm/rust-threat-detector
Built for security operations. Designed for memory safety. Implemented in Rust.