Skip to content

Commit

Permalink
fix: fix cuckoo dns implem to align with yara
Browse files Browse the repository at this point in the history
  • Loading branch information
vthib committed May 1, 2024
1 parent 348898f commit 113085f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
10 changes: 9 additions & 1 deletion boreal/src/module/cuckoo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,15 @@ fn search_dns(ctx: &mut EvalContext, args: Vec<Value>) -> Option<bool> {
Some(
values
.iter()
.filter_map(|value| value.get(host_field_name))
.filter_map(|value| {
// For some reason, YARA parses the "ip" key even though it does not use it.
// This means it considers objects without this key as invalid and will not
// consider them.
// It's unclear if this is voluntary or not, but align with this behavior
// for now.
let _ip = value.get("ip")?;
value.get(host_field_name)
})
.filter_map(|host| host.as_str())
.any(|host| regex.is_match(host.as_bytes())),
)
Expand Down
40 changes: 30 additions & 10 deletions boreal/tests/it/cuckoo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,8 +604,8 @@ fn test_network_dns_lookup() {
Some(
r#"{
"network": { "domains": [
{ "domain": "gheif" },
{ "domain": "abcde" }
{ "ip": "a", "domain": "gheif" },
{ "ip": "a", "domain": "abcde" }
]}
}"#,
),
Expand All @@ -615,8 +615,8 @@ fn test_network_dns_lookup() {
Some(
r#"{
"network": { "dns": [
{ "hostname": "gheif" },
{ "hostname": "abcde" }
{ "ip": "a", "hostname": "gheif" },
{ "ip": "a", "hostname": "abcde" }
]}
}"#,
),
Expand All @@ -627,8 +627,8 @@ fn test_network_dns_lookup() {
Some(
r#"{
"network": { "domains": [
{ "domain": "gheif" },
{ "hostname": "abcde" }
{ "ip": "a", "domain": "gheif" },
{ "ip": "a", "hostname": "abcde" }
] }
}"#,
),
Expand All @@ -638,8 +638,8 @@ fn test_network_dns_lookup() {
Some(
r#"{
"network": { "dns": [
{ "hostname": "gheif" },
{ "domain": "abcde" }
{ "ip": "a", "hostname": "gheif" },
{ "ip": "a", "domain": "abcde" }
] }
}"#,
),
Expand All @@ -649,12 +649,32 @@ fn test_network_dns_lookup() {
Some(
r#"{
"network": { "dom": [
{ "hostname": "abcde" },
{ "ip": "a", "hostname": "abcde" },
{ "ip": "a", "domain": "abcde" }
] }
}"#,
),
);
test(
"cuckoo.network.dns_lookup(/^a/) == 0",
Some(
r#"{
"network": { "domains": [
{ "domain": "abcde" }
] }
}"#,
),
);
test(
"cuckoo.network.dns_lookup(/^a/) == 0",
Some(
r#"{
"network": { "dns": [
{ "hostname": "abcde" }
] }
}"#,
),
);
test(
"cuckoo.network.dns_lookup(/^a/) == 0",
Some(r#"{ "network": { "domains": [] } }"#),
Expand All @@ -675,7 +695,7 @@ fn test_network_dns_lookup() {
);
test(
"cuckoo.network.dns_lookup(/^a/) == 0",
Some(r#"{ "network": true"#),
Some(r#"{ "network": true }"#),
);
test(
"cuckoo.network.dns_lookup(/^a/) == 0",
Expand Down

0 comments on commit 113085f

Please sign in to comment.