-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Bradley Kemp
committed
Oct 1, 2020
1 parent
8e879b2
commit 8fd532f
Showing
6 changed files
with
111 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package evaluator | ||
|
||
func (rule *RuleEvaluator) calculateFieldMappings() { | ||
if rule.config == nil { | ||
return | ||
} | ||
|
||
mappings := map[string][]string{} | ||
|
||
for _, config := range rule.config { | ||
for field, mapping := range config.FieldMappings { | ||
// TODO: trim duplicates and only care about fields that are actually checked by this rule | ||
mappings[field] = append(mappings[field], mapping.TargetNames...) | ||
} | ||
} | ||
|
||
rule.fieldmappings = mappings | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package evaluator | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/bradleyjkemp/sigma-go" | ||
) | ||
|
||
func TestRuleEvaluator_HandlesBasicFieldMappings(t *testing.T) { | ||
rule := ForRule(sigma.Rule{ | ||
Logsource: sigma.Logsource{ | ||
Category: "category", | ||
Product: "product", | ||
Service: "service", | ||
}, | ||
Detection: sigma.Detection{ | ||
Searches: map[string]sigma.Search{ | ||
"test": { | ||
FieldMatchers: []sigma.FieldMatcher{{ | ||
Field: "name", | ||
Values: []string{"value"}, | ||
}}, | ||
}, | ||
}, | ||
Conditions: []sigma.Condition{ | ||
{Search: sigma.SearchIdentifier{Name: "test"}}}, | ||
}, | ||
}, WithConfig(sigma.Config{ | ||
FieldMappings: map[string]sigma.FieldMapping{ | ||
"name": {TargetNames: []string{"mapped-name"}}, | ||
}, | ||
})) | ||
|
||
if rule.Matches(context.Background(), map[string]interface{}{ | ||
"name": "value", | ||
}) { | ||
t.Error("If a field is mapped, the old name shouldn't be used") | ||
} | ||
|
||
if !rule.Matches(context.Background(), map[string]interface{}{ | ||
"mapped-name": "value", | ||
}) { | ||
t.Error("If a field is mapped, the mapped name should work") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters