website-vulnerability-scanner 0.2.0

Cross-platform defensive website security & configuration scanner with GUI and CLI reports.
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
use clap::ValueEnum;
use serde::{Deserialize, Serialize};

pub const SCHEMA_VERSION: &str = "2.0.0";

#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum, Serialize, Deserialize, Default)]
#[serde(rename_all = "lowercase")]
pub enum ScanProfile {
    #[default]
    Web,
    Api,
}

impl ScanProfile {
    pub fn label(self) -> &'static str {
        match self {
            ScanProfile::Web => "Web Site",
            ScanProfile::Api => "REST/JSON API",
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum, Serialize, Deserialize, Default)]
#[serde(rename_all = "lowercase")]
pub enum ReportAudience {
    Executive,
    #[default]
    Developer,
    Security,
}

impl ReportAudience {
    pub fn label(self) -> &'static str {
        match self {
            ReportAudience::Executive => "Owner / Executive",
            ReportAudience::Developer => "Developer",
            ReportAudience::Security => "Security / Auditor",
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Severity {
    Critical,
    High,
    Medium,
    Low,
    Info,
    Pass,
}

impl Severity {
    pub fn rank(self) -> u8 {
        match self {
            Severity::Critical => 5,
            Severity::High => 4,
            Severity::Medium => 3,
            Severity::Low => 2,
            Severity::Info => 1,
            Severity::Pass => 0,
        }
    }

    pub fn label(self) -> &'static str {
        match self {
            Severity::Critical => "CRITICAL",
            Severity::High => "HIGH",
            Severity::Medium => "MEDIUM",
            Severity::Low => "LOW",
            Severity::Info => "INFO",
            Severity::Pass => "PASS",
        }
    }

    pub fn css_class(self) -> &'static str {
        match self {
            Severity::Critical => "critical",
            Severity::High => "high",
            Severity::Medium => "medium",
            Severity::Low => "low",
            Severity::Info => "info",
            Severity::Pass => "pass",
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
pub enum FailThreshold {
    Critical,
    High,
    Medium,
    Low,
}

impl FailThreshold {
    pub fn matches(self, severity: Severity) -> bool {
        let min_rank = match self {
            FailThreshold::Critical => Severity::Critical.rank(),
            FailThreshold::High => Severity::High.rank(),
            FailThreshold::Medium => Severity::Medium.rank(),
            FailThreshold::Low => Severity::Low.rank(),
        };
        severity.rank() >= min_rank
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum Category {
    TransportTls,
    SecurityHeaders,
    HttpProtocol,
    Cookies,
    Cors,
    DnsEmail,
    InformationDisclosure,
    SecretsAndLeaks,
    ApiSecurity,
    ClientHtml,
    ExposedFiles,
    Availability,
}

impl Category {
    pub fn label(self) -> &'static str {
        match self {
            Category::TransportTls => "TLS / HTTPS",
            Category::SecurityHeaders => "Security Headers",
            Category::HttpProtocol => "HTTP & Caching",
            Category::Cookies => "Cookies",
            Category::Cors => "CORS Policy",
            Category::DnsEmail => "DNS & Email",
            Category::InformationDisclosure => "Information Disclosure",
            Category::SecretsAndLeaks => "Secrets & Data Leaks",
            Category::ApiSecurity => "API & Auth Hygiene",
            Category::ClientHtml => "Client & HTML Components",
            Category::ExposedFiles => "Exposed Files & Metadata",
            Category::Availability => "Availability",
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(rename_all = "snake_case")]
pub enum ExecutionStatus {
    #[default]
    Completed,
    Skipped,
    Error,
    Cancelled,
}

impl ExecutionStatus {
    pub fn label(self) -> &'static str {
        match self {
            ExecutionStatus::Completed => "completed",
            ExecutionStatus::Skipped => "skipped",
            ExecutionStatus::Error => "error",
            ExecutionStatus::Cancelled => "cancelled",
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(rename_all = "snake_case")]
pub enum Verdict {
    #[default]
    Pass,
    Fail,
    Inconclusive,
    NotApplicable,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(rename_all = "lowercase")]
pub enum Confidence {
    #[default]
    High,
    Medium,
    Low,
}

impl Confidence {
    pub fn label(self) -> &'static str {
        match self {
            Confidence::High => "high",
            Confidence::Medium => "medium",
            Confidence::Low => "low",
        }
    }
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CheckOutcome {
    pub check_id: String,
    pub category: Category,
    pub location: String,
    pub auth_context: String,
    pub status: ExecutionStatus,
    pub verdict: Verdict,
    #[serde(default)]
    pub reason: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Finding {
    pub id: String,
    pub category: Category,
    pub severity: Severity,
    pub title: String,
    pub summary: String,
    pub evidence: Option<String>,
    pub remediation: String,
    #[serde(default)]
    pub standard_ref: Option<String>,
    #[serde(default)]
    pub confidence: Confidence,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FindingInstance {
    pub fingerprint: String,
    pub finding_id: String,
    pub category: Category,
    pub severity: Severity,
    pub confidence: Confidence,
    pub location: String,
    pub auth_context: String,
    pub title: String,
    pub summary: String,
    pub evidence: Option<String>,
    pub remediation: String,
    #[serde(default)]
    pub standard_ref: Option<String>,
}

/// Computes a deterministic 64-bit FNV-1a hex fingerprint for a finding instance.
pub fn compute_fingerprint(
    rule_id: &str,
    target: &str,
    location: &str,
    auth_context: &str,
) -> String {
    let mut hash: u64 = 0xcbf29ce484222325;
    for part in [rule_id, "|", target, "|", location, "|", auth_context] {
        for b in part.as_bytes() {
            hash ^= u64::from(*b);
            hash = hash.wrapping_mul(0x100000001b3);
        }
    }
    format!("fp-{hash:016x}")
}

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct CoverageSummary {
    pub total_checks: usize,
    pub completed: usize,
    pub skipped: usize,
    pub errors: usize,
    pub cancelled: usize,
    pub not_applicable: usize,
    pub coverage_percent: u8,
    pub is_preliminary: bool,
}

impl CoverageSummary {
    pub fn from_outcomes(outcomes: &[CheckOutcome], cancelled: bool) -> Self {
        let mut summary = Self::default();
        for o in outcomes {
            if o.verdict == Verdict::NotApplicable {
                summary.not_applicable += 1;
                continue;
            }
            summary.total_checks += 1;
            match o.status {
                ExecutionStatus::Completed => summary.completed += 1,
                ExecutionStatus::Skipped => summary.skipped += 1,
                ExecutionStatus::Error => summary.errors += 1,
                ExecutionStatus::Cancelled => summary.cancelled += 1,
            }
        }
        summary.coverage_percent = (summary.completed * 100)
            .checked_div(summary.total_checks)
            .map_or(if cancelled { 0 } else { 100 }, |v| v.min(100) as u8);
        summary.is_preliminary = cancelled
            || summary.errors > 0
            || summary.cancelled > 0
            || summary.coverage_percent < 100;
        summary
    }
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ScorePenalty {
    pub finding_id: String,
    pub title: String,
    pub severity: Severity,
    pub points: u8,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TlsInfo {
    pub protocol: String,
    pub cipher_suite: String,
    pub subject: String,
    pub issuer: String,
    pub sans: Vec<String>,
    pub not_before: String,
    pub not_after: String,
    pub days_remaining: i64,
    pub hostname_matches: bool,
}

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct SeverityCounts {
    pub critical: usize,
    pub high: usize,
    pub medium: usize,
    pub low: usize,
    pub info: usize,
    pub pass: usize,
}

impl SeverityCounts {
    pub fn from_findings(findings: &[Finding]) -> Self {
        let mut counts = Self::default();
        for f in findings {
            match f.severity {
                Severity::Critical => counts.critical += 1,
                Severity::High => counts.high += 1,
                Severity::Medium => counts.medium += 1,
                Severity::Low => counts.low += 1,
                Severity::Info => counts.info += 1,
                Severity::Pass => counts.pass += 1,
            }
        }
        counts
    }
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ScanReport {
    #[serde(default = "default_schema_v1")]
    pub schema_version: String,
    #[serde(default)]
    pub engine_version: String,
    pub target: String,
    pub final_url: String,
    pub scanned_at: String,
    pub duration_ms: u128,
    pub status_code: Option<u16>,
    #[serde(default)]
    pub profile: ScanProfile,
    #[serde(default = "default_auth_ctx")]
    pub auth_context: String,
    #[serde(default)]
    pub run_status: ExecutionStatus,
    #[serde(default)]
    pub cancelled: bool,
    pub pages_scanned: usize,
    pub crawled_urls: Vec<String>,
    pub score: u8,
    pub grade: String,
    #[serde(default)]
    pub score_breakdown: Vec<ScorePenalty>,
    #[serde(default)]
    pub coverage: CoverageSummary,
    #[serde(default)]
    pub outcomes: Vec<CheckOutcome>,
    #[serde(default)]
    pub instances: Vec<FindingInstance>,
    pub tls: Option<TlsInfo>,
    pub findings: Vec<Finding>,
    pub counts: SeverityCounts,
}

fn default_schema_v1() -> String {
    "1.0.0".to_string()
}

fn default_auth_ctx() -> String {
    "anonymous".to_string()
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MultiScanReport {
    #[serde(default = "default_schema_v1")]
    pub schema_version: String,
    #[serde(default)]
    pub engine_version: String,
    pub tool: String,
    pub version: String,
    pub generated_at: String,
    #[serde(default)]
    pub cancelled: bool,
    pub reports: Vec<ScanReport>,
}

#[derive(Debug, Clone)]
pub struct ScanConfig {
    pub timeout_secs: u64,
    pub concurrency: usize,
    pub max_pages: usize,
    pub max_requests: usize,
    pub max_body_bytes: usize,
    pub profile: ScanProfile,
    pub skip_paths: bool,
    pub skip_dns: bool,
    pub user_agent: String,
    pub auth_context: String,
    pub openapi_path: Option<String>,
    pub custom_rules: Vec<crate::rules::CustomRule>,
    pub custom_advisories: Vec<crate::advisories::AdvisoryEntry>,
    pub auth_headers: Vec<(String, String)>,
    pub check_legacy_tls: bool,
    pub check_unauth_access: bool,
}

impl Default for ScanConfig {
    fn default() -> Self {
        Self {
            timeout_secs: 10,
            concurrency: 6,
            max_pages: 10,
            max_requests: 120,
            max_body_bytes: 512 * 1024,
            profile: ScanProfile::Web,
            skip_paths: false,
            skip_dns: false,
            user_agent: format!("web-vuln-scanner/{}", env!("CARGO_PKG_VERSION")),
            auth_context: "anonymous".to_string(),
            openapi_path: None,
            custom_rules: Vec::new(),
            custom_advisories: Vec::new(),
            auth_headers: Vec::new(),
            check_legacy_tls: true,
            check_unauth_access: true,
        }
    }
}