-
Notifications
You must be signed in to change notification settings - Fork 688
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
Add OSSEC rule to indicate to admins what ansible-apt-key alert means #2224
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
915b9d9
OSSEC rule test: Ansible apt-key alert should fire
redshiftzero e3eb6a7
OSSEC rule tests: DRY up false positive regression tests
redshiftzero db52c75
Update language in config test developer docs for Ansible 2+ change
redshiftzero 43a4fea
Add new section explaining how to update and test OSSEC rule changes
redshiftzero fb229b5
OSSEC rule tests: DRY up tests for expected OSSEC alert
redshiftzero 471f9bc
OSSEC alerts: Add alert to notify admins when Ansible playbooks run
redshiftzero File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,95 @@ | ||
.. _updating_ossec_rules: | ||
|
||
Updating OSSEC Rules | ||
==================== | ||
|
||
SecureDrop uses the OSSEC open source host-based intrusion detection system | ||
(IDS) for log analysis, file integrity checking, policy monitoring, rootkit | ||
detection and real-time alerting. Refer to our :ref:`OSSEC guide <ossec_guide>` | ||
to learn more about how SecureDrop admins set up and monitor OSSEC alerts. | ||
|
||
Alerting Strategy | ||
----------------- | ||
|
||
The goals of the OSSEC alerts in SecureDrop is to notify administrators of: | ||
|
||
1. Suspicious security events | ||
2. Changes that require some kind of administrator action | ||
3. Other important notifications regarding system state. | ||
|
||
If an alert is purely informational and there is no realistic action an | ||
admin is expected to take, you should think carefully before | ||
suggesting a rule for it. Each additional alert that admins must read and/or | ||
respond to takes time. Alerts that are unimportant or otherwise require no action | ||
can lead to alert fatigue and thus to critical alerts being ignored. | ||
|
||
Using ``ossec-logtest`` | ||
----------------------- | ||
|
||
Development on the OSSEC rules should be done from the staging environment. | ||
|
||
On ``mon-staging``, there is a utility installed as part of OSSEC called | ||
``ossec-logtest`` that you can use to test log events. In order to evaluate | ||
whether an alert will be produced, and if so, what rule triggered it and its | ||
level, you can simply pass the event to ``ossec-logtest``: | ||
|
||
.. code:: sh | ||
|
||
root@mon-staging:/home/vagrant# sudo echo "Feb 10 23:34:40 app-prod kernel: [ 124.188641] grsec: denied RWX mmap of <anonymous mapping> by /usr/sbin/apache2[apache2:1328] uid/euid:33/33 gid/egid:33/33, parent /usr/sbin/apache2[apache2:1309] uid/euid:0/0 gid/egid:0/0" | /var/ossec/bin/ossec-logtest | ||
2017/08/16 22:28:25 ossec-testrule: INFO: Reading local decoder file. | ||
2017/08/16 22:28:25 ossec-testrule: INFO: Started (pid: 18973). | ||
ossec-testrule: Type one log per line. | ||
|
||
**Phase 1: Completed pre-decoding. | ||
full event: 'Feb 10 23:34:40 app-prod kernel: [ 124.188641] grsec: denied RWX mmap of <anonymous mapping> by /usr/sbin/apache2[apache2:1328] uid/euid:33/33 gid/egid:33/33, parent /usr/sbin/apache2[apache2:1309] uid/euid:0/0 gid/egid:0/0' | ||
hostname: 'app-prod' | ||
program_name: 'kernel' | ||
log: '[ 124.188641] grsec: denied RWX mmap of <anonymous mapping> by /usr/sbin/apache2[apache2:1328] uid/euid:33/33 gid/egid:33/33, parent /usr/sbin/apache2[apache2:1309] uid/euid:0/0 gid/egid:0/0' | ||
|
||
**Phase 2: Completed decoding. | ||
decoder: 'iptables' | ||
|
||
**Phase 3: Completed filtering (rules). | ||
Rule id: '100101' | ||
Level: '7' | ||
Description: 'grsec error was detected' | ||
**Alert to be generated. | ||
|
||
This is the utility we use in automated tests of OSSEC. | ||
|
||
Writing Automated Tests for OSSEC Rules | ||
--------------------------------------- | ||
|
||
We strongly recommend before making changes to OSSEC rules to attempt to write | ||
a failing test which you then can make pass with a patch to the OSSEC rules: | ||
|
||
1. Identify a log event you can use to trigger the alert. | ||
|
||
.. warning:: Be sure to use only log events from test SecureDrop instances or | ||
those you have verified do not contain any sensitive data. | ||
|
||
2. Write a Testinfra_ test to verify that the log event does or does not trigger | ||
an alert. | ||
3. Apply your patch to the OSSEC rule on the relevant VM (likely ``app``). | ||
4. Restart the service via ``sudo service ossec restart`` on ``mon``. | ||
|
||
.. note:: Currently we only have automated tests for alerts triggered due to | ||
log events (for example not for `syscheck`_, OSSEC's integrity | ||
checking process). If you have ideas for additional automated test | ||
coverage of alerts, please suggest them in ticket `2134`_ on GitHub. | ||
|
||
.. _Testinfra: https://testinfra.readthedocs.io/en/latest/ | ||
.. _syscheck: https://ossec-docs.readthedocs.io/en/latest/manual/syscheck/ | ||
.. _2134: https://github.com/freedomofpress/securedrop/issues/2134 | ||
|
||
Deployment | ||
---------- | ||
|
||
The OSSEC rules and associated configuration files are distributed via Debian | ||
packages maintained by Freedom of the Press Foundation. Any changes made to OSSEC | ||
configuration files will land on production SecureDrop monitoring servers as | ||
part of each SecureDrop release. This upgrade will occur automatically. | ||
|
||
.. note:: The use of automatic upgrades for release deployment means that any | ||
changes made locally by administrators to their OSSEC rules will not | ||
persist after a SecureDrop update. |
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
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
.. _ossec_guide: | ||
|
||
OSSEC Guide | ||
=========== | ||
|
||
|
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
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 |
---|---|---|
@@ -1,61 +1,29 @@ | ||
import pytest | ||
import re | ||
|
||
|
||
alert_level_regex = re.compile(r"Level: '(\d+)'") | ||
rule_id_regex = re.compile(r"Rule id: '(\d+)'") | ||
sdvars = pytest.securedrop_test_vars | ||
|
||
|
||
def test_grsec_denied_rwx_mapping_produces_alert(Command, Sudo): | ||
"""Check that a denied RWX mmaping produces an OSSEC alert""" | ||
test_alert = ("Feb 10 23:34:40 app kernel: [ 124.188641] grsec: denied " | ||
"RWX mmap of <anonymous mapping> by /usr/sbin/apache2" | ||
"[apache2:1328] uid/euid:33/33 gid/egid:33/33, parent " | ||
"/usr/sbin/apache2[apache2:1309] uid/euid:0/0 gid/egid:0/0") | ||
|
||
@pytest.mark.parametrize('log_event', | ||
sdvars.log_events_without_ossec_alerts) | ||
def test_ossec_false_positives_suppressed(Command, Sudo, log_event): | ||
with Sudo(): | ||
c = Command('echo "{}" | /var/ossec/bin/ossec-logtest'.format( | ||
test_alert)) | ||
|
||
# Level 7 alert should be triggered by rule 100101 | ||
assert "Alert to be generated" in c.stderr | ||
alert_level = alert_level_regex.findall(c.stderr)[0] | ||
assert alert_level == "7" | ||
|
||
|
||
def test_overloaded_tor_guard_does_not_produce_alert(Command, Sudo): | ||
"""Check that using an overloaded guard does not produce an OSSEC alert""" | ||
test_alert = ("Aug 16 21:54:44 app-staging Tor[26695]: [warn] Your Guard " | ||
"<name> (<fingerprint>) is failing a very large amount of " | ||
"circuits. Most likely this means the Tor network is " | ||
"overloaded, but it could also mean an attack against you " | ||
"or potentially the guard itself.") | ||
|
||
with Sudo(): | ||
c = Command('echo "{}" | /var/ossec/bin/ossec-logtest'.format( | ||
test_alert)) | ||
log_event["alert"])) | ||
assert "Alert to be generated" not in c.stderr | ||
|
||
|
||
def test_ossec_keep_alive_mark_does_not_produce_alert(Command, Sudo): | ||
"""Check that OSSEC keep alive messages sent to the OSSEC manager | ||
do not produce OSSEC alerts. | ||
|
||
For more information see: | ||
https://github.com/ossec/ossec-hids/issues/466 | ||
http://ossec-docs.readthedocs.io/en/latest/faq/alerts.html | ||
""" | ||
|
||
# Example alert from: | ||
# https://groups.google.com/forum/#!msg/ossec-list/dE3klm84JMU/kGZkRdSl3ZkJ | ||
test_alert = ("Dec 02 09:48:40 app-staging ossec-keepalive: --MARK--: " | ||
"&pQSW__BPa5S?%tyDTJ3-iCG2lz2dU))r(F%6tjp8wqpf=]IKFT%ND2k" | ||
"P]ua/W)3-6'eHduX$;$Axqq7Vr.dVZ1SUDSaH)4xTXCIieaEKv47LD-b" | ||
"U)SXMnXO/jPGKn3.!NGBR_5]jD2UoSV9)h%z8G%7.xhI;s)267.rV214" | ||
"O@t2#w)Z(k'UQp9]MyDERrOrG[-,e?iS@B3Rg/kGiR[g6mc0K)/]S]0'" | ||
"+?+'/.[r$fqBR^7iAjoPv4j6SWjeRsLGr%$3#p+buf&u_RC3i/mE3vS3*" | ||
"jp&B1qSJM431TmEg,YJ][ge;6-dJI69?-TB?!BI4?Uza63V3vMY3ake6a" | ||
"hj-%A-m_5lgab!OVR,!pR+;L]eLgilU") | ||
|
||
@pytest.mark.parametrize('log_event', | ||
sdvars.log_events_with_ossec_alerts) | ||
def test_ossec_expected_alerts_are_present(Command, Sudo, log_event): | ||
with Sudo(): | ||
c = Command('echo "{}" | /var/ossec/bin/ossec-logtest'.format( | ||
test_alert)) | ||
assert "Alert to be generated" not in c.stderr | ||
log_event["alert"])) | ||
assert "Alert to be generated" in c.stderr | ||
alert_level = alert_level_regex.findall(c.stderr)[0] | ||
assert alert_level == log_event["level"] | ||
rule_id = rule_id_regex.findall(c.stderr)[0] | ||
assert rule_id == log_event["rule_id"] |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beautiful job on the new test vars! The additions even pass YAML linting standards. 🥇