Skip to main content

security_rust/injection/
jndi_injection.rs

1// Copyright (c) 2026 erik <erik@erik.xyz> — https://erik.xyz
2
3use crate::{AttackCategory, DetectionResult, Detector, Severity};
4use regex::Regex;
5use std::sync::LazyLock;
6
7static PATTERNS: LazyLock<Vec<Regex>> = LazyLock::new(|| {
8    vec![
9        Regex::new(r"(?i)\$\{jndi:").unwrap(),
10        Regex::new(r"(?i)\$\{lower:j\}").unwrap(),
11        Regex::new(r"(?i)\$\{upper:j\}").unwrap(),
12        Regex::new(r"(?i)\$\{::-j\}").unwrap(),
13        Regex::new(r"(?i)\$\{env:").unwrap(),
14        Regex::new(r"(?i)\$\{sys:").unwrap(),
15        Regex::new(r"(?i)\$\{java:").unwrap(),
16    ]
17});
18
19pub struct JndiInjectionDetector;
20
21impl Detector for JndiInjectionDetector {
22    fn name(&self) -> &'static str {
23        "jndi_injection"
24    }
25
26    fn detect(&self, input: &str) -> Option<DetectionResult> {
27        for re in PATTERNS.iter() {
28            if let Some(m) = re.find(input) {
29                return Some(DetectionResult {
30                    attack_type: "jndi_injection".into(),
31                    category: AttackCategory::Injection,
32                    severity: Severity::Critical,
33                    matched_pattern: m.as_str().to_string(),
34                    offset: m.start(),
35                    message: "JNDI/Log4Shell injection detected".into(),
36                });
37            }
38        }
39        None
40    }
41}