-
-
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.
Add support for sigmac to parse Config files and include them in sigm…
…a.go (#2) * sigmac parses Configs and adds them to sigma.go * Fix extra newline
- Loading branch information
1 parent
f07dede
commit 252e5f9
Showing
3 changed files
with
117 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package main | ||
|
||
import ( | ||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
type ruleOrConfig string | ||
|
||
func (r ruleOrConfig) IsRule() bool { | ||
return r == "rule" | ||
} | ||
|
||
func (r *ruleOrConfig) UnmarshalYAML(node *yaml.Node) error { | ||
// Check if there's a key called "detection". | ||
// This is a required field in a Sigma rule but doesn't exist in a config | ||
for _, node := range node.Content { | ||
if node.Kind == yaml.ScalarNode && node.Value == "detection" { | ||
*r = "rule" | ||
return nil | ||
} | ||
} | ||
return nil | ||
} |
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,44 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
func Test_isSigmaRule(t *testing.T) { | ||
tests := []struct { | ||
file string | ||
expectedIsRule bool | ||
}{ | ||
{ | ||
`title: foo | ||
logsources: | ||
foo: | ||
category: process_creation | ||
index: bar | ||
`, | ||
false, | ||
}, | ||
{ | ||
`title: foo | ||
detection: | ||
foo: | ||
- bar | ||
- baz | ||
selection: foo | ||
`, | ||
true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
var isRule ruleOrConfig | ||
err := yaml.Unmarshal([]byte(tt.file), &isRule) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if isRule.IsRule() != tt.expectedIsRule { | ||
t.Errorf("Expected\n%s to be detected as a rule", tt.file) | ||
} | ||
} | ||
} |
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