-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdisruptive-logging.rs
43 lines (37 loc) · 1.14 KB
/
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
use modsecurity::{ModSecurity, Rules};
pub fn main() {
let ms = ModSecurity::builder().with_log_callbacks().build();
let mut rules = Rules::new();
rules
.add_plain(
r#"
SecRuleEngine DetectionOnly
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)
.with_logging(|msg| {
if let Some(msg) = msg {
println!("Received log: {}", msg);
}
})
.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");
assert!(transaction.intervention().is_none());
}