fuzzing in 2014 - · pdf filemov eax, [edx] write trying to perform r/w operations on...

44
浏览器 FUZZING IN 2014: 戴维 VS aka 把头扔到对的地 Rosario valotta

Upload: hoanghuong

Post on 06-Feb-2018

223 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: FUZZING IN 2014 -   · PDF filemov eax, [edx] WRITE Trying to perform r/w operations on illegal or restricted memory locations Attempt to write to an ... 即使有些绕过技术

浏览器 FUZZING IN 2014: 戴维 VS 巨⼈人

aka

把⽯石头扔到对的地⽅方

Rosario valotta

Page 2: FUZZING IN 2014 -   · PDF filemov eax, [edx] WRITE Trying to perform r/w operations on illegal or restricted memory locations Attempt to write to an ... 即使有些绕过技术

议程 1.  内存破坏bugs: 在哪⾥里和为什么

2.  浏览器 FUZZING的先进技术

3.  介绍新的fuzzing⽅方法

4.  时间维度的FUZZING

5.  空间维度的FUZZING

6.  享受 FILEJA!

7.  ⼀一些成果

Page 3: FUZZING IN 2014 -   · PDF filemov eax, [edx] WRITE Trying to perform r/w operations on illegal or restricted memory locations Attempt to write to an ... 即使有些绕过技术

•  嗨,  北京!  我是Rosario,  我来⾃自距离8126.23公⾥里的地⽅方  

•  ⽇日常⼯工作:    在移动通讯运营商担任项⺫⽬目经理

•  也是⼀一位独⽴立安全研究,因为兴趣与热情⽆无关⾦金钱利益  

•  主要关注于Web安全,  浏览器安全  和新型攻击技术  

•  参与过的安全会议演讲:  HITB  两次,Deepsec,nuit  du  hack,phDays,swiss  cyber  storm  

•  https://sites.google.com/site/tentacoloviola/

你好 !

Page 4: FUZZING IN 2014 -   · PDF filemov eax, [edx] WRITE Trying to perform r/w operations on illegal or restricted memory locations Attempt to write to an ... 即使有些绕过技术

为什么要fuzzing?

巨⼤大的攻击⾯面:新功能不断添加,数百万⾏行的代码

简答:发现内存破坏的漏洞

⽆无所不在的平台:数⼗十亿的⽤用户在使⽤用

复杂带来的代价

为什么是浏览器?

Page 5: FUZZING IN 2014 -   · PDF filemov eax, [edx] WRITE Trying to perform r/w operations on illegal or restricted memory locations Attempt to write to an ... 即使有些绕过技术

漏洞市场

提供者 买家/中介 最终客户 独⽴立研究员  

漏洞研究公司

浏览器⼚厂商

间谍⽣生意

漏洞交易中介公司

浏览器提供漏洞奖励计划

坏⼈人

政府们

执法部⻔门

军事单位

⼤大型公司

任何有⾜足够预算并想控制他的⺫⽬目标群体

Page 6: FUZZING IN 2014 -   · PDF filemov eax, [edx] WRITE Trying to perform r/w operations on illegal or restricted memory locations Attempt to write to an ... 即使有些绕过技术

戴维 VS 巨⼈人 •  发现可攻击利⽤用的漏洞变得越来越困难

•  浏览器越来越安全

•  更⼤大且竞争的市场

•  如果你是寂寞安全研究员,⽤用弹⼸弓你⽆无法与 bug-killing 的⽆无敌舰队在那⾥里竞争

•  旧的⽅方法不在有⽤用

•  你需要新想法和新的⽅方法,你需要知道⽤用⽯石⼦子砸在哪⾥里才有⽤用

Page 7: FUZZING IN 2014 -   · PDF filemov eax, [edx] WRITE Trying to perform r/w operations on illegal or restricted memory locations Attempt to write to an ... 即使有些绕过技术

内存破坏漏洞的基本流程

ACCESS VIOLATIO

NS

READ

mov eax, [ebx] call [eax]

(eax=deadbeef) mov eax, [edx]

WRITE

Trying to perform r/w operations on illegal or restricted memory locations

Attempt to write to an invalid memory location pointed by a register

Attempt to read from a register pointing to an invalid memory location

DEP Violation /Read AV

on EIP

GS Violation

READ AV

HEAP  CORRUPTION

GENERIC  register

•  特殊的⾮非法访问bug •  ⾮非法访问bug被认为“可利⽤用攻击”的条件是:

•  能控制执⾏行流程 •  攻击者有完整控制⾮非法存取寄存器

Page 8: FUZZING IN 2014 -   · PDF filemov eax, [edx] WRITE Trying to perform r/w operations on illegal or restricted memory locations Attempt to write to an ... 即使有些绕过技术

DATA EXECUTION Prevention: 没有可执⾏行的堆栈,必须串起数个rop gadgets 来组成可执⾏行的shell-code ASRL: ⾼高熵随机化,跳转到 rop gadgets时不能依靠固定的内存地址 /GS: 堆栈缓冲区安全检查,不能利⽤用攻击者的输⼊入来堆栈溢出 Safe seh: eh(exception handler) 安全检查,不能覆盖 eh 常规来获取代码执⾏行的异常

操作系统内存保护

内存保护与沙箱 在现代的浏览器与操作系统,控制EIP是不⾜足以获取执⾏行任意代码

SANDBOX/Protected mode: 每个浏览窗⼝口运⾏行在低特权环境,⽆无法访问到⽂文件系统或其他关键机器的数据结构 Safe browsing/Smartscreen: 基于⽂文件的签名和信誉评价的技术,来阻⽌止执⾏行下载的⽂文件

浏览器保护

即使有些绕过技术存在,击败内存保护并跳脱浏览器沙箱还是⼀一个很困难的⼯工作

Page 9: FUZZING IN 2014 -   · PDF filemov eax, [edx] WRITE Trying to perform r/w operations on illegal or restricted memory locations Attempt to write to an ... 即使有些绕过技术

浏览器Fuzzing的常⻅见⺫⽬目标 渲染引擎是浏览器的体系结构最复杂模块: 显⽰示 HTML,XML,SVG,MATHML,VML ⽂文档和图像。 它可以显⽰示其他类型的数据通过插件或扩展 (PDF、 媒体⽂文件、 字体等)

• 这是负责解析 HTML,套⽤用 CSS ,构建⼀一个称为”DOM”的web⻚页⾯面内部树狀模型

• 在渲染完成之前, 每个逻辑操作是在 DOM 上执⾏行

选择有效的武器来Fuzz渲染引擎有: 1.  Fuzzing ⽂文件格式 2.  Fuzzing DOM

Page 10: FUZZING IN 2014 -   · PDF filemov eax, [edx] WRITE Trying to perform r/w operations on illegal or restricted memory locations Attempt to write to an ... 即使有些绕过技术

<⽂文件/>格式//fuzzing 基于变异技术 基于⽣生成技术

开始与⼀一个有效的测试⽤用例的池

对它们进⾏行伪随机突变 (bit翻转,追加随机,等等)

⼏几个免费的⼯工具: •  zzUF •  RADAmsa •  SDL Minifuzz

模型化您的输⼊入, 定义结构化的数据块 (语法意识fuzzing)

定义状态模型和代理(数据可⽤用操作)

⼏几个有价值的⼯工具: •  peach •  spike

+ 相对易⽤用的⽅方法 - 较少的代码覆盖率和代码路径

+ 可能有⾮非预期的结果在⻓长期实施后

- 需要对协议/⽂文件格式有较深的知识 + 由于有效的组合,所以更好的覆盖度

+ ⽐比较全⾯面和可扩展性更强

Page 11: FUZZING IN 2014 -   · PDF filemov eax, [edx] WRITE Trying to perform r/w operations on illegal or restricted memory locations Attempt to write to an ... 即使有些绕过技术

DOM fuzzing •  DOM 有⼀一个复杂的数据结构,带来沉重的建模加载 HTML — JS — CSS 所有可能的执⾏行 •  很多的 api: DOM 规格是由 组织来定义的,划分在 4 个不同规范⽂文件

Create random

elements

Tweak elements  attributes

Perform random

mutations on DOM

Collect element

reference

Trigger GC (e.g.

Heap spray)

Crawl DOM

reference

Several namespaces

Native JS structures or DOM collections

ON simple elements And on collections

Define custom Events handlers Also on event handling

routines

•  Michal zalewski 的 Cross_fuzz ⼯工具仍然是个基准 •  众多模块, ⼲⼴广泛被使⽤用 à很难再发现新的崩溃

•  Nduja 引⼊入⼀一些新的观念从 DOM Level 2 and 3 规范和提供有趣的结果

•  基本⼯工作流程:

Page 12: FUZZING IN 2014 -   · PDF filemov eax, [edx] WRITE Trying to perform r/w operations on illegal or restricted memory locations Attempt to write to an ... 即使有些绕过技术

新思路: fuzzing DOM 在 时间 与 空间 •  让我们提议 扩展的表⾯面(extended surface) 为浏览器 DOM fuzzing 渲染引擎 + ⽂文件格式范例

•  想法是把两个新维度引⼊入fuzzing模型: 时间和空间

•  Time: 引⼊入时间依赖关系在fuzzing逻辑当中: 1. 同步 / 异步事件 2. ⺴⽹网络交互

为了触发竞⽤用条件 •  Space: 延申fuzzing逻辑边界,在多个脚本上下⽂文中查找内存不⼀一致

Page 13: FUZZING IN 2014 -   · PDF filemov eax, [edx] WRITE Trying to perform r/w operations on illegal or restricted memory locations Attempt to write to an ... 即使有些绕过技术

⽯石⼦子 #1 - 时间维度的Fuzzing

Page 14: FUZZING IN 2014 -   · PDF filemov eax, [edx] WRITE Trying to perform r/w operations on illegal or restricted memory locations Attempt to write to an ... 即使有些绕过技术

JS 竟⽤用条件 •  所有现代浏览器都使⽤用⼀一条 OS 线程来实现 JS 脚本引擎。

•  唯⼀一的例外是web workers,但它不会访问 DOM,相对安全⻛风险较⼩小。

问: 既然 2个JS 事件不会发⽣生在同⼀一时间,我真的需要关⼼心争⽤用条件吗?

• 简答: 是的 • 详答: 如果你的代码对象/函数修改依赖于在触发⼀一个事件和调⽤用回调之间,你可能会有⿇麻烦 •  在过去发现⼏几个竞⽤用条件导致的漏洞:

•  APPLE WEBKIT - CVE-2012-3748 •  Mozilla firefox - CVE-2006-4253 •  Google chrome - CVE-2006-4253 •  Microsoft IE - CVE-2011-1257

•  三个主要问题来源:

events Set  

timeout  Set  

interval  

Network  interactions

Page 15: FUZZING IN 2014 -   · PDF filemov eax, [edx] WRITE Trying to perform r/w operations on illegal or restricted memory locations Attempt to write to an ... 即使有些绕过技术

JS 时间模型 •  浏览器是事件驱动

•  ⼏几乎每个浏览器执⾏行的动作都是被⽣生成⼀一个事件并附加到事件队列中 •  事件循环是⼀一个函数,在⼀一定时间许可下,从队列中取出事件并处理→ 在⼀一个时间只运⾏行⼀一个脚本

•  ⼤大部分事件是⽤用异步处理的

•  ⼀一些特殊事件 (mutation) 和事件由 dispatchEvent 触发的都是同步的

myFunction 执⾏行队列

事件队列

fn fn

x  

Event handler 1

x   x  

Event handler 2 Event handler 1

x   x  

Page 16: FUZZING IN 2014 -   · PDF filemov eax, [edx] WRITE Trying to perform r/w operations on illegal or restricted memory locations Attempt to write to an ... 即使有些绕过技术

JS 事件模型 •  DOM 级别 3 和 4 定义如何触发事件,处理和如何管理你的 DOM 对象的事件侦听器

•  myelem.addEventListener(“MouseClick”,  myHandlerFunction,  captureIsOn)  •  myelem.removeEventListener(“MouseClick”,  myHandlerFunction,  captureIsOn)  

•  DOM 保存侦听器的映射和事件处理程序连接到由事件类型分类的每个节点

•  当触发相应的事件的对象上,该节点上注册的所有事件处理函式都会被执⾏行

•  事件类型:

•  UI 事件 •  ⿏鼠标事件

•  MUTATION EVENTS •  etc

Code for eh1

Code for eh2

Code for eh3

Listeners: mouse click  •  Eh1  •  eh2

Listeners: Onload  •  eh3

Node #n

•  DOMAttrModified  •  DOMAttributeNameChanged  •  DOMCharacterDataModified  •  DOMElementNameChanged  •  DOMNodeInserted  •  DOMNodeInsertedIntoDocument  •  DOMNodeRemoved  •  DOMNodeRemovedFromDocument  •  DOMSubtreeModified  

Page 17: FUZZING IN 2014 -   · PDF filemov eax, [edx] WRITE Trying to perform r/w operations on illegal or restricted memory locations Attempt to write to an ... 即使有些绕过技术

事件传递 window  

document  

<html>  

<body>  

<div>  

<a>  

1

2

3

4

5

6

7

8

9

10

11

capture

bubble

•  事件对象被分派到事件⺫⽬目标

•  在开始分派时,浏览器必须确定该事件的传递路径

▪  事件必须经过的 dom 节点的层次结构列表

•  传递路径分为 3 个阶段: 1.  Capture:从⽂文件根节点到⺫⽬目标的⽗父节点 2.  Target:到达最终⺫⽬目标元素的事件 3.  Bubble:从⺫⽬目标的ancestor,以相反顺序到⽂文件的根元素

•  节点中的传播路径,如果侦听该事件的类型,可以根据处理函式来处理事件  →  改变的传播路径  

target  

Page 18: FUZZING IN 2014 -   · PDF filemov eax, [edx] WRITE Trying to perform r/w operations on illegal or restricted memory locations Attempt to write to an ... 即使有些绕过技术

18  

更多的事件!

//  select  the  target  node    var  target  =  document.querySelector('#some-­‐id');    //  create  an  observer  instance    var  observer  =  new  MutationObserver(function(mutations)  {  

 mutations.forEach(function(mutation)  {        //whatever    });    

});    //  configuration  of  the  observer:    var  config  =  {  attributes:  true,  childList:  true};    //  pass  in  the  target  node  and  the  observer  options    observer.observe(target,  config);    //  later,  you  can  stop  observing    observer.disconnect();    

•  mutations  =  observer.takeRecords();  •  NodeList  nl=observer.addedNodes; •  NodeList  nl=observer.removedNodes;  

•  在DOM Level4,Mutation Events 已被弃⽤用出于性能的原因

•  这不意味着你不能使⽤用他们 ;-­‐)  

•  现在,所有浏览器都⽀支持MutationObservers  

•  每个mutation被排队进mutation集合中

•  这使 DOM Mutation事件异步

•  ⼀一些有趣的 api 将为数组/节点列表中突变,提供⼀一个机会来区分添加的节点和删除部分

Page 19: FUZZING IN 2014 -   · PDF filemov eax, [edx] WRITE Trying to perform r/w operations on illegal or restricted memory locations Attempt to write to an ... 即使有些绕过技术

Fuzzing 事件:⼀一些提⽰示 setTimeout(fn,0) 将强制 fn 执⾏行在下⼀一个tick,甚⾄至如果不是在队列中的第⼀一个事件 尝试修改延迟,当fn已经在事件队列中

可以嵌套同步事件 突变事件处理程序可以同步中断触发 (例如 dom 节点中删除或⼀一些其他事件被调度使⽤用 dispatchEvent)的处理程序代码中的其他突变事件

传递路径分发后仍然保持不变 不可预料的后果可能来⾃自于传递路径改变节点在capture或bubble阶段

takeRecords,addedNodes,removedNodes 什么都没有但突变记录的 dom 节点的逻辑视图 (引⽤用的集合)

监听给定的 DOM 节点使⽤用两个 MutationEvent 的突变事件这两个 MutationObservers: 试着调整 takeRecords 数组后⼀一些同步 MutationEvent 改变节点

Page 20: FUZZING IN 2014 -   · PDF filemov eax, [edx] WRITE Trying to perform r/w operations on illegal or restricted memory locations Attempt to write to an ... 即使有些绕过技术

FUZZing with ⺴⽹网路调⽤用 (1/2) •  可以使⽤用 XMLHttpRequests 触发更多的竞⽤用条件  •  XHRs 可以是同步 (已弃⽤用) 或异步操作 •  可以使⽤用⼀一些事件侦听器监视 XHRs 状态:

•  readystatechange,  progress,  abort,  error,  load,  timeout,  loadend  

•  Xhr 对象必须不是垃圾回收 如果其状态打开和设置发送标志 或 它的状态加载 或 它已注册的⼀一个或多个事件侦听器

Create xhr  object Open xhr Execute

callback Send xhr

force GC

Unload/reload  document  

Redefine  XHR  

removeEventListener  Add listener

在回调返回之前, 你可以依靠同步事件来触发 GC

类似的考虑也适⽤用于 web sockets的⺴⽹网络调⽤用

Xhr dangling

references???

Page 21: FUZZING IN 2014 -   · PDF filemov eax, [edx] WRITE Trying to perform r/w operations on illegal or restricted memory locations Attempt to write to an ... 即使有些绕过技术

FUZZing with ⺴⽹网路调⽤用 (2/2) •  争⽤用条件可能会发⽣生,如果你的回调代码依赖于⼀一些对象/函数已经被回收或此刻的回调执⾏行未初始化

•  例如:假设回调代码执⾏行绑定到 xhr 对象上的⼀一些突变操作 并且你正在运⾏行多个并发 xhr 呼叫

Create xhr#1  object

Open xhr#1

Execute callback

Send xhr#1

Create xhr#2  object

Open xhr#2

Send xhr#2

Execute callback

GC

1

2

•  当  xhr  是递归时,⼀一些其他竟⽤用条件可能会发⽣生:

Create xhr  

object Open xhr Execute

callback Send xhr

XHR methods/attribute tweaking

3

类似的考虑也适⽤用于 web sockets的⺴⽹网络调⽤用

Page 22: FUZZING IN 2014 -   · PDF filemov eax, [edx] WRITE Trying to perform r/w operations on illegal or restricted memory locations Attempt to write to an ... 即使有些绕过技术

当⺴⽹网路调⽤用与DOM⼀一起派对! •  结合典型 DOM Fuzzing ⺴⽹网络调⽤用的⽅方法

•  使⽤用 xhrs 或 wss 来获取 JS有效代码段并在 dom 的上下⽂文中处理它

Create xhr/WS  object

Open xhr/WS

Execute callback

Send xhr/WS

Nodejs app

js Eval (JS)  

•  每个请求: 1.  在⽣生成响应之前会有随机延滞à这影响客户端时间点 2.  有效的 js 的⼀一个⽚片段组成并返回为text/html 或...... 3.  ... 函数的引⽤用在客户端上的声明返回

⼀一些 的应⽤用程序实作 http 和 Web Socket服务器

Page 23: FUZZING IN 2014 -   · PDF filemov eax, [edx] WRITE Trying to perform r/w operations on illegal or restricted memory locations Attempt to write to an ... 即使有些绕过技术

…派对的另⼀一⾯面

•  评估JS ⽚片段影响: ▪  同步 DOM 突变发⽣生在中间呼叫处理 ▪  当客户端位置⻚页导航到其他地⽅方,xhr/ws 引⽤用不释放

xhr  =  new  XMLHttpRequest();  xhr.open("GET",  "http://127.0.0.1:8887",  RBool());  xhr.onreadystatechange  =  function()  {  

 if  (this.readyState  ==  4)  {      var  s=document.createElement("script");      s.innerText=xhr.responseText;      document.body.appendChild(s);    }  

}  

混合同步与异步调⽤用

socket  =  new  WebSocket("ws://127.0.0.1:9999",  "fuzz");  socket.addEventListener("message",  function(event)  {  

 s=document.createElement("script");    s.src=(window.URL.createObjectURL(new  Blob([data],{type:"text/html"}));    document.body.appendChild(s);    f.contentWindow.eval(s.innerText);  

});  

Page 24: FUZZING IN 2014 -   · PDF filemov eax, [edx] WRITE Trying to perform r/w operations on illegal or restricted memory locations Attempt to write to an ... 即使有些绕过技术

主计划 #1

Add listener

Create random

elements

Tweak elements  attributes

Perform random

mutations on DOM

Collect element

reference

Trigger GC

Crawl DOM

reference

Use Several namespaces Also ON elements on collections

Use mutation events and mutation observers

Eval (JS)  

Send xhr/WS

Nodejs app

js Open

xhr/WS

Create xhr/WS  object

Event handler

crossfuzz layer

nduja layer

fileja layer

Page 25: FUZZING IN 2014 -   · PDF filemov eax, [edx] WRITE Trying to perform r/w operations on illegal or restricted memory locations Attempt to write to an ... 即使有些绕过技术

⽯石⼦子 #2 - 跨引擎的Fuzzing

Page 26: FUZZING IN 2014 -   · PDF filemov eax, [edx] WRITE Trying to perform r/w operations on illegal or restricted memory locations Attempt to write to an ... 即使有些绕过技术

IE 脚本引擎 •  在Windows上, JavaScript 被实作成⼀一个 COM DLL 可以被不同的应⽤用调⽤用: •  Windows Script Host (wsh) •  Internet Explorer

•  在IE 9之前的版本, IE 和 WSH 使⽤用相同⼀一份的JavaScript引擎 - Jscript.dll

•  在IE9的版本, 发⾏行⼀一个专⻔门为浏览器所设计的不同版本DLL – Jscript9.dll

•  为了维护向下兼容,Jscript9 引擎可以模拟 IE8 和 IE7 doc 模式,保持旧版引擎相同的⾏行为

•  模拟旧版引擎⾏行为其实并不意味着加载旧版引擎 !

Jscript.dll

Internet  Explorer 8 wsh

Jscript.dll

Internet  Explorer 9 wsh

Jscript9.dll

Page 27: FUZZING IN 2014 -   · PDF filemov eax, [edx] WRITE Trying to perform r/w operations on illegal or restricted memory locations Attempt to write to an ... 即使有些绕过技术

使⽤用旧版引擎 •  当定义为 <script>  或 <script  language=‘javascript’>    IE 9 + 加载 jscript9.dll

•  你可以强制 IE 加载旧版引擎 使⽤用下列宣告: <script  language=‘Jscript.Encode’>    

•  Jscript.Encode  是设计来解译编码过的脚本,但同时可以处理明⽂文的脚本。JScript9.dll 不⽀支持这项功能。

•  为了能够加载 Jscript.Encode  脚本,必须强制IE=8的模拟 •  IE也透过 jscript.dll ⽀支持VBScript 脚本      <script  language=‘vbscript’>    •  从IE11后弃⽤用 Vbscript ,但透过浏览器强制在以前版本的模拟模式可以继续使⽤用VBScript

<html>  <head>  <title>  test  encode</title>  <meta  http-­‐equiv="X-­‐UA-­‐Compatible"  content="IE=8"></meta>  </head>  <body>  <script    language="Jscript.Encode">          function  a(){alert(1);}  </script>  <script>  a();</script>  </body>  </html>  

Page 28: FUZZING IN 2014 -   · PDF filemov eax, [edx] WRITE Trying to perform r/w operations on illegal or restricted memory locations Attempt to write to an ... 即使有些绕过技术

Host - 引擎交互

•  Host和脚本引擎之间的通信使⽤用两个接⼝口: IActiveScript 和 IActiveScriptSite  

•  IActiveScriptSite 在host端上实现,并使 JS 引擎来调⽤用它的host

•  IActiveScript,实施在脚本引擎端,提供了必要的函数调⽤用来初始化引擎

•  IActiveScript 还包括 AddNamedItem API,Host⽤用来将对象添加到引擎的全局范围。IE 使⽤用此函数来添加窗⼝口和其他 DOM 对象到引擎

•  Idispatch 接⼝口实现在两端,⽤用于获取对象的句柄和执⾏行 get、 集合和函数调⽤用操作

IE 9+

IActiveScriptSite  

Jscript9.dll

IDispatch   IActiveScript  

IDispatch  

Page 29: FUZZING IN 2014 -   · PDF filemov eax, [edx] WRITE Trying to perform r/w operations on illegal or restricted memory locations Attempt to write to an ... 即使有些绕过技术

跨引擎的交互

IE 9+

Jscript.dll

IDispatch   IActiveScript  

Jscript9.dll

IDispatch   IActiveScript  

•  当发现Jscript.Encode 脚本时,IE9 host Jscript9 和 Jscript 两个引擎同时运⾏行,这两个引擎可以相互沟通

•  当引擎想要与其他引擎的对象进⾏行交互时,IE 需要封送的对象并将它传递回给请求的引擎 •  所以 Jscript9 和 Jscript 引擎之间的任何通信时,需要通过 IE 调⽤用 IDispatch 接⼝口

1.  Jscript 使⽤用 IDispatch 如果host的请求 jscript9 空间中的对象 2.  Host使⽤用 IDispatch JSCRIPT9 如果要封送的对象的引⽤用 3.  Host取消封送的引⽤用并将其返回到 jscript

Object  Unmarshalled  Object  Reference  

IDispatch  

Marshalled  Object  Reference  

Page 30: FUZZING IN 2014 -   · PDF filemov eax, [edx] WRITE Trying to perform r/w operations on illegal or restricted memory locations Attempt to write to an ... 即使有些绕过技术

威胁模型 •  引擎没办法知道在其他引擎context中创建的对象的状态

•  可以在其他引擎上删除对象或删除整个其他引擎context

•  Host(IE)有责任维护的对象和不同的脚本context中的对象引⽤用之间的⼀一致性

•  为了触发内存破坏,策略是使⽤用典型的 DOM fuzzing⽅方法,但所有爬⾏行调整和变异操作是跨引擎操作的

Parent window  

Jscript9.dll

Child window (ofiframe)  

Jscript.dll

Create random

elements

Tweak elements  attributes

Perform random

mutations on DOM

Collect element

reference

Trigger GC

Crawl DOM reference

Use Several namespaces Also ON elements on collections

Create random

elements

Tweak elements  attributes

Perform random

mutations on DOM

Collect element

reference

Trigger GC

Crawl DOM reference

Use Several namespaces Also ON elements on collections

OPEN

Page 31: FUZZING IN 2014 -   · PDF filemov eax, [edx] WRITE Trying to perform r/w operations on illegal or restricted memory locations Attempt to write to an ... 即使有些绕过技术

主计划 #2

Parent window  

Jscript9.dll

Child window  Jscript.dll

Create random

elements

Tweak elements  attributes

Perform random

mutations on DOM

Collect element

reference Trigger GC

Crawl DOM

reference

Use Several namespaces Also ON elements on collections

Create random

elements

Tweak elements  attributes

Perform random

mutations on DOM

Collect element

reference

Trigger GC

Crawl DOM reference

Use Several namespaces Also ON elements on collections

OPEN

Add listener

Use mutation events and mutation observers

Eval (JS)  

Send xhr/WS

Nodejs app

js Open xhr/

WS

Create xhr/WS  object

Event handler

Page 32: FUZZING IN 2014 -   · PDF filemov eax, [edx] WRITE Trying to perform r/w operations on illegal or restricted memory locations Attempt to write to an ... 即使有些绕过技术

FILEJA 的介绍 •  结合传统的 DOM fuzzing与时间事件和跨引擎fuzzing •  javascript & Nodejs 编写⽽而成

•  tested on grinder framework but totally agnostic from fuzzing framework

•  完全通⽤用技术: 不绑定到特定的 api,但可以是任何现有的 fuzzer 的⼀一个插件 +

Events/  network  

calls

= Increased

fuzzing surface

Your fuzzer

Your fuzzer

Your fuzzer

Cross engine

•  应⽤用在類似 nduja 的 fuzzer

•  兩個⽉月的完整测试在幾個主要以 ie11, chrome, win7 的虛擬機器上 •  在第⼀一周發現4 个可利⽤用的 bugs,另外5个bugs 在接下来幾個⽉月内发现

Page 33: FUZZING IN 2014 -   · PDF filemov eax, [edx] WRITE Trying to perform r/w operations on illegal or restricted memory locations Attempt to write to an ... 即使有些绕过技术

⼀一些结果 #1 Registers:          EAX  =  0x45454545  -­‐                  EBX  =  0x0303FCC0  -­‐  RW-­‐          ECX  =  0x68EB08B3  -­‐  R-­‐X  -­‐  jscript9!NativeCodeGenerator::CheckCodeGen          EDX  =  0x019AD684  -­‐  RW-­‐          ESI  =  0x00000003  -­‐                  EDI  =  0x0AC2F89C  -­‐  RW-­‐          EBP  =  0x0AC2F720  -­‐  RW-­‐          ESP  =  0x0AC2F6D4  -­‐  RW-­‐          EIP  =  0x45454545  -­‐            Call  Stack:          0x68EAD364  -­‐  jscript9!Js::JavascriptFunction::CallRootFunction          0x68EAD2B6  -­‐  jscript9!ScriptSite::CallRootFunction          0x68EAD23D  -­‐  jscript9!ScriptSite::Execute          0x68EAECC1  -­‐  jscript9!ScriptEngineBase::ExecuteInternal<0>          0x68EAEBFD  -­‐  jscript9!ScriptEngineBase::Execute          0x659DE34E  -­‐  mshtml!CMutationObserver::PerformMicrotaskCheckpoint          0x659DE284  -­‐  mshtml!CObserverManager::InvokeObserversForCheckpoint          0x65AA45DE  -­‐  mshtml!GlobalWndOnMethodCall          0x65487C5E  -­‐  mshtml!GlobalWndProc          0x753CC4E7  -­‐  user32!InternalCallWinProc          0x753CC5E7  -­‐  user32!UserCallWinProcCheckWow          0x753CCC19  -­‐  user32!DispatchMessageWorker          0x753CCC70  -­‐  user32!DispatchMessageW          0x65DD8DDC  -­‐  mshtml!ModelessThreadProc  

IE 11 Type: D.E.P. Violation Exploitable: YES

Survived  

KB-296926

2  June14

Page 34: FUZZING IN 2014 -   · PDF filemov eax, [edx] WRITE Trying to perform r/w operations on illegal or restricted memory locations Attempt to write to an ... 即使有些绕过技术

⼀一些结果 #2 Registers:          EAX  =  0x02F7AE34  -­‐  RW-­‐          EBX  =  0x00000000  -­‐                  ECX  =  0x771B179F  -­‐  R-­‐X  -­‐  ntdll!vDbgPrintExWithPrefixInternal          EDX  =  0x02F7ABD1  -­‐  RW-­‐          ESI  =  0x00620000  -­‐  RW-­‐          EDI  =  0x00645478  -­‐  RW-­‐          EBP  =  0x02F7AE9C  -­‐  RW-­‐          ESP  =  0x02F7AE24  -­‐  RW-­‐          EIP  =  0x77253873  -­‐  R-­‐X  -­‐  ntdll!RtlReportCriticalFailure    Call  Stack:          0x772547A3  -­‐  ntdll!RtlpReportHeapFailure          0x77254883  -­‐  ntdll!RtlpLogHeapFailure          0x77219D8A  -­‐  ntdll!RtlpCoalesceFreeBlocks          0x771E6287  -­‐  ntdll!RtlpFreeHeap          0x771E65A6  -­‐  ntdll!RtlFreeHeap          0x761FC3C4  -­‐  kernel32!HeapFree          0x020E0034  -­‐            0x03DA9539  -­‐            0x03DA3167  -­‐            0x673FCEAB  -­‐  jscript9!Js::JavascriptFunction::CallFunction<1>          0x674B46F2  -­‐  jscript9!Js::InterpreterStackFrame::Process          0x67552226  -­‐  jscript9!Js::InterpreterStackFrame::OP_TryCatch          0x674B4712  -­‐  jscript9!Js::InterpreterStackFrame::Process          0x67400AA3  -­‐  jscript9!Js::InterpreterStackFrame::InterpreterThunk<1>  

IE 11 Type: heap corruption Exploitable: probably

Page 35: FUZZING IN 2014 -   · PDF filemov eax, [edx] WRITE Trying to perform r/w operations on illegal or restricted memory locations Attempt to write to an ... 即使有些绕过技术

⼀一些结果 #3 Registers:          EAX  =  0x024C4400  -­‐                  EBX  =  0x00000000  -­‐                  ECX  =  0x047C87F8  -­‐  RW-­‐          EDX  =  0x02C40000  -­‐                  ESI  =  0x00000000  -­‐                  EDI  =  0x08A2BDA0  -­‐  RW-­‐          EBP  =  0x08315D50  -­‐  RW-­‐          ESP  =  0x08315D44  -­‐  RW-­‐          EIP  =  0x62ACBE7D  -­‐  R-­‐X  -­‐  mshtml!CWindow::SetTimeoutWithPaintController    Code:          0x62ACBE7D  -­‐  mov  eax,  [edx]          0x62ACBE7F  -­‐  push  edx          0x62ACBE80  -­‐  call  dword  ptr  [eax+8]          0x62ACBE83  -­‐  jmp  62a7f579h          0x62ACBE88  -­‐  mov  eax,  [ecx]          0x62ACBE8A  -­‐  push  ecx          0x62ACBE8B  -­‐  call  dword  ptr  [eax+8]          0x62ACBE8E  -­‐  jmp  62a7f58ah  Call  Stack:          0x62A7F6FD  -­‐  mshtml!CWindow::SetTimeoutHelper          0x62A7F914  -­‐  mshtml!CWindow::SetTimeoutFromScript          0x62A7F9A6  -­‐  mshtml!CFastDOM::CWindow::Trampoline_setTimeout            

IE 11 Type: r.A. Violation Exploitable: YES

Survived  

KB-296926

2  June14

Page 36: FUZZING IN 2014 -   · PDF filemov eax, [edx] WRITE Trying to perform r/w operations on illegal or restricted memory locations Attempt to write to an ... 即使有些绕过技术

⼀一些结果 #4 Registers:          EAX  =  0x00004444  -­‐                  EBX  =  0x0086EAB8  -­‐  RW-­‐          ECX  =  0x009320BC  -­‐  RW-­‐          EDX  =  0x032D1A01  -­‐  RW-­‐          ESI  =  0x00000001  -­‐                  EDI  =  0x0020003A  -­‐                  EBP  =  0x02EBC3F8  -­‐  RW-­‐          ESP  =  0x02EBC3E8  -­‐  RW-­‐          EIP  =  0x6A362B1F  -­‐  R-­‐X  -­‐  mshtml!CScriptData::AsyncFireOnError    Code:          0x6A362B1F  -­‐  call  dword  ptr  [eax]          0x6A362B21  -­‐  mov  esi,  eax          0x6A362B23  -­‐  lea  ecx,  [ebp-­‐8]          0x6A362B26  -­‐  push  0          0x6A362B28  -­‐  push  esi          0x6A362B29  -­‐  call  mshtml!CElement::CLock::CLock          0x6A362B2E  -­‐  push  -­‐1          0x6A362B30  -­‐  mov  ecx,  esi    Call  Stack:          0x69EF1A3C  -­‐  mshtml!GlobalWndOnMethodCall          0x69ED9A52  -­‐  mshtml!GlobalWndProc  

IE 11 Type: r.A. Violation Exploitable: YES

Page 37: FUZZING IN 2014 -   · PDF filemov eax, [edx] WRITE Trying to perform r/w operations on illegal or restricted memory locations Attempt to write to an ... 即使有些绕过技术

⼀一些结果 #5 Registers:          EAX  =  0x00454545  -­‐                  EBX  =  0x00000000  -­‐                  ECX  =  0x00410000  -­‐  R-­‐-­‐          EDX  =  0x00000008  -­‐                  ESI  =  0x0020F000  -­‐                  EDI  =  0x0020F000  -­‐                  EBP  =  0x0015E494  -­‐  RW-­‐          ESP  =  0x0015E47C  -­‐  RW-­‐          EIP  =  0x00454545  -­‐            Call  Stack:          0x668907A2  -­‐  chrome_child!WTF::DefaultAllocator::backingMalloc<WebCore::SVGTextChunk  *,void>          0x66CE6896  -­‐  chrome_child!WebCore::MutationObserver::enqueueMutationRecord          0x66CEE2B6  -­‐  chrome_child!WebCore::MutationObserverInterestGroup::enqueueMutationRecord          0x66AF3188  -­‐  chrome_child!WebCore::Element::willModifyAttribute          0x66B8B668  -­‐  chrome_child!WebCore::Element::setAttribute          0x66B8B29A  -­‐  chrome_child!WebCore::ElementV8Internal::setAttributeMethod          0x66B8AFFE  -­‐  chrome_child!WebCore::ElementV8Internal::setAttributeMethodCallback  

Chrome 35 Type: D.E.P. Violation Exploitable: YES

Page 38: FUZZING IN 2014 -   · PDF filemov eax, [edx] WRITE Trying to perform r/w operations on illegal or restricted memory locations Attempt to write to an ... 即使有些绕过技术

⼀一些结果 #6  Registers:          EAX  =  0x00000000  -­‐                  EBX  =  0x00000000  -­‐                  ECX  =  0x08010000  -­‐                  EDX  =  0x00000008  -­‐                  ESI  =  0x08001000  -­‐                  EDI  =  0x769BC502  -­‐  R-­‐X  -­‐  kernel32!InterlockedExchangeStub          EBP  =  0x0031E098  -­‐  RW-­‐          ESP  =  0x0031E080  -­‐  RW-­‐          EIP  =  0x00000000  -­‐            Call  Stack:          0x63914050  -­‐  chrome_child!WTF::StringImpl::createUninitialized          0x641B200F  -­‐  chrome_child!WebCore::StringTraits<WTF::AtomicString>::fromV8String<0>          0x63936B84  -­‐  chrome_child!WebCore::v8StringToWebCoreString<WTF::AtomicString>          0x63936CED  -­‐  chrome_child!WebCore::V8StringResource<1>::operator  WTF::AtomicString          0x63A7B279  -­‐  chrome_child!WebCore::ElementV8Internal::setAttributeMethod          0x63A7AFFE  -­‐  chrome_child!WebCore::ElementV8Internal::setAttributeMethodCallback          0x638A4D32  -­‐  chrome_child!v8::internal::FunctionCallbackArguments::Call          0x638A4B76  -­‐  chrome_child!v8::internal::HandleApiCallHelper<0>          0x638A49BB  -­‐  chrome_child!v8::internal::Builtin_HandleApiCall  

Chrome 35 Type: D.E.P. Violation Exploitable: probably

Page 39: FUZZING IN 2014 -   · PDF filemov eax, [edx] WRITE Trying to perform r/w operations on illegal or restricted memory locations Attempt to write to an ... 即使有些绕过技术

⼀一些结果 #7    Caught  a  Write  Access  Violation  in  process  5896  at  2014-­‐04-­‐12  17:51:14  with  a  crash  hash  of  D17449B5.C819B416    Registers:          EAX  =  0x0016F17C  -­‐  RW-­‐          EBX  =  0xFFFCE3CE  -­‐                  ECX  =  0x0016F17C  -­‐  RW-­‐          EDX  =  0x00000004  -­‐                  ESI  =  0x00000000  -­‐                  EDI  =  0x00C7B000  -­‐                  EBP  =  0x0016F15C  -­‐  RW-­‐          ESP  =  0x0016F14C  -­‐  RW-­‐          EIP  =  0x6386228C  -­‐  R-­‐X    Code:          0x6386228C  -­‐  mov  [edi+4],  ebx          0x6386228F  -­‐  call  638622ech          0x63862294  -­‐  mov  ecx,  [ebp+8]          0x63862297  -­‐  mov  [edi],  ebx          0x63862299  -­‐  mov  [ecx],  edi          0x6386229B  -­‐  add  esp,  4          0x6386229E  -­‐  pop  esi          0x6386229F  -­‐  pop  ebx  

Chrome 35 Type: w.a. Violation Exploitable: probably

Page 40: FUZZING IN 2014 -   · PDF filemov eax, [edx] WRITE Trying to perform r/w operations on illegal or restricted memory locations Attempt to write to an ... 即使有些绕过技术

⼀一些结果 #8    Registers:          EAX  =  0xFEEEFEEE  -­‐                  EBX  =  0x02EAA84C  -­‐  RW-­‐          ECX  =  0x02EAA750  -­‐  RW-­‐          EDX  =  0x02EAA750  -­‐  RW-­‐          ESI  =  0x02EAA840  -­‐  RW-­‐          EDI  =  0x72D9102D  -­‐  R-­‐X  -­‐  pthread_mutex_unlock          EBP  =  0x024AF448  -­‐  RW-­‐          ESP  =  0x024AF440  -­‐  RW-­‐          EIP  =  0x66ECD873  -­‐  R-­‐X  -­‐  CFHostUnscheduleFromRunLoop    Code:          0x66ECD873  -­‐  mov  edx,  [eax+1ch]          0x66ECD876  -­‐  call  edx          0x66ECD878  -­‐  pop  ebp          0x66ECD879  -­‐  ret          0x66ECD87A  -­‐  int  3          0x66ECD87B  -­‐  int  3          0x66ECD87C  -­‐  int  3          0x66ECD87D  -­‐  int  3    Call  Stack:          0x66ECA6FE  -­‐  CFHostUnscheduleFromRunLoop          0x66ECA676  -­‐  CFHostUnscheduleFromRunLoop          0x66EC8F8F  -­‐  CFHostUnscheduleFromRunLoop  

Safari 5 / webkit Type: R.a. Violation Exploitable: YES

Page 41: FUZZING IN 2014 -   · PDF filemov eax, [edx] WRITE Trying to perform r/w operations on illegal or restricted memory locations Attempt to write to an ... 即使有些绕过技术

⼀一些结果 #9  Registers:          EAX  =  0x68CC0056  -­‐  R-­‐X  -­‐  mshtml!CWritableCSSStyleDeclaration::`vftable'          EBX  =  0x03A3BEE0  -­‐  RW-­‐          ECX  =  0x03DF3BA8  -­‐  RW-­‐          EDX  =  0x00000000  -­‐                  ESI  =  0x00000000  -­‐                  EDI  =  0x02D0755C  -­‐  RW-­‐          EBP  =  0x02D0753C  -­‐  RW-­‐          ESP  =  0x02D07504  -­‐  RW-­‐          EIP  =  0x8B876960  -­‐            Code:          0x8B876960  -­‐  add  [eax],  al          0x8B876962  -­‐  add  [eax],  al          0x8B876964  -­‐  add  [eax],  al          0x8B876966  -­‐  add  [eax],  al          0x8B876968  -­‐  add  [eax],  al          0x8B87696A  -­‐  add  [eax],  al          0x8B87696C  -­‐  add  [eax],  al          0x8B87696E  -­‐  add  [eax],  al    Call  Stack:          0x68FBCB63  -­‐  mshtml!CJScript9Holder::VarToVARIANT          0x6985FEED  -­‐  mshtml!CFastDOM::CCSSStyleDeclaration::Trampoline_Set_stopColor          0x6AA0858B  -­‐  jscript9!Js::JavascriptExternalFunction::ExternalFunctionThunk          0x6AA090BA  -­‐  jscript9!Js::JavascriptOperators::CallSetter  

IE11 Type: DEP Violation Exploitable: YES

Survived  

KB-296926

2  June14

Page 42: FUZZING IN 2014 -   · PDF filemov eax, [edx] WRITE Trying to perform r/w operations on illegal or restricted memory locations Attempt to write to an ... 即使有些绕过技术

⼀一些结果 #10 Caught  a  Read  Access  Violation  in  process  5036  at  2014-­‐03-­‐29  15:30:59  with  a  crash  hash  of  F3D898F3.D2E8590A    Registers:          EAX  =  0x44444444  -­‐                  EBX  =  0x00000000  -­‐                  ECX  =  0x44444444  -­‐                  EDX  =  0x44444444  -­‐                  ESI  =  0x02DA2500  -­‐  RW-­‐          EDI  =  0x02DA24FC  -­‐  RW-­‐          EBP  =  0x0360BBEC  -­‐  RW-­‐          ESP  =  0x0360BBD8  -­‐  RW-­‐          EIP  =  0x7719EF10  -­‐  R-­‐X  -­‐  ntdll!RtlEnterCriticalSection      Call  Stack:          0x699FCD4D  -­‐  mshtml!CMarkup::AcquirePerfData          0x69936609  -­‐  mshtml!URLRequest::ResourceTimingMark          0x6993AFC7  -­‐  mshtml!URLRequest::OnResponse          0x6993AF9A  -­‐  mshtml!URLRequest::URLMONRequestSink::OnResponse          0x7704B075  -­‐  urlmon!CINetHttp::QueryStatusOnResponseDefault          0x77015824  -­‐  urlmon!CINetHttp::QueryStatusOnResponse          0x77015740  -­‐  urlmon!CINet::QueryInfoOnResponse  

IE 11 / Chrome 35 Type: R.a. Violation Exploitable: No(t yet)  

Page 43: FUZZING IN 2014 -   · PDF filemov eax, [edx] WRITE Trying to perform r/w operations on illegal or restricted memory locations Attempt to write to an ... 即使有些绕过技术

接下来的⼯工作 •  没有最终的 fileja 版本,原型只是⺫⽬目的是为了表明⼏几个概念,被证明是⾮非常有效的使浏览器崩溃

•  整合到你⾃自⼰己的 fuzzer,并让它运⾏行 ! •  不太可能由我继续这项⼯工作,将公开发布fuzzer 原型 •  ⼀一些⽅方向:

•  利⽤用⺴⽹网络协议栈来实现,很多的测试需要在⾮非 windows 平台和移动设备上做

•  可以将跨引擎⽅方法在 IE 上的也扩展到 VBScript

Page 44: FUZZING IN 2014 -   · PDF filemov eax, [edx] WRITE Trying to perform r/w operations on illegal or restricted memory locations Attempt to write to an ... 即使有些绕过技术

Thankyou

谢谢