-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnon-disruptive-logging.rs
45 lines (37 loc) · 1.13 KB
/
non-disruptive-logging.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use modsecurity::{ModSecurity, Rules};
pub fn main() {
let ms = ModSecurity::default();
let mut rules = Rules::new();
rules
.add_plain(
r#"
SecRuleEngine On
SecRule REQUEST_HEADERS:X-Client-Port "@streq 22" \
"id:'1234567',\
log,\
msg:'Blocking SSH port',\
phase:1,\
t:none,\
status:403,\
deny
"#,
)
.expect("Failed to add rules");
let mut transaction = ms
.transaction_builder()
.with_rules(&rules)
.build()
.expect("Error building transaction");
transaction
.add_request_header("X-Client-Port", "22")
.expect("Error adding request header");
transaction
.process_request_headers()
.expect("Error processing request headers");
let intervention = transaction.intervention().expect("Expected intervention");
assert_eq!(intervention.status(), 403);
println!(
"Received log: {}",
intervention.log().expect("Expected log")
);
}