Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion server/modules/suricata/suricata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func TestValidate(t *testing.T) {
{
Name: "Invalid Direction",
Input: `alert http any any <-> any any (msg:"This rule has an invalid direction";)`,
ExpectedErr: "invalid direction, must be '<>' or '->', got <->",
ExpectedErr: "invalid direction, must be '<>', '->', or '=>', got <->",
},
{
Name: "Unexpected Suffix",
Expand Down Expand Up @@ -432,6 +432,21 @@ func TestParse(t *testing.T) {
}
}

func TestParseTransactionalRules(t *testing.T) {
t.Parallel()

rule := `alert http any any => any any (msg:"transactional"; sid:1;)`
detections, err := ParseSuricataRules(context.Background(), rule, "ruleset")

assert.NoError(t, err)
if !assert.Len(t, detections, 1) {
return
}
assert.Equal(t, "1", detections[0].PublicID)
assert.Equal(t, "transactional", detections[0].Title)
assert.Equal(t, rule, detections[0].Content)
}

func TestExtractDetails(t *testing.T) {
t.Parallel()

Expand Down
6 changes: 3 additions & 3 deletions server/modules/suricata/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func ParseSuricataRule(rule string) (*SuricataRule, error) {
buf.WriteRune(ch)
}
case stateSource:
if ch == '<' || ch == '-' {
if ch == '<' || ch == '-' || ch == '=' {
out.Source = strings.TrimSpace(buf.String())
buf.Reset()
buf.WriteRune(ch)
Expand All @@ -92,8 +92,8 @@ func ParseSuricataRule(rule string) (*SuricataRule, error) {
case stateDirection:
if ch == ' ' {
out.Direction = strings.TrimSpace(buf.String())
if out.Direction != "<>" && out.Direction != "->" {
return nil, fmt.Errorf("invalid direction, must be '<>' or '->', got %s", out.Direction)
if out.Direction != "<>" && out.Direction != "->" && out.Direction != "=>" {
return nil, fmt.Errorf("invalid direction, must be '<>', '->', or '=>', got %s", out.Direction)
}

buf.Reset()
Expand Down
17 changes: 16 additions & 1 deletion server/modules/suricata/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,25 @@ func TestParseSuricata(t *testing.T) {
Options: []*RuleOption{},
},
},
{
Name: "Transactional Rule",
Input: `alert http any any => any any (msg:"transactional"; sid:1;)`,
Output: &SuricataRule{
Action: "alert",
Protocol: "http",
Source: "any any",
Direction: "=>",
Destination: "any any",
Options: []*RuleOption{
{Name: "msg", Value: util.Ptr(`"transactional"`)},
{Name: "sid", Value: util.Ptr("1")},
},
},
},
{
Name: "Bad Direction",
Input: `a b source port <- destination port ()`,
Error: util.Ptr("invalid direction, must be '<>' or '->', got <-"),
Error: util.Ptr("invalid direction, must be '<>', '->', or '=>', got <-"),
},
{
Name: "Unnecessary Suffix",
Expand Down