Bug 200801 - security/ossec-hids-server: root escalation via syscheck feature
Summary: security/ossec-hids-server: root escalation via syscheck feature
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Some People
Assignee: Brad Davis
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-06-12 00:47 UTC by Jason Unovitch
Modified: 2015-06-12 14:15 UTC (History)
0 users

See Also:
bugzilla: maintainer-feedback? (brd)


Attachments
security/vuxml entry for ossec-hids-* and CVE-2015-3222 (1.37 KB, patch)
2015-06-12 00:53 UTC, Jason Unovitch
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jason Unovitch freebsd_committer freebsd_triage 2015-06-12 00:47:46 UTC
Source:  https://github.com/ossec/ossec-hids/releases/tag/2.8.2

Affected versions: 2.7 - 2.8.1

Beginning is OSSEC 2.7 (d88cf1c) a feature was added to syscheck, which
is the daemon that monitors file changes on a system, called
report_changes. This feature is only available on *NIX systems. It's
purpose is to help determine what about a file has changed. The logic to
do accomplish this is as follows which can be found in
src/syscheck/seechanges.c:

252 /* Run diff */
253 date_of_change = File_DateofChange(old_location);
254 snprintf(diff_cmd, 2048, "diff \"%s\" \"%s\" > \"%s/local/%s/diff.%d\" "
255     "2>/dev/null",
256     tmp_location, old_location,
257     DIFF_DIR_PATH, filename + 1, (int)date_of_change);
258 if (system(diff_cmd) != 256) {
259    merror("%s: ERROR: Unable to run diff for %s",
260           ARGV0,  filename);
261    return (NULL);
262 }
Above, on line 258, the system() call is used to shell out to the
system's diff command. The raw filename is passed in as an argument
which presents an attacker with the possibility to run arbitrary code.
Since the syscheck daemon runs as the root user so it can inspect any
file on the system for changes, any code run using this vulnerability
will also be run as the root user.

An example attack might be creating a file called foo-$(touch bar)
which should create another file bar.

Again, this vulnerability exists only on *NIX systems and is contingent
on the following criteria:

A vulnerable version is in use.
The OSSEC agent is configured to use syscheck to monitor the file system for changes.
The list of directories monitored by syscheck includes those writable by underprivileged users.
The report_changes option is enabled for any of those directories.
The fix for this is to create temporary trusted file names that symlink
back to the original files before calling system() and running the
system's diff command.
Comment 1 Jason Unovitch freebsd_committer freebsd_triage 2015-06-12 00:53:40 UTC
Created attachment 157656 [details]
security/vuxml entry for ossec-hids-* and CVE-2015-3222

Validation:

# make validate
/bin/sh /usr/ports/security/vuxml/files/tidy.sh "/usr/ports/security/vuxml/files/tidy.xsl" "/usr/ports/security/vuxml/vuln.xml" > "/usr/ports/security/vuxml/vuln.xml.tidy"
>>> Validating...
/usr/local/bin/xmllint --valid --noout /usr/ports/security/vuxml/vuln.xml
>>> Successful.
Checking if tidy differs...
... seems okay
Checking for space/tab...
... seems okay
/usr/local/bin/python2.7 /usr/ports/security/vuxml/files/extra-validation.py /usr/ports/security/vuxml/vuln.xml


# env PKG_DBDIR=/usr/ports/security/vuxml pkg audit ossec-hids-server-2.8.2
0 problem(s) in the installed packages found.

# env PKG_DBDIR=/usr/ports/security/vuxml pkg audit ossec-hids-server-2.8.1
ossec-hids-server-2.8.1 is vulnerable:
security/ossec-hids-* -- root escalation via syscheck feature
CVE: CVE-2015-3222
WWW: http://vuxml.FreeBSD.org/freebsd/c470db07-1098-11e5-b6a8-002590263bf5.html

1 problem(s) in the installed packages found.

# env PKG_DBDIR=/usr/ports/security/vuxml pkg audit ossec-hids-server-2.7
ossec-hids-server-2.7 is vulnerable:
security/ossec-hids-* -- root escalation via syscheck feature
CVE: CVE-2015-3222
WWW: http://vuxml.FreeBSD.org/freebsd/c470db07-1098-11e5-b6a8-002590263bf5.html

ossec-hids-server-2.7 is vulnerable:
security/ossec-hids-* -- root escalation via temp files
CVE: CVE-2014-5284
WWW: http://vuxml.FreeBSD.org/freebsd/36858e78-3963-11e4-ad84-000c29f6ae42.html

1 problem(s) in the installed packages found.
Comment 2 Brad Davis freebsd_committer freebsd_triage 2015-06-12 12:53:43 UTC
Thanks for the report. I am looking into it.
Comment 3 commit-hook freebsd_committer freebsd_triage 2015-06-12 14:11:17 UTC
A commit references this bug:

Author: brd
Date: Fri Jun 12 14:10:39 UTC 2015
New revision: 389270
URL: https://svnweb.freebsd.org/changeset/ports/389270

Log:
  Add ossec-hids-* vulnerabilities.

  PR:		200801
  Submitted by:	Jason Unovitch <jason.unovitch@gmail.com>
  Approved by:	swills (mentor)

Changes:
  head/security/vuxml/vuln.xml
Comment 4 Brad Davis freebsd_committer freebsd_triage 2015-06-12 14:15:44 UTC
Also committed the 2.8.2 update to the security/ossec-hids-* ports as r389271.