1 / 20

阶段工作总结

阶段工作总结. 杨峰 清华大学 2011 年 5 月. 概要. 1. Windows XP 进程监控的实现. 2. Windows XP System Call 监控的实现. 3. Ubuntu 进程监控的实现. 4. 监控系统性能测试与分析. 5 . 遇到的问题与解决. 6 . 下一步工作与计划. Windows XP 进程监控的实现. 原理与方法 CR3 切换 <-> 页表切换 <-> 进程切换 VT 的设置 SPT 更新 信息获取

cai
Download Presentation

阶段工作总结

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 阶段工作总结 杨峰 清华大学 2011年5月

  2. 概要 1. Windows XP 进程监控的实现 2. Windows XPSystem Call监控的实现 3. Ubuntu 进程监控的实现 4. 监控系统性能测试与分析 5. 遇到的问题与解决 6. 下一步工作与计划

  3. Windows XP 进程监控的实现 • 原理与方法 CR3切换<->页表切换<->进程切换 VT的设置 SPT更新 信息获取 SPT: Shadow Page Table • 具体实现 vmx.c: mov_to_cr() hvm.c: hvm_set_cr3() • 测试与总结 效果展示与问题分析

  4. Windows XP 进程监控的实现 原理和方法 • CR3切换的拦截 --> Xen默认即可拦截,无需再设置 • Windows进程信息的存储: • FS_BASE -> KPCR.KTHREAD -> EPROCESS -> ProcessName 具体实现 vmx.c: mov_to_cr() --> hvm.c: hvm_set_cr3() Process info: GUEST_FS_BASE -> get KPCR address, use offset to find process information

  5. Windows XP 进程监控的实现 测试与总结 • 对所有进程的Syscall调用进行监控 • print info • CALL name: [C:\WINDOWS\System32\svchost.exe], cr3: [0x826e000] pid: [820], NtWaitForMultipleObjects(0x4, 0x1c8fee0: 0x584, 0x1, 0x0, 0x0: 0) • print info • CALL name: [C:\WINDOWS\system32\wuauclt.exe], cr3: [0xc186000] pid: [1776], NtQuerySystemInformation(0x2, 0x26ffd60, 0x138, 0x0: 0) • print info • RET 0x0 = name: [C:\WINDOWS\system32\wuauclt.exe], cr3: [0xc186000] pid: [1776], NtQuerySystemInformation(0x2, 0x26ffd60, 0x138, 0x0: 0) • …… • print info • CALL name: [C:\WINDOWS\System32\svchost.exe], cr3: [0x826e000] pid: [820], NtQueryInformationFile(0x878, 0x1ccfb54, 0x1ccfb64, 0x8, 0x6) • print info • RET 0x0 = name: [C:\WINDOWS\System32\svchost.exe], cr3: [0x826e000] pid: [820], NtQueryInformationFile(0x878, 0x1ccfb54, 0x1ccfb64, 0x8, 0x6) • print info • CALL name: [C:\WINDOWS\System32\svchost.exe], cr3: [0x826e000] pid: [820], NtClose(0x878) • print info • CALL name: [], cr3: [0x6f75000] pid: [-1], NtNotifyChangeDirectoryFile(0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0) • Guest OS domain crash, and Guest OS restart. • 出错了,idle进程导致的错误  System Idle Process不是一个真正的进程 • 1、监控指定进程即可,无需监控idle进程 • 2、可以先判断出idle进程对应的cr3,再设置跳过对其的监控

  6. Windows XPSysCall监控的实现 • 原理与方法 cr3切换<->sysenter执行<->sys call return VT的设置 sysenter拦截 return address np(not present) • 具体实现 CR3切换 vmx.c:mov_to_cr()  hvm.c:hvm_set_cr3() sysenter拦截: vmx.c:vmx_vmexit_handler() syscall return拦截: multi.c: 设置新的函数实现该功能 • 测试与总结 效果展示与问题分析

  7. Windows XPSysCall监控的实现 PROCESS SYSCALL SYSCALL RET 通过CR3判断是否 被监控进程正在运行 是否开启 对该进程的监控 是否由sysenter执行 出错导致(PF) 如果是则向 用户态进程发送 syscall相关信息 用户态程序根据 返回结果通知 Xen读取Guest OS 对应内存位置信息 并再传递给用户态 设置SYSCALL RETURN ADDR 为缺页(NP) 缺页触发PF 检查是否是 SYSCALL RETURN 如果是 输出对应信息

  8. Windows XPSysCall监控的实现 V M E X I T H Y P E R C A L L • SYSCALL 监控简要流程图

  9. Windows XPSysCall监控的实现 • 测试结果 Setting filter by name to: explorer.exe print info CALL name: [C:\WINDOWS\Explorer.EXE], cr3: [0xa9ab000] pid: [1200], NtWaitForMultipleObjects(0x9, 0x10d5d8: 0x568, 0x1, 0x1, 0x0: 0) print info CALL name: [C:\WINDOWS\Explorer.EXE], cr3: [0xa9ab000] pid: [1200], NtClose(0x334) print info RET 0x0 = name: [C:\WINDOWS\Explorer.EXE], cr3: [0xa9ab000] pid: [1200], NtClose(0x334) print info CALL name: [C:\WINDOWS\Explorer.EXE], cr3: [0xa9ab000] pid: [1200], NtClose(0x324) print info RET 0x0 = name: [C:\WINDOWS\Explorer.EXE], cr3: [0xa9ab000] pid: [1200], NtClose(0x324) …… print info CALL name: [C:\WINDOWS\Explorer.EXE], cr3: [0xa9ab000] pid: [1200], NtWaitForSingleObject(0x264, 0x0, 0xf4fca4: -50000000) print info RET 0x0 = name: [C:\WINDOWS\Explorer.EXE], cr3: [0xa9ab000] pid: [1200], NtWaitForSingleObject(0x264, 0x0, 0xf4fca4: -50000000) print info CALL name: [C:\WINDOWS\Explorer.EXE], cr3: [0xa9ab000] pid: [1200], NtReleaseMutant(0x264, 0x0: 0) print info RET 0x0 = name: [C:\WINDOWS\Explorer.EXE], cr3: [0xa9ab000] pid: [1200], NtReleaseMutant(0x264, 0x0: 0) print info CALL name: [C:\WINDOWS\Explorer.EXE], cr3: [0xa9ab000] pid: [1200], NtClose(0x21c) print info RET 0x0 = name: [C:\WINDOWS\Explorer.EXE], cr3: [0xa9ab000] pid: [1200], NtClose(0x21c) ……

  10. Windows XPSysCall监控的实现 SYSENTER EIP 真值的获取与保存 问题与思考 XEN下的 调试方法 SHADOW PAGE 的基本操作

  11. Windows XPSysCall监控的实现 • 恶意代码样本分析结果 现场展示 …… ……

  12. Ubuntu 进程监控的实现 • 与Windows进程监控的区别 监控的原理一致,操作系统实现的差异造成信息获取的方法不同。 • Linux进程结构 所有进程都对应一个TASK_STRUCT TASK_STRUCT里面有一个成员叫做TASKS(双向链表) THREAD_INFO:ESP&0XFFFFE000 显示的这个内容的第一个指针(前4个字节)就是当前进程的TASK_STRUCT 获取PID、COMM等: TASK_STRUCT+OFFSET OFFSET如何确定?编写Linux kernel module程序输出所需参数偏移量

  13. Ubuntu 进程监控的实现 • 测试结果 只在xen的kernel中输出,验证性实验 (XEN) ETHER: process pid 0, process name swapper (XEN) ETHER: process pid f, process name kblockd/0 (XEN) ETHER: process pid 6d2, process name dbus-daemon-lau (XEN) ETHER: process pid 6d2, process name nm-dispatcher.a (XEN) ETHER: process pid 5bc, process name gnome-panel (XEN) ETHER: process pid 0, process name swapper (XEN) ETHER: process pid 4c5, process name udisks-daemon (XEN) ETHER: process pid 25, process name scsi_eh_1 (XEN) ETHER: process pid 0, process name swapper (XEN) ETHER: process pid 0, process name swapper (XEN) ETHER: process pid 652, process name gnome-screensav (XEN) ETHER: process pid 528, process name Xorg (XEN) ETHER: process pid 5af, process name gnome-power-man (XEN) ETHER: process pid 528, process name Xorg (XEN) ETHER: process pid 5af, process name gnome-power-man (XEN) ETHER: process pid 0, process name swapper (XEN) ETHER: process pid 0, process name swapper (XEN) ETHER: process pid 0, process name swapper

  14. 监控系统性能测试与分析 • 测试平台 Host OS:Ubuntu 10.10 AMD64 Xen Version: 4.0.1 Guest OS:Windows XP SP3 Benchmark Software: PCMark 05 • 测试结果

  15. 监控系统性能测试与分析 • Ether的测试结果

  16. 监控系统性能测试与分析 • 简单分析 开启监控后,对调用系统服务函数频繁的HDD相关操作和Web渲染操作影响较大,但仍在可以接受的范围内。对于文件解密操作,其主要是对CPU性能的测量,监控系统的引入造成的性能影响不大。 对比Ether的测试结果,大体一致。部分性能测试损失较高,推测可能是与时间计数器的设置(欺骗)有关。 性能损失的主要影响因素是用户态监控程序的引入,此结论与Ether的设计直接相关。但此种设计也有它的优势:更好的语义结果、更简单的实现方式。

  17. 遇到的问题与解决 问题1 问题3 Windows下SYSCALL 监控方法的实现 (Xen的实现差异与 Xen的结构) Ubuntu下SYSCALL 的监控方法 (如何实现?) 问题2 问题4 Xen SPT的操作 (页表的设计、结构 与实现函数) 单步调试的实现 (Guest OSCrash After Several Instructions Execute)

  18. 遇到的问题与解决 • Ubuntu Guest OS Syscall Monitor 任何时候Guest OS的VMCS寄存器中SYSENTER EIP都是0! (XEN) *** Guest State *** (XEN) CR0: actual=0x000000008005003b, shadow=0x000000008005003b, gh_mask=ffffffffffffffff (XEN) CR4: actual=0x00000000000026f0, shadow=0x00000000000006d0, gh_mask=ffffffffffffffff (XEN) CR3: actual=0x000000009d85dac0, target_count=0 (XEN) target0=0000000000000000, target1=0000000000000000 (XEN) target2=0000000000000000, target3=0000000000000000 (XEN) RSP = 0x00000000c07c1f34 (0x00000000c07c1f34) RIP = 0x00000000c05c6ca9 (0x00000000c05c6ca9) (XEN) RFLAGS=0x0000000000000007 (0x0000000000000007) DR7 = 0x0000000000000400 (XEN) Sysenter RSP=0000000000000000 CS:RIP=0000:0000000000000000 (XEN) CS: sel=0x0060, attr=0x0c09b, limit=0xffffffff, base=0x0000000000000000 (XEN) DS: sel=0x007b, attr=0x0c0f3, limit=0xffffffff, base=0x0000000000000000 (XEN) SS: sel=0x0068, attr=0x0c093, limit=0xffffffff, base=0x0000000000000000 (XEN) ES: sel=0x007b, attr=0x0c0f3, limit=0xffffffff, base=0x0000000000000000 (XEN) FS: sel=0x00d8, attr=0x08093, limit=0xffffffff, base=0x0000000000b45000 (XEN) GS: sel=0x00e0, attr=0x04091, limit=0x00000018, base=0x00000000c1408580 (XEN) GDTR: limit=0x000000ff, base=0x00000000c1400000 (XEN) LDTR: sel=0x0000, attr=0x1c000, limit=0xffffffff, base=0x0000000000000000 (XEN) IDTR: limit=0x000007ff, base=0x00000000c07c3000 (XEN) TR: sel=0x0080, attr=0x0008b, limit=0x0000206b, base=0x00000000c14063c0 (XEN) Guest PAT = 0x0000000000000000 (XEN) TSC Offset = 000000ed23a87eec (XEN) DebugCtl=0000000000000000 DebugExceptions=0000000000000000 (XEN) Interruptibility=0000 ActivityState=0000 (XEN) *** Host State *** ……

  19. 下一步的工作与计划 • 单步调试的实现 kernel? • 自动的恶意代码行为分析的实现 socket • 前一阶段工作小结 summary & paper?

  20. Thanks! Q&A

More Related