-
Notifications
You must be signed in to change notification settings - Fork 687
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3374 from dachary/wip-journalist-submission-frequ…
…ency ossec: resolve journalist notification racing with reboots
- Loading branch information
Showing
7 changed files
with
158 additions
and
18 deletions.
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
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,14 @@ | ||
OSSEC HIDS Notification. | ||
2018 May 06 20:18:24 | ||
|
||
Received From: (app) 10.0.1.4->head -1 /var/lib/securedrop/submissions_today.txt | grep '^[0-9]*$' | ||
Rule: 400600 fired (level 1) -> "Boolean value indicating if there were submissions in the past 24h." | ||
Portion of the log(s): | ||
|
||
ossec: output: 'head -1 /var/lib/securedrop/submissions_today.txt | grep '^[0-9]*$'': | ||
0 | ||
|
||
|
||
|
||
--END OF NOTIFICATION | ||
|
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,39 @@ | ||
OSSEC HIDS Notification. | ||
2018 May 06 20:18:24 | ||
|
||
Received From: (app) 10.0.1.4->netstat -tan |grep LISTEN |grep -v 127.0.0.1 | sort | ||
Rule: 533 fired (level 7) -> "Listened ports status (netstat) changed (new port opened or closed)." | ||
Portion of the log(s): | ||
|
||
ossec: output: 'netstat -tan |grep LISTEN |grep -v 127.0.0.1 | sort': | ||
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN | ||
tcp 0 0 0.0.0.0:37294 0.0.0.0:* LISTEN | ||
tcp6 0 0 :::111 :::* LISTEN | ||
tcp6 0 0 :::44352 :::* LISTEN | ||
Previous output: | ||
ossec: output: 'netstat -tan |grep LISTEN |grep -v 127.0.0.1 | sort': | ||
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN | ||
tcp 0 0 0.0.0.0:48638 0.0.0.0:* LISTEN | ||
tcp6 0 0 :::111 :::* LISTEN | ||
tcp6 0 0 :::37312 :::* LISTEN | ||
|
||
|
||
|
||
--END OF NOTIFICATION | ||
|
||
|
||
|
||
OSSEC HIDS Notification. | ||
2018 May 06 20:18:24 | ||
|
||
Received From: (app) 10.0.1.4->head -1 /var/lib/securedrop/submissions_today.txt | grep '^[0-9]*$' | ||
Rule: 400600 fired (level 1) -> "Boolean value indicating if there were submissions in the past 24h." | ||
Portion of the log(s): | ||
|
||
ossec: output: 'head -1 /var/lib/securedrop/submissions_today.txt | grep '^[0-9]*$'': | ||
0 | ||
|
||
|
||
|
||
--END OF NOTIFICATION | ||
|
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,22 @@ | ||
OSSEC HIDS Notification. | ||
2018 May 06 20:18:24 | ||
|
||
Received From: (app) 10.0.1.4->netstat -tan |grep LISTEN |grep -v 127.0.0.1 | sort | ||
Rule: 533 fired (level 7) -> "Listened ports status (netstat) changed (new port opened or closed)." | ||
Portion of the log(s): | ||
|
||
ossec: output: 'netstat -tan |grep LISTEN |grep -v 127.0.0.1 | sort': | ||
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN | ||
tcp 0 0 0.0.0.0:37294 0.0.0.0:* LISTEN | ||
tcp6 0 0 :::111 :::* LISTEN | ||
tcp6 0 0 :::44352 :::* LISTEN | ||
Previous output: | ||
ossec: output: 'netstat -tan |grep LISTEN |grep -v 127.0.0.1 | sort': | ||
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN | ||
tcp 0 0 0.0.0.0:48638 0.0.0.0:* LISTEN | ||
tcp6 0 0 :::111 :::* LISTEN | ||
tcp6 0 0 :::37312 :::* LISTEN | ||
|
||
|
||
|
||
--END OF NOTIFICATION |
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 |
---|---|---|
|
@@ -64,25 +64,31 @@ class TestJournalistMail(TestBase): | |
|
||
def test_procmail(self, host): | ||
self.service_started(host, "postfix") | ||
today_payload = ( | ||
'ossec: output: head -1 /var/lib/securedrop/submissions_today.txt' | ||
'\n1234') | ||
for (destination, payload) in ( | ||
('journalist', today_payload), | ||
('ossec', 'MYGREATPAYLOAD')): | ||
for (destination, f) in ( | ||
('journalist', 'alert-journalist-one.txt'), | ||
('journalist', 'alert-journalist-two.txt'), | ||
('ossec', 'alert-ossec.txt')): | ||
self.ansible(host, "copy", | ||
"dest=/tmp/{f} src=testinfra/ossec/{f}".format(f=f)) | ||
assert self.run(host, | ||
"/var/ossec/process_submissions_today.sh forget") | ||
assert self.run(host, "postsuper -d ALL") | ||
assert self.run( | ||
host, | ||
"echo -e '{payload}' | " | ||
"mail -s 'abc' root@localhost".format(payload=payload)) | ||
"cat /tmp/{f} | mail -s 'abc' root@localhost".format(f=f)) | ||
assert self.wait_for_command( | ||
host, | ||
"mailq | grep -q {destination}@ossec.test".format( | ||
destination=destination)) | ||
self.service_stopped(host, "postfix") | ||
|
||
def test_process_submissions_today(self, host): | ||
self.run(host, "/var/ossec/process_submissions_today.sh test_main") | ||
assert self.run(host, | ||
"/var/ossec/process_submissions_today.sh " | ||
"test_handle_notification") | ||
assert self.run(host, | ||
"/var/ossec/process_submissions_today.sh " | ||
"test_modified_in_the_past_24h") | ||
|
||
def test_send_encrypted_alert(self, host): | ||
self.service_started(host, "postfix") | ||
|
@@ -109,8 +115,8 @@ def trigger(who, payload): | |
# encrypted mail to journalist or ossec contact | ||
# | ||
for (who, payload, expected) in ( | ||
('journalist', 'ossec: output\n1', '1'), | ||
('ossec', 'MYGREATPAYLOAD', 'MYGREATPAYLOAD')): | ||
('journalist', 'JOURNALISTPAYLOAD', 'JOURNALISTPAYLOAD'), | ||
('ossec', 'OSSECPAYLOAD', 'OSSECPAYLOAD')): | ||
assert self.run(host, "postsuper -d ALL") | ||
trigger(who, payload) | ||
assert self.run( | ||
|
@@ -185,10 +191,15 @@ def test_journalist_mail_notification(self, host): | |
# empty the mailq on mon in case there were leftovers | ||
# | ||
assert self.run(mon, "postsuper -d ALL") | ||
# | ||
# forget about past notifications in case there were leftovers | ||
# | ||
assert self.run(mon, "/var/ossec/process_submissions_today.sh forget") | ||
|
||
# | ||
# the command fires every time ossec starts, | ||
# regardless of the frequency | ||
# https://github.com/ossec/ossec-hids/issues/1415 | ||
# | ||
with app.sudo(): | ||
self.service_restarted(app, "ossec") | ||
|
@@ -203,6 +214,21 @@ def test_journalist_mail_notification(self, host): | |
mon, | ||
"test 1 = $(mailq | grep [email protected] | wc -l)") | ||
|
||
assert self.run( | ||
mon, | ||
"grep --count 'notification suppressed' /var/log/syslog " | ||
"> /tmp/before") | ||
|
||
# | ||
# The second notification within less than 24h is suppressed | ||
# | ||
with app.sudo(): | ||
self.service_restarted(app, "ossec") | ||
assert self.wait_for_command(mon, """ | ||
grep --count 'notification suppressed' /var/log/syslog > /tmp/after | ||
test $(cat /tmp/before) -lt $(cat /tmp/after) | ||
""") | ||
|
||
# | ||
# teardown the ossec and postfix on mon and app | ||
# | ||
|