security_rust/protocol/
dns_rebinding.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)Host:\s*127\.").unwrap(),
11 Regex::new(r"(?i)Host:\s*10\.").unwrap(),
12 Regex::new(r"(?i)Host:\s*192\.168\.").unwrap(),
13 Regex::new(r"(?i)Host:\s*172\.(1[6-9]|2\d|3[01])").unwrap(),
14 Regex::new(r"(?i)Host:\s*localhost").unwrap(),
15 Regex::new(r"(?i)Host:\s*\[::1\]").unwrap(),
16 Regex::new(r"(?i)Host:\s*0\.0\.0\.0").unwrap(),
17 ]
18});
19
20pub struct DnsRebindingDetector;
21
22impl Detector for DnsRebindingDetector {
23 fn name(&self) -> &'static str {
24 "dns_rebinding"
25 }
26
27 fn detect(&self, input: &str) -> Option<DetectionResult> {
28 for re in PATTERNS.iter() {
29 if let Some(m) = re.find(input) {
30 return Some(DetectionResult {
31 attack_type: "dns_rebinding".into(),
32 category: AttackCategory::Protocol,
33 severity: Severity::High,
34 matched_pattern: m.as_str().to_string(),
35 offset: m.start(),
36 message: "DNS rebinding attack detected".into(),
37 });
38 }
39 }
40 None
41 }
42}