Skip to content
Merged
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
4 changes: 2 additions & 2 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var hexRE = regexp.MustCompile(`(?i)(\|(?:\s*[a-f0-9]{2}\s*)+\|)`)
var escapeRE = regexp.MustCompile(`([()+.'\\])`)

// escapeContent matches escaped special characters.
var escapeContent = regexp.MustCompile(`\\([\\;":])`)
var escapeContent = regexp.MustCompile(`\\([\\;":|\[\]+ .])`)

// metaSplitRE matches string in metadata.
var metaSplitRE = regexp.MustCompile(`,\s*`)
Expand Down Expand Up @@ -386,7 +386,7 @@ func containsUnescaped(s string) bool {
for _, b := range s {
if esc {
switch b {
case '\\', ';', '"', ':':
case '\\', ';', '"', ':', '|', '[', ']', '+', '.', ' ':
esc = false
default:
return true
Expand Down
34 changes: 34 additions & 0 deletions parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2139,6 +2139,25 @@ func TestParseRule(t *testing.T) {
},
},
},
{
name: "content match with escaped pipe and characters",
rule: `alert tcp any any -> any any (msg:"test"; content:"\|test\| \[abc\] \+ \. \ "; sid:1; rev:1;)`,
want: &Rule{
Action: "alert",
Protocol: "tcp",
Source: Network{Nets: []string{"any"}, Ports: []string{"any"}},
Destination: Network{Nets: []string{"any"}, Ports: []string{"any"}},
SID: 1,
Revision: 1,
Description: "test",
Matchers: []orderedMatcher{
&Content{
DataPosition: pktData,
Pattern: []byte("|test| [abc] + . "),
},
},
},
},
// Errors
{
name: "invalid action",
Expand Down Expand Up @@ -2364,6 +2383,21 @@ func TestContainsUnescaped(t *testing.T) {
input: `\\\\\\\\\;`,
want: false,
},
{
name: "escaped pipe",
input: `\|`,
want: false,
},
{
name: "escaped bracket",
input: `\[`,
want: false,
},
{
name: "escaped plus dot space",
input: `\+\.\ `,
want: false,
},
} {
got := containsUnescaped(tt.input)
if got != tt.want {
Expand Down
Loading