security_rust/injection/
jndi_injection.rs1use 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 Regex::new(r"(?i)ldap://").unwrap(),
17 Regex::new(r"(?i)rmi://").unwrap(),
18 Regex::new(r"(?i)dns://").unwrap(),
19 Regex::new(r"(?i)ldaps://").unwrap(),
20 ]
21});
22
23pub struct JndiInjectionDetector;
24
25impl Detector for JndiInjectionDetector {
26 fn name(&self) -> &'static str {
27 "jndi_injection"
28 }
29
30 fn detect(&self, input: &str) -> Option<DetectionResult> {
31 for re in PATTERNS.iter() {
32 if let Some(m) = re.find(input) {
33 return Some(DetectionResult {
34 attack_type: "jndi_injection".into(),
35 category: AttackCategory::Injection,
36 severity: Severity::Critical,
37 matched_pattern: m.as_str().to_string(),
38 offset: m.start(),
39 message: "JNDI/Log4Shell injection detected".into(),
40 });
41 }
42 }
43 None
44 }
45}