Skip to content

Commit

Permalink
test(matchers): added cased modirifer test #1398
Browse files Browse the repository at this point in the history
  • Loading branch information
hitenkoku committed Aug 16, 2024
1 parent 7fe85e8 commit d6f5d6f
Showing 1 changed file with 221 additions and 0 deletions.
221 changes: 221 additions & 0 deletions src/detections/rule/matchers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1659,6 +1659,70 @@ mod tests {
check_select(rule_str, record_json_str, false);
}

#[test]
fn test_detect_startswith_cased() {
// startswith|casedが正しく検知できることを確認
let rule_str = r#"
enabled: true
detection:
selection:
Channel: Security
EventID: 4732
TargetUserName|startswith|cased: "Administrators"
details: 'user added to local Administrators UserName: %MemberName% SID: %MemberSid%'
"#;

let record_json_str = r#"
{
"Event": {
"System": {
"EventID": 4732,
"Channel": "Security"
},
"EventData": {
"TargetUserName": "AdministratorsTest"
}
},
"Event_attributes": {
"xmlns": "http://schemas.microsoft.com/win/2004/08/events/event"
}
}"#;

check_select(rule_str, record_json_str, true);
}

#[test]
fn test_detect_startswith_cased2() {
// startswith|casedが正しく検知できることを確認
let rule_str = r#"
enabled: true
detection:
selection:
Channel: Security
EventID: 4732
TargetUserName|startswith|cased: "administrators"
details: 'user added to local Administrators UserName: %MemberName% SID: %MemberSid%'
"#;

let record_json_str = r#"
{
"Event": {
"System": {
"EventID": 4732,
"Channel": "Security"
},
"EventData": {
"TargetUserName": "AdministratorsTest"
}
},
"Event_attributes": {
"xmlns": "http://schemas.microsoft.com/win/2004/08/events/event"
}
}"#;

check_select(rule_str, record_json_str, false);
}

#[test]
fn test_detect_endswith1() {
// endswithが正しく検知できることを確認
Expand Down Expand Up @@ -1753,6 +1817,99 @@ mod tests {
check_select(rule_str, record_json_str, false);
}

#[test]
fn test_detect_endswith_cased1() {
// endswith|casedが正しく検知できることを確認
let rule_str = r#"
enabled: true
detection:
selection:
Channel: Security
EventID: 4732
TargetUserName|endswith|cased: "Administrators"
details: 'user added to local Administrators UserName: %MemberName% SID: %MemberSid%'
"#;

let record_json_str = r#"
{
"Event": {
"System": {
"EventID": 4732,
"Channel": "Security"
},
"EventData": {
"TargetUserName": "AdministratorsTest"
}
},
"Event_attributes": {
"xmlns": "http://schemas.microsoft.com/win/2004/08/events/event"
}
}"#;
check_select(rule_str, record_json_str, false);
}

#[test]
fn test_detect_endswith_cased2() {
// endswith|casedが正しく検知できることを確認
let rule_str = r#"
enabled: true
detection:
selection:
Channel: Security
EventID: 4732
TargetUserName|endswith|cased: "test"
details: 'user added to local Administrators UserName: %MemberName% SID: %MemberSid%'
"#;

let record_json_str = r#"
{
"Event": {
"System": {
"EventID": 4732,
"Channel": "Security"
},
"EventData": {
"TargetUserName": "AdministratorsTest"
}
},
"Event_attributes": {
"xmlns": "http://schemas.microsoft.com/win/2004/08/events/event"
}
}"#;
check_select(rule_str, record_json_str, false);
}

#[test]
fn test_detect_endswith_cased3() {
// endswith|casedが正しく検知できることを確認
let rule_str = r#"
enabled: true
detection:
selection:
Channel: Security
EventID: 4732
TargetUserName|endswith|cased: "sTest"
details: 'user added to local Administrators UserName: %MemberName% SID: %MemberSid%'
"#;

let record_json_str = r#"
{
"Event": {
"System": {
"EventID": 4732,
"Channel": "Security"
},
"EventData": {
"TargetUserName": "AdministratorsTest"
}
},
"Event_attributes": {
"xmlns": "http://schemas.microsoft.com/win/2004/08/events/event"
}
}"#;
check_select(rule_str, record_json_str, true);
}

#[test]
fn test_detect_contains1() {
// containsが正しく検知できることを確認
Expand Down Expand Up @@ -1848,6 +2005,70 @@ mod tests {
check_select(rule_str, record_json_str, false);
}

#[test]
fn test_detect_contains_cased1() {
// contains|casedが正しく検知できることを確認
let rule_str = r#"
enabled: true
detection:
selection:
Channel: Security
EventID: 4732
TargetUserName|contains|cased: "Administrators"
details: 'user added to local Administrators UserName: %MemberName% SID: %MemberSid%'
"#;

let record_json_str = r#"
{
"Event": {
"System": {
"EventID": 4732,
"Channel": "Security"
},
"EventData": {
"TargetUserName": "TestAdministratorsTest"
}
},
"Event_attributes": {
"xmlns": "http://schemas.microsoft.com/win/2004/08/events/event"
}
}"#;

check_select(rule_str, record_json_str, true);
}

#[test]
fn test_detect_contains_cased2() {
// contains|casedが正しく検知できることを確認
let rule_str = r#"
enabled: true
detection:
selection:
Channel: Security
EventID: 4732
TargetUserName|contains|cased: "MinistratorS"
details: 'user added to local Administrators UserName: %MemberName% SID: %MemberSid%'
"#;

let record_json_str = r#"
{
"Event": {
"System": {
"EventID": 4732,
"Channel": "Security"
},
"EventData": {
"TargetUserName": "TestministratorsTest"
}
},
"Event_attributes": {
"xmlns": "http://schemas.microsoft.com/win/2004/08/events/event"
}
}"#;

check_select(rule_str, record_json_str, false);
}

#[test]
fn test_detect_wildcard_multibyte() {
// multi byteの確認
Expand Down

0 comments on commit d6f5d6f

Please sign in to comment.