rprobe 0.9.0

A simple tool to probe a remote host http or https connection
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
// File: models.rs
// SPDX-License-Identifier: MIT OR Apache-2.0
//
// Copyright (c) 2023-2025
// - Volker Schwaberow <volker@schwaberow.de>

use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use uuid::Uuid;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ScanData {
    pub scan_id: String,
    pub timestamp: DateTime<Utc>,
    pub targets: Vec<String>,
    pub configuration: ScanConfiguration,
    pub results: Vec<HttpScanResult>,
    pub summary: ScanSummary,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ScanConfiguration {
    pub timeout: u64,
    pub workers: u32,
    pub rate_limit: u32,
    pub http_enabled: bool,
    pub https_enabled: bool,
    pub detect_all: bool,
    pub content_analysis: bool,
    pub tls_analysis: bool,
    pub comprehensive_tls: bool,
    pub screenshot: bool,
    pub plugin: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HttpScanResult {
    pub url: String,
    pub timestamp: DateTime<Utc>,
    pub status_code: Option<u16>,
    pub response_time_ms: Option<u64>,
    pub content_length: Option<u64>,
    pub headers: HashMap<String, String>,
    pub title: Option<String>,
    pub server: Option<String>,
    pub technology_detections: Vec<PluginResult>,
    pub content_findings: Vec<ContentFinding>,
    pub tls_info: Option<TlsInfo>,
    pub screenshot_path: Option<String>,
    pub error_message: Option<String>,
    pub success: bool,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PluginResult {
    pub plugin_name: String,
    pub plugin_version: String,
    pub detection_info: String,
    pub confidence: f32,
    pub category: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ContentFinding {
    pub category: String,
    pub description: String,
    pub severity: FindingSeverity,
    pub matched_text: Option<String>,
    pub context: Option<String>,
    pub location: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum FindingSeverity {
    Critical,
    High,
    Medium,
    Low,
    Info,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TlsInfo {
    pub subject: String,
    pub issuer: String,
    pub valid_from: DateTime<Utc>,
    pub valid_to: DateTime<Utc>,
    pub days_until_expiry: i64,
    pub serial_number: Option<String>,
    pub fingerprint: Option<String>,
    pub certificate_chain: Vec<String>,
    pub cipher_suite: Option<String>,
    pub tls_version: Option<String>,
    pub warnings: Vec<String>,
    pub errors: Vec<String>,
    pub comprehensive_data: Option<HashMap<String, String>>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ScanSummary {
    pub scan_id: String,
    pub timestamp: DateTime<Utc>,
    pub total_targets: usize,
    pub successful_requests: usize,
    pub failed_requests: usize,
    pub total_detections: usize,
    pub critical_findings: usize,
    pub high_findings: usize,
    pub duration_seconds: f64,
    pub tags: Vec<String>,
    pub configuration_hash: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HistoricalScanResult {
    pub url: String,
    pub scan_id: String,
    pub timestamp: DateTime<Utc>,
    pub status_code: Option<u16>,
    pub response_time_ms: Option<u64>,
    pub technology_detections: Vec<String>,
    pub content_findings_count: usize,
    pub critical_findings_count: usize,
    pub tls_valid_until: Option<DateTime<Utc>>,
    pub success: bool,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ChangeEvent {
    pub id: String,
    pub url: String,
    pub timestamp: DateTime<Utc>,
    pub change_type: ChangeType,
    pub old_value: Option<String>,
    pub new_value: Option<String>,
    pub field_name: String,
    pub severity: ChangeSeverity,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ChangeType {
    StatusCodeChanged,
    TechnologyAdded,
    TechnologyRemoved,
    CertificateChanged,
    ResponseTimeChange,
    ContentChanged,
    SecurityFindingAdded,
    SecurityFindingResolved,
    SiteDown,
    SiteUp,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ChangeSeverity {
    Critical,
    High,
    Medium,
    Low,
    Info,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ChangeSet {
    pub scan_id: String,
    pub previous_scan_id: Option<String>,
    pub timestamp: DateTime<Utc>,
    pub changes: Vec<ChangeEvent>,
}

impl ScanData {
    pub fn new(
        targets: Vec<String>,
        configuration: ScanConfiguration,
        results: Vec<HttpScanResult>,
    ) -> Self {
        let scan_id = Uuid::new_v4().to_string();
        let timestamp = Utc::now();
        
        let total_targets = targets.len();
        let successful_requests = results.iter().filter(|r| r.success).count();
        let failed_requests = total_targets - successful_requests;
        let total_detections = results
            .iter()
            .map(|r| r.technology_detections.len())
            .sum();
        let critical_findings = results
            .iter()
            .flat_map(|r| &r.content_findings)
            .filter(|f| matches!(f.severity, FindingSeverity::Critical))
            .count();
        let high_findings = results
            .iter()
            .flat_map(|r| &r.content_findings)
            .filter(|f| matches!(f.severity, FindingSeverity::High))
            .count();

        let configuration_hash = Self::hash_configuration(&configuration);
        
        let summary = ScanSummary {
            scan_id: scan_id.clone(),
            timestamp,
            total_targets,
            successful_requests,
            failed_requests,
            total_detections,
            critical_findings,
            high_findings,
            duration_seconds: 0.0, 
            tags: Vec::new(),
            configuration_hash,
        };

        Self {
            scan_id,
            timestamp,
            targets,
            configuration,
            results,
            summary,
        }
    }

    fn hash_configuration(config: &ScanConfiguration) -> String {
        use sha2::{Sha256, Digest};
        let config_bytes = bincode::serialize(config).unwrap_or_default();
        let mut hasher = Sha256::new();
        hasher.update(&config_bytes);
        format!("{:x}", hasher.finalize())
    }

    pub fn set_duration(&mut self, duration_seconds: f64) {
        self.summary.duration_seconds = duration_seconds;
    }

    pub fn add_tags(&mut self, tags: Vec<String>) {
        self.summary.tags.extend(tags);
    }
}

impl HttpScanResult {
    pub fn new_successful(
        url: String,
        status_code: u16,
        response_time_ms: u64,
        content_length: Option<u64>,
        headers: HashMap<String, String>,
        title: Option<String>,
        server: Option<String>,
    ) -> Self {
        Self {
            url,
            timestamp: Utc::now(),
            status_code: Some(status_code),
            response_time_ms: Some(response_time_ms),
            content_length,
            headers,
            title,
            server,
            technology_detections: Vec::new(),
            content_findings: Vec::new(),
            tls_info: None,
            screenshot_path: None,
            error_message: None,
            success: true,
        }
    }

    pub fn new_failed(url: String, error_message: String) -> Self {
        Self {
            url,
            timestamp: Utc::now(),
            status_code: None,
            response_time_ms: None,
            content_length: None,
            headers: HashMap::new(),
            title: None,
            server: None,
            technology_detections: Vec::new(),
            content_findings: Vec::new(),
            tls_info: None,
            screenshot_path: None,
            error_message: Some(error_message),
            success: false,
        }
    }
}

impl ChangeEvent {
    pub fn new(
        url: String,
        change_type: ChangeType,
        field_name: String,
        old_value: Option<String>,
        new_value: Option<String>,
        severity: ChangeSeverity,
    ) -> Self {
        Self {
            id: Uuid::new_v4().to_string(),
            url,
            timestamp: Utc::now(),
            change_type,
            old_value,
            new_value,
            field_name,
            severity,
        }
    }
}

impl std::fmt::Display for FindingSeverity {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Critical => write!(f, "Critical"),
            Self::High => write!(f, "High"),
            Self::Medium => write!(f, "Medium"),
            Self::Low => write!(f, "Low"),
            Self::Info => write!(f, "Info"),
        }
    }
}

impl std::fmt::Display for ChangeSeverity {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Critical => write!(f, "Critical"),
            Self::High => write!(f, "High"),
            Self::Medium => write!(f, "Medium"),
            Self::Low => write!(f, "Low"),
            Self::Info => write!(f, "Info"),
        }
    }
}

impl std::fmt::Display for ChangeType {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::StatusCodeChanged => write!(f, "Status Code Changed"),
            Self::TechnologyAdded => write!(f, "Technology Added"),
            Self::TechnologyRemoved => write!(f, "Technology Removed"),
            Self::CertificateChanged => write!(f, "Certificate Changed"),
            Self::ResponseTimeChange => write!(f, "Response Time Changed"),
            Self::ContentChanged => write!(f, "Content Changed"),
            Self::SecurityFindingAdded => write!(f, "Security Finding Added"),
            Self::SecurityFindingResolved => write!(f, "Security Finding Resolved"),
            Self::SiteDown => write!(f, "Site Down"),
            Self::SiteUp => write!(f, "Site Up"),
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_scan_data_creation() {
        let config = ScanConfiguration {
            timeout: 10,
            workers: 5,
            rate_limit: 10,
            http_enabled: true,
            https_enabled: true,
            detect_all: true,
            content_analysis: true,
            tls_analysis: true,
            comprehensive_tls: false,
            screenshot: false,
            plugin: None,
        };

        let results = vec![HttpScanResult::new_successful(
            "https://example.com".to_string(),
            200,
            500,
            Some(1024),
            HashMap::new(),
            Some("Example".to_string()),
            Some("nginx".to_string()),
        )];

        let targets = vec!["https://example.com".to_string()];
        let scan_data = ScanData::new(targets.clone(), config, results);

        assert!(!scan_data.scan_id.is_empty());
        assert_eq!(scan_data.targets, targets);
        assert_eq!(scan_data.summary.total_targets, 1);
        assert_eq!(scan_data.summary.successful_requests, 1);
        assert_eq!(scan_data.summary.failed_requests, 0);
    }

    #[test]
    fn test_serialization_roundtrip() {
        let config = ScanConfiguration {
            timeout: 10,
            workers: 5,
            rate_limit: 10,
            http_enabled: true,
            https_enabled: true,
            detect_all: true,
            content_analysis: false,
            tls_analysis: false,
            comprehensive_tls: false,
            screenshot: false,
            plugin: None,
        };

        let results = vec![HttpScanResult::new_failed(
            "https://example.com".to_string(),
            "Connection timeout".to_string(),
        )];

        let targets = vec!["https://example.com".to_string()];
        let original = ScanData::new(targets, config, results);

        let serialized = bincode::serialize(&original).unwrap();
        let deserialized: ScanData = bincode::deserialize(&serialized).unwrap();

        assert_eq!(original.scan_id, deserialized.scan_id);
        assert_eq!(original.targets, deserialized.targets);
        assert_eq!(original.results.len(), deserialized.results.len());
    }

    #[test]
    fn test_change_event_creation() {
        let change = ChangeEvent::new(
            "https://example.com".to_string(),
            ChangeType::StatusCodeChanged,
            "status_code".to_string(),
            Some("200".to_string()),
            Some("404".to_string()),
            ChangeSeverity::High,
        );

        assert!(!change.id.is_empty());
        assert_eq!(change.url, "https://example.com");
        assert_eq!(change.old_value, Some("200".to_string()));
        assert_eq!(change.new_value, Some("404".to_string()));
    }
}