security_rust/protocol/
request_smuggling.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)Transfer-Encoding:.*\r\n.*Transfer-Encoding:").unwrap(),
11 Regex::new(r"(?i)Transfer-Encoding:[\s]*chunked").unwrap(),
12 Regex::new(r"(?i)Content-Length:[\s]*0").unwrap(),
13 Regex::new(r"(?i)\r\n0\r\n").unwrap(),
14 ]
15});
16
17pub struct RequestSmugglingDetector;
18
19impl Detector for RequestSmugglingDetector {
20 fn name(&self) -> &'static str {
21 "request_smuggling"
22 }
23
24 fn detect(&self, input: &str) -> Option<DetectionResult> {
25 for re in PATTERNS.iter() {
26 if let Some(m) = re.find(input) {
27 return Some(DetectionResult {
28 attack_type: "request_smuggling".into(),
29 category: AttackCategory::Protocol,
30 severity: Severity::High,
31 matched_pattern: m.as_str().to_string(),
32 offset: m.start(),
33 message: "HTTP request smuggling detected".into(),
34 });
35 }
36 }
37 None
38 }
39}