Skip to content

Commit

Permalink
Merge 06fd7a4 into fc02df5
Browse files Browse the repository at this point in the history
  • Loading branch information
ryandeivert committed Apr 2, 2020
2 parents fc02df5 + 06fd7a4 commit 2f3dfda
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 13 deletions.
3 changes: 3 additions & 0 deletions conf/global.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
],
"scheduled_query_locations": [
"scheduled_queries"
],
"publisher_locations": [
"publishers"
]
},
"infrastructure": {
Expand Down
4 changes: 4 additions & 0 deletions docs/source/config-global.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ Configuration
],
"scheduled_query_locations": [
"scheduled_queries"
],
"publisher_locations": [
"publishers"
]
}
}
Expand All @@ -82,6 +85,7 @@ Options
``matcher_locations`` Yes ``["matchers"]`` List of local paths where ``matchers`` are defined
``rule_locations`` Yes ``["rules"]`` List of local paths where ``rules`` are defined
``scheduled_query_locations`` Yes ``["scheduled_queries"]`` List of local paths where ``scheduled_queries`` are defined
``publisher_locations`` Yes ``["publishers"]`` List of local paths where ``publishers`` are defined
============================= ============= ========================= ===============


Expand Down
File renamed without changes.
7 changes: 4 additions & 3 deletions rules/matchers/matchers.py → matchers/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
is specific for the `prod` environment, we can define a matcher
and add it to our rules' `matchers` keyword argument:
from rules.matchers import matchers
from matchers import default
@rule('root_logins', logs=['osquery:differential'], matchers=[matchers.prod],
outputs=['pagerduty:sample-integration'])
Expand All @@ -14,13 +14,16 @@
@rule('root_logins', logs=['osquery:differential'],
matchers=[matchers.prod, matchers.pci], outputs=['pagerduty:sample-integration'])
"""


class AwsGuardDutyMatcher:
"""A class contains matchers for AWS GuardDuty service"""

@classmethod
def guard_duty(cls, rec):
return rec['detail-type'] == 'GuardDuty Finding'


class OsqueryMatcher:
"""A class defines contains matchers for Osquery events"""

Expand All @@ -33,12 +36,10 @@ class OsqueryMatcher:
'runlevel'
}


@classmethod
def added(cls, rec):
return rec['action'] == 'added'


@classmethod
def user_login(cls, rec):
"""Capture user logins from the osquery last table
Expand Down
2 changes: 1 addition & 1 deletion rules/community/cloudtrail/cloudtrail_aws_config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Alert on AWS Config"""
from rules.matchers.matchers import AwsConfigMatcher
from matchers.default import AwsConfigMatcher
from streamalert.shared.rule import rule


Expand Down
2 changes: 1 addition & 1 deletion rules/community/guardduty/guard_duty_all.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Alert on GuardDuty"""
from rules.matchers.matchers import AwsGuardDutyMatcher
from matchers.default import AwsGuardDutyMatcher
from streamalert.shared.rule import rule


Expand Down
2 changes: 1 addition & 1 deletion rules/community/osquery/ssh_login_activity.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Detect ssh login activity based on osquery last table"""
from rules.matchers.matchers import OsqueryMatcher
from matchers.default import OsqueryMatcher
from streamalert.shared.rule import rule


Expand Down
6 changes: 3 additions & 3 deletions streamalert/shared/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from copy import deepcopy
from inspect import isclass

from streamalert.shared.config import load_config
from streamalert.shared.importer import import_folders
from streamalert.shared.logger import get_logger

Expand Down Expand Up @@ -117,17 +118,16 @@ class AlertPublisherRepository:
As a usability optimization, using this Repository will eagerly load and register all
publishers in the application.
"""
_PUBLISHERS_DIRECTORY = 'publishers'
_publishers = {}
_is_imported = False

@classmethod
def import_publishers(cls):
if not cls._is_imported:
import_folders(cls._PUBLISHERS_DIRECTORY)
config = load_config()
import_folders(*config['global']['general'].get('publisher_locations', []))
cls._is_imported = True


@staticmethod
def is_valid_publisher(thing):
"""Returns TRUE if the given reference can be registered as a publisher
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/conf/global.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"general": {
"matcher_locations": [],
"rule_locations": [],
"scheduled_query_locations": []
"scheduled_query_locations": [],
"publisher_locations": []
},
"infrastructure": {
"alerts_table": {
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/streamalert/shared/test_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def setUp(self):
self.setUpPyfakefs()

# Add rule and matcher files which should be imported.
self.fs.create_file('matchers/matchers.py')
self.fs.create_file('matchers/default.py')
self.fs.create_file('rules/example.py')
self.fs.create_file('rules/community/cloudtrail/critical_api.py')

Expand All @@ -45,7 +45,7 @@ def test_python_rule_paths():
"""Rule - Python File Paths"""
result = set(_python_file_paths('matchers', 'rules'))
expected = {
'matchers/matchers.py',
'matchers/default.py',
'rules/example.py',
'rules/community/cloudtrail/critical_api.py'
}
Expand All @@ -72,7 +72,7 @@ def test_import_rules(mock_import):
"""Rule - Import Folders"""
import_folders('matchers', 'rules')
mock_import.assert_has_calls([
call('matchers.matchers'),
call('matchers.default'),
call('rules.example'),
call('rules.community.cloudtrail.critical_api')
], any_order=True)

0 comments on commit 2f3dfda

Please sign in to comment.