security_rust/protocol/
host_header.rs1use regex::Regex;
4use std::sync::LazyLock;
5
6use crate::{AttackCategory, DetectionResult, Detector, Severity};
7
8static PATTERNS: LazyLock<Vec<Regex>> = LazyLock::new(|| {
9 vec![
10 Regex::new(r"(?i)\r\n.*Host:").unwrap(),
11 Regex::new(r"(?i)\r\n.*X-Forwarded").unwrap(),
12 Regex::new(r"(?i)\r\n.*X-Forwarded-Host").unwrap(),
13 Regex::new(r"(?i)\r\n.*X-Original-URL").unwrap(),
14 Regex::new(r"(?i)\r\n.*X-Rewrite-URL").unwrap(),
15 ]
16});
17
18pub struct HostHeaderDetector;
19
20impl Detector for HostHeaderDetector {
21 fn name(&self) -> &'static str {
22 "host_header"
23 }
24
25 fn detect(&self, input: &str) -> Option<DetectionResult> {
26 for re in PATTERNS.iter() {
27 if let Some(m) = re.find(input) {
28 return Some(DetectionResult {
29 attack_type: "host_header".into(),
30 category: AttackCategory::Protocol,
31 severity: Severity::High,
32 matched_pattern: m.as_str().to_string(),
33 offset: m.start(),
34 message: "Host header attack detected".into(),
35 });
36 }
37 }
38 None
39 }
40}