Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

matching: multi match support #331

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
9 changes: 9 additions & 0 deletions doc/update.rst
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,15 @@ with the provided metadata::
convert rules to drop. It is not available for rule
modification.

Multi Matching
--------------

The above matching methods can also be combined. It's logical AND, so all combined matcher need to match a given rule::

multi:filename:*/emerging-scan.rule;re:nmap;
multi:group:emerging-web_specific_apps;re:wordpress;re:cve[-,]201[6-9];
multi:re:cve[-_]202[23];metadata: deployment perimeter;

Modifying Rules
---------------

Expand Down
6 changes: 5 additions & 1 deletion suricata/update/configs/disable.conf
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@

# Disable all rules with a metadata of "deployment perimeter". Note that metadata
# matches are case insensitive.
# metadata: deployment perimeter
# metadata: deployment perimeter

# Example of multi matching
# Disable all rules with significant performance impact (metadata match) from emerging-policy (group match)
multi:metadata: performance_impact Significant;group:emerging-policy;
4 changes: 4 additions & 0 deletions suricata/update/configs/drop.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@
#
# re:heartbleed
# re:MS(0[7-9]|10)-\d+

# Example of multi matching
# Set phishing related (metadata match) rules from emerging-current_events (group match) to drop
multi:metadata: tag Phishing;group:emerging-current_events;
6 changes: 5 additions & 1 deletion suricata/update/configs/enable.conf
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@

# Enable all rules with a metadata of "deployment perimeter". Note that metadata
# matches are case insensitive.
# metadata: deployment perimeter
# metadata: deployment perimeter

# Example of multi matching
# Enable all rules with a recent cve reference (regular expression match) and a perimeter deployment (metadata match)
multi:re:cve[-_]202[23];metadata: deployment perimeter;
33 changes: 33 additions & 0 deletions suricata/update/matchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,35 @@ def parse(cls, buf):
return cls(key, val)
return None

class MultiRuleMatcher(object):
"""Matcher that build a container around other matchers. All childmatchers have to match for a true match.
Config syntax is "multi:<chlild1>;<child2>;<clildN>"."""

def __init__(self, childmatchers):
self.childmatchers = childmatchers

def match(self, rule):
for matcher in self.childmatchers:
if not matcher.match(rule):
return False
return True

@classmethod
def parse(cls, buf):
if buf.startswith("multi:"):
try:
logger.debug("Parsing multi matcher: %s", buf)
childmatcherstrs = filter(None, buf.split(":", 1)[1].strip().split(";"))
childmatchers = []
for childstr in childmatcherstrs:
matcher = parse_rule_match(childstr.strip())
if matcher:
childmatchers.append(matcher)
return cls(childmatchers)
except Exception as e:
raise e
return None


class ModifyRuleFilter(object):
"""Filter to modify an idstools rule object.
Expand Down Expand Up @@ -328,4 +357,8 @@ def parse_rule_match(match):
if matcher:
return matcher

matcher = MultiRuleMatcher.parse(match)
if matcher:
return matcher

return None