原文:
https://omespino.com/write-up-google-bug-bounty-xss-to-cloud-shell-instance-takeover-rce-as-root-5000-usd/
什么是Google Cloud Shell?
"您的在线开发和运营环境。Cloud Shell是一个在线开发和运营环境,可通过浏览器访问。您可以在其在线终端上预装了实用程序(例如gcloud命令行工具,kubectl等)来管理资源。您还可以使用在线Cloud Shell编辑器开发,构建,调试和部署您的云原生应用程序。"这实际上是Eclipse Theia编辑器实例。
所以实际上Google Cloud Shell就是Liunx虚拟机上装了个在线Eclipse Theia,那么什么是Eclipse Theia?
"Eclipse Theia是一个可扩展的平台,用于使用最新的Web技术开发多语言的Cloud/Desktop IDE。"

由于Theia是开源的,所以我们从Theia的GitHub存储仓库开始调查。
调查:
基本的计划是调查Theia的GitHub存储仓库,然后从issue里找有security标签的,然后分析这些issue。
幸运的是,有一个Google员工提交了一个markdown上的xss,并且给出了poc。


然后我就在https://shell.cloud.google.com/里测试了这个poc。

我知道Google会奖励xss,但是我像提高利用。
提升利用:
我第一个想法是如果xss和文件在同一个域,那么我有可能使用GET请求获取本地文件。但是比较难,我也注意到UI Theia编辑器部分允许在别的实例里,和命令行终端不在一个实例里。
幸运的是UI Theia实例有私钥在root目录下,我们只需要打开/(root)就能看到key,但是没法截图,如果你是我,你就可以看到“id_cloudshell”文件。

通过观察chrome下载流量,我们可以通过2个接口来使用js发送get请求来读这些文件。
第一步:‘https://’ + location.host + ‘/files/?uri=’ 用这个去获取任意uri的id。例如:/files/?uri=file:///etc/hosts。响应是这个样子:
{id: “5147084a-XXXX-43a9-afb0-bb8a126f1162”}
第二步:使用https://’ + location.host + ‘/files/download/?id=’,使用id /files/download/?id=5147084a-XXXX-43a9-afb0-bb8a126f1162 然后获取文件内容。
把所有的都放在一起:
Google Cloud Shell 有一个选项是点一下导入github仓库到Google Cloud Shell实例里,所以这个思路是:
1. 创建一个恶意的git库,把恶意代码写道read.me文件里。
2. 我们把Google Cloud Shell按钮也放到相同的文件里。

1. 然后诱使用户把这个项目导入到他的Google Cloud Shell实例里。
2. 一点read.md被解析,我们就获取到了/etc/hosts然后去构建公共域去访问cloud shell和私钥/../id_cloudshell。
主机名” cs-6000-devshell-vm-XXXXXXXX-XXXX-XXXXX-XXXXX”,我们删除cs-6000部分,然后拼接上.cloudshell.dev,然后就搞成”devshell-vm-XXXXXXXX-XXXX-XXXXX-XXXXX.cloudshell.dev”这个样子,这样是每个人都可以访问的。
3. 我们知道root是可以通过ssh登陆linux的。
4. 我们可以通过ping一下devshell-vm-XXXXXXXX-XXXX-XXXXX-XXXXX.cloudshell.dev(公共域)来获取ip,然后扫一下端口,然后发现ssh开在6000端口。
5. 知道了公共区域的主机名,端口,root用户还有私钥,我们只需要使用以下命令来登陆然后执行任意命令。
ssh -i id_cloudshell -p 6000 root@devshell-vm-XXXXXXXX-XXXX-XXXXX-XXXXX.cloudshell.dev
最终版read.me file 代码

译者按:
捋一下作者的思路,通过github issue发现了一个xss,然后又是本地域,然后使用ajax读文件。然后通过对产品的了解,达到了rce。唯一的问题是作者需要将恶意个文件导入进来,这点需要诱导用户配合。作者想尽办法,扩大利用,毕竟没有人想收self-xss漏洞。
本文迁移自知识星球“火线Zone”