Module: check_mk
Branch: master
Commit: 315b38ecd2e479c1750802eb883f432ac7797de1
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=315b38ecd2e479…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Jan 27 08:48:45 2015 +0100
#1878 SEC Fixed possible shell injection when filtering the EC archive
To optimize searches in the Event Console archive files, the event console
uses "grep" to make a fast preselection of history entries. The grep command
is used for different filters, like the "ID of rule". This allows normal logged
in users with only GUI privileges to execute shell commands on the monitoring
host with privileges of the user the Event Console is running with. Normally
this is the sites user in OMD sites or the user nagios.
All currently maintained versions are affected. If you are using an affected
version which we offer no more releases for, you can use the patch of
this Werk to fix the issue for your version.
This issue has been discovered and reported by Christian Thiemann. Thanks!
---
.werks/1878 | 21 +++++++++++++++++++++
ChangeLog | 1 +
mkeventd/bin/mkeventd | 8 ++++----
3 files changed, 26 insertions(+), 4 deletions(-)
diff --git a/.werks/1878 b/.werks/1878
new file mode 100644
index 0000000..cd1826f
--- /dev/null
+++ b/.werks/1878
@@ -0,0 +1,21 @@
+Title: Fixed possible shell injection when filtering the EC archive
+Level: 2
+Component: ec
+Class: security
+Compatible: compat
+State: unknown
+Version: 1.2.7i1
+Date: 1422344183
+
+To optimize searches in the Event Console archive files, the event console
+uses "grep" to make a fast preselection of history entries. The grep command
+is used for different filters, like the "ID of rule". This allows normal
logged
+in users with only GUI privileges to execute shell commands on the monitoring
+host with privileges of the user the Event Console is running with. Normally
+this is the sites user in OMD sites or the user nagios.
+
+All currently maintained versions are affected. If you are using an affected
+version which we offer no more releases for, you can use the patch of
+this Werk to fix the issue for your version.
+
+This issue has been discovered and reported by Christian Thiemann. Thanks!
diff --git a/ChangeLog b/ChangeLog
index de4d9a5..2a10f6c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -169,6 +169,7 @@
* 1845 Keep record of original source IP address of a syslog message or SNMP trap...
* 1873 SEC: Escaping event text of event console messages correctly in views...
* 1672 Now able to reclassify logwatch messages before forwarding them to the event
console...
+ * 1878 SEC: Fixed possible shell injection when filtering the EC archive...
* 1839 FIX: Fix exception when notifying EC alert into monitoring for traps (because
PID is missing)
* 1813 FIX: Fixed bug in event console rule editor when no contact groups configured
diff --git a/mkeventd/bin/mkeventd b/mkeventd/bin/mkeventd
index ea452d7..4fb1755 100755
--- a/mkeventd/bin/mkeventd
+++ b/mkeventd/bin/mkeventd
@@ -847,7 +847,7 @@ def parse_history_file(path, headers, filters, greptexts, limit):
# Revert lines from the log file to have the newer lines processed first
cmd = 'tac "%s"' % path
if greptexts:
- cmd += ' | grep -i -e %s' % ".*".join(greptexts)
+ cmd += " | grep -i -e %s" %
quote_shell_string(".*".join(greptexts))
grep = subprocess.Popen(cmd, shell=True, close_fds=True, stdout=subprocess.PIPE)
for line in grep.stdout:
@@ -3215,11 +3215,11 @@ def substitute_event_tags(text, event):
text = text.replace('$%s$' % key.upper(), value)
return text
-def shell_escape(s):
- return s.replace("'", "'\"'\"")
+def quote_shell_string(s):
+ return "'" + s.replace("'",
"'\"'\"'") + "'"
def send_email(to, subject, body):
- os.popen("mail -s '%s' '%s'" % (shell_escape(subject),
shell_escape(to)), "w").write(body)
+ os.popen("mail -s %s %s" % (quote_shell_string(subject),
quote_shell_string(to)), "w").write(body)
def execute_script(body):
p = subprocess.Popen(