threat-intel 0.1.0

Comprehensive threat intelligence framework with multi-source aggregation, CVE integration, and risk assessment
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
# Use Cases

Real-world applications and scenarios for Threat Intel.

## 1. SIEM Integration

### Scenario: Security Information and Event Management

Enrich security events with threat intelligence for better detection and response.

**Implementation:**

```rust
use threat_intel::{ThreatIntelConfig, ThreatIntelEngine, IOCType};

struct SIEMIntegration {
    threat_intel: ThreatIntelEngine,
}

impl SIEMIntegration {
    async fn new() -> anyhow::Result<Self> {
        let config = ThreatIntelConfig::default();
        let mut engine = ThreatIntelEngine::new(config);
        engine.initialize().await?;
        
        Ok(Self { threat_intel: engine })
    }
    
    async fn enrich_event(&self, ip_address: &str) -> anyhow::Result<EventEnrichment> {
        // Query for IP in IOC database
        let iocs = self.threat_intel.query_iocs(IOCType::IpAddress).await?;
        
        let is_malicious = iocs.iter().any(|ioc| ioc.value == ip_address);
        
        if is_malicious {
            let ioc = iocs.iter().find(|i| i.value == ip_address).unwrap();
            Ok(EventEnrichment {
                is_threat: true,
                confidence: ioc.confidence,
                threat_type: "Malicious IP".to_string(),
                first_seen: ioc.first_seen,
                tags: ioc.tags.clone(),
            })
        } else {
            Ok(EventEnrichment::benign())
        }
    }
}

struct EventEnrichment {
    is_threat: bool,
    confidence: f32,
    threat_type: String,
    first_seen: chrono::DateTime<chrono::Utc>,
    tags: Vec<String>,
}

impl EventEnrichment {
    fn benign() -> Self {
        Self {
            is_threat: false,
            confidence: 0.0,
            threat_type: String::new(),
            first_seen: chrono::Utc::now(),
            tags: vec![],
        }
    }
}
```

**Benefits:**
- Real-time threat detection
- Reduced false positives
- Better incident prioritization
- Context for security analysts

## 2. Vulnerability Management

### Scenario: Track Software Vulnerabilities

Monitor infrastructure for known vulnerabilities.

**Implementation:**

```rust
use threat_intel::{ThreatIntelEngine, RiskLevel};

struct VulnerabilityScanner {
    threat_intel: ThreatIntelEngine,
}

impl VulnerabilityScanner {
    async fn scan_infrastructure(&self) -> anyhow::Result<ScanReport> {
        let mut report = ScanReport::new();
        
        // Scan different components
        let components = vec![
            ("apache", "2.4.41"),
            ("openssl", "1.1.1"),
            ("nginx", "1.18.0"),
        ];
        
        for (product, version) in components {
            let vulns = self.threat_intel
                .query_vulnerabilities(product, version)
                .await?;
            
            if !vulns.is_empty() {
                let assessment = self.threat_intel.assess_risk(&vulns);
                report.add_component(product, version, assessment, vulns);
            }
        }
        
        Ok(report)
    }
}

struct ScanReport {
    components: Vec<ComponentRisk>,
}

impl ScanReport {
    fn new() -> Self {
        Self { components: vec![] }
    }
    
    fn add_component(
        &mut self,
        product: &str,
        version: &str,
        assessment: threat_intel::RiskAssessment,
        vulns: Vec<threat_intel::Vulnerability>,
    ) {
        self.components.push(ComponentRisk {
            product: product.to_string(),
            version: version.to_string(),
            risk_level: assessment.level,
            vuln_count: vulns.len(),
            recommendations: assessment.recommendations,
        });
    }
}

struct ComponentRisk {
    product: String,
    version: String,
    risk_level: RiskLevel,
    vuln_count: usize,
    recommendations: Vec<String>,
}
```

**Benefits:**
- Automated vulnerability discovery
- Risk-based prioritization
- Actionable recommendations
- Continuous monitoring

## 3. SOC Operations

### Scenario: Security Operations Center Workflow

Daily threat intelligence briefings for SOC analysts.

**Implementation:**

```rust
use threat_intel::{ThreatIntelEngine};

struct SOCDashboard {
    threat_intel: ThreatIntelEngine,
}

impl SOCDashboard {
    async fn daily_briefing(&self) -> anyhow::Result<ThreatBriefing> {
        let stats = self.threat_intel.get_stats();
        
        // Get critical vulnerabilities
        let critical_threats = self.get_critical_threats().await?;
        
        // Get active threat actors
        let active_actors = self.threat_intel
            .query_threat_actors("apt")
            .await?;
        
        Ok(ThreatBriefing {
            date: chrono::Utc::now(),
            total_vulnerabilities: stats.total_vulnerabilities,
            total_iocs: stats.total_iocs,
            critical_threats,
            active_threat_actors: active_actors.len(),
            recommendations: self.generate_recommendations(),
        })
    }
    
    async fn get_critical_threats(&self) -> anyhow::Result<Vec<String>> {
        // Query recent critical vulnerabilities
        let vulns = self.threat_intel
            .query_vulnerabilities("*", "*")
            .await?;
        
        Ok(vulns.iter()
            .filter(|v| matches!(v.severity, threat_intel::Severity::Critical))
            .take(10)
            .filter_map(|v| v.cve_id.clone())
            .collect())
    }
    
    fn generate_recommendations(&self) -> Vec<String> {
        vec![
            "Review critical vulnerabilities in production systems".to_string(),
            "Update threat actor TTPs in detection rules".to_string(),
            "Validate IOC blocklists are current".to_string(),
        ]
    }
}

struct ThreatBriefing {
    date: chrono::DateTime<chrono::Utc>,
    total_vulnerabilities: usize,
    total_iocs: usize,
    critical_threats: Vec<String>,
    active_threat_actors: usize,
    recommendations: Vec<String>,
}
```

**Benefits:**
- Situational awareness
- Trend analysis
- Proactive threat hunting
- Resource allocation

## 4. Incident Response

### Scenario: Rapid Threat Correlation

Quickly correlate incidents with known threats during response.

**Implementation:**

```rust
use threat_intel::{ThreatIntelEngine, IOCType};

struct IncidentResponse {
    threat_intel: ThreatIntelEngine,
}

impl IncidentResponse {
    async fn investigate_incident(&self, incident: &Incident) -> anyhow::Result<Investigation> {
        let mut investigation = Investigation::new(incident.id.clone());
        
        // Check if IP is known malicious
        if let Some(ip) = &incident.source_ip {
            let iocs = self.threat_intel.query_iocs(IOCType::IpAddress).await?;
            if let Some(ioc) = iocs.iter().find(|i| i.value == *ip) {
                investigation.add_finding(format!(
                    "Source IP {} is known malicious (confidence: {:.0}%)",
                    ip, ioc.confidence * 100.0
                ));
            }
        }
        
        // Check if domain is suspicious
        if let Some(domain) = &incident.domain {
            let iocs = self.threat_intel.query_iocs(IOCType::Domain).await?;
            if iocs.iter().any(|i| i.value == *domain) {
                investigation.add_finding(format!(
                    "Domain {} appears in threat feeds",
                    domain
                ));
            }
        }
        
        // Check for related threat actors
        if let Some(technique) = &incident.mitre_technique {
            let actors = self.threat_intel.query_threat_actors(technique).await?;
            if !actors.is_empty() {
                investigation.add_finding(format!(
                    "Technique {} associated with {} threat actors",
                    technique, actors.len()
                ));
                for actor in actors.iter().take(3) {
                    investigation.add_actor(actor.name.clone());
                }
            }
        }
        
        Ok(investigation)
    }
}

struct Incident {
    id: String,
    source_ip: Option<String>,
    domain: Option<String>,
    mitre_technique: Option<String>,
}

struct Investigation {
    incident_id: String,
    findings: Vec<String>,
    related_actors: Vec<String>,
}

impl Investigation {
    fn new(incident_id: String) -> Self {
        Self {
            incident_id,
            findings: vec![],
            related_actors: vec![],
        }
    }
    
    fn add_finding(&mut self, finding: String) {
        self.findings.push(finding);
    }
    
    fn add_actor(&mut self, actor: String) {
        self.related_actors.push(actor);
    }
}
```

**Benefits:**
- Faster incident analysis
- Attribution insights
- Guided remediation
- Historical context

## 5. Threat Hunting

### Scenario: Proactive Threat Discovery

Hunt for threats based on latest intelligence.

**Implementation:**

```rust
use threat_intel::{ThreatIntelEngine, IOCType};

struct ThreatHunter {
    threat_intel: ThreatIntelEngine,
}

impl ThreatHunter {
    async fn hunt_campaign(&self, campaign_name: &str) -> anyhow::Result<HuntResults> {
        let mut results = HuntResults::new(campaign_name);
        
        // Get threat actors associated with campaign
        let actors = self.threat_intel
            .query_threat_actors(campaign_name)
            .await?;
        
        // Get their known IOCs
        for actor in &actors {
            let iocs = self.get_actor_iocs(&actor.name).await?;
            results.add_iocs(iocs);
            results.add_tactics(actor.tactics.clone());
            results.add_techniques(actor.techniques.clone());
        }
        
        Ok(results)
    }
    
    async fn get_actor_iocs(&self, actor_name: &str) -> anyhow::Result<Vec<String>> {
        // Query IOCs associated with this actor
        let ip_iocs = self.threat_intel.query_iocs(IOCType::IpAddress).await?;
        let domain_iocs = self.threat_intel.query_iocs(IOCType::Domain).await?;
        
        let mut iocs = Vec::new();
        
        // Filter IOCs with actor in tags
        for ioc in ip_iocs.iter().chain(domain_iocs.iter()) {
            if ioc.tags.iter().any(|tag| tag.contains(actor_name)) {
                iocs.push(ioc.value.clone());
            }
        }
        
        Ok(iocs)
    }
}

struct HuntResults {
    campaign: String,
    iocs: Vec<String>,
    tactics: Vec<String>,
    techniques: Vec<String>,
}

impl HuntResults {
    fn new(campaign: &str) -> Self {
        Self {
            campaign: campaign.to_string(),
            iocs: vec![],
            tactics: vec![],
            techniques: vec![],
        }
    }
    
    fn add_iocs(&mut self, iocs: Vec<String>) {
        self.iocs.extend(iocs);
    }
    
    fn add_tactics(&mut self, tactics: Vec<String>) {
        self.tactics.extend(tactics);
    }
    
    fn add_techniques(&mut self, techniques: Vec<String>) {
        self.techniques.extend(techniques);
    }
}
```

**Benefits:**
- Proactive defense
- Intelligence-driven hunting
- Early threat detection
- Reduced dwell time

## 6. Compliance Reporting

### Scenario: Generate Security Compliance Reports

Automated reporting for security compliance.

**Implementation:**

```rust
use threat_intel::{ThreatIntelEngine, Severity};

struct ComplianceReporter {
    threat_intel: ThreatIntelEngine,
}

impl ComplianceReporter {
    async fn generate_report(&self) -> anyhow::Result<ComplianceReport> {
        let stats = self.threat_intel.get_stats();
        
        // Get all vulnerabilities for compliance check
        let critical_vulns = self.count_by_severity(Severity::Critical).await?;
        let high_vulns = self.count_by_severity(Severity::High).await?;
        
        let compliance_status = if critical_vulns == 0 && high_vulns < 5 {
            "COMPLIANT"
        } else {
            "NON-COMPLIANT"
        };
        
        Ok(ComplianceReport {
            report_date: chrono::Utc::now(),
            status: compliance_status.to_string(),
            total_vulnerabilities: stats.total_vulnerabilities,
            critical_count: critical_vulns,
            high_count: high_vulns,
            threat_sources: stats.sources_count,
            last_update: stats.last_sync,
        })
    }
    
    async fn count_by_severity(&self, severity: Severity) -> anyhow::Result<usize> {
        let vulns = self.threat_intel.query_vulnerabilities("*", "*").await?;
        Ok(vulns.iter().filter(|v| v.severity == severity).count())
    }
}

struct ComplianceReport {
    report_date: chrono::DateTime<chrono::Utc>,
    status: String,
    total_vulnerabilities: usize,
    critical_count: usize,
    high_count: usize,
    threat_sources: usize,
    last_update: Option<chrono::DateTime<chrono::Utc>>,
}
```

**Benefits:**
- Automated compliance
- Audit trail
- Risk documentation
- Regulatory requirements

## Summary

Threat Intel is ideal for:

✅ **SIEM Integration** - Enrich security events
✅ **Vulnerability Management** - Track and prioritize vulns
✅ **SOC Operations** - Daily briefings and awareness
✅ **Incident Response** - Rapid correlation and attribution
✅ **Threat Hunting** - Proactive threat discovery
✅ **Compliance** - Automated security reporting

## Next Steps

- Review [Architecture]./architecture.md for system design
- Check [Getting Started]./getting-started.md for quick start
- See [API Reference]./api-reference.md for detailed docs
- Read [Configuration Guide]./configuration.md for advanced setup