跟踪 Windows API 调用
我目前正在开发 .NET/Python 中的一个工具,用于监视系统上的某些事件,例如编写特定的注册表项或创建具有特殊名称的文件。
我评估了许多可能性,并且由于我不必关心 WinXP 支持,因此我使用 Windows 事件跟踪来获取所有文件和注册表活动的实时流,并且这工作得很好(通过使用来自 NT 的事件)内核记录器)。
现在,我必须扩展我的工具来监视对某些 Windows API 函数(例如 WriteProcessMemory
、NtUnmapViewOfSection
或 VirtualAllocEx
)的所有调用。我发现许多工具允许我跟踪单个进程的所有 API 调用,但挂钩所有进程并不是一个好主意,不是吗?
现在我想知道是否有可能使用 ETW 来实现这一点。内核是否提供了任何提供程序来通知我 API 调用?如果没有,我还能做什么?
摘要:如果我想捕获 API 调用,是否必须挂钩每个进程?
I am currently working on a tool in .NET/Python that monitors certain events on a system, like writing specific registry keys or creating files with a special name.
I evaluated many possibilities, and as I don't have to care about WinXP support, I am using Event Tracing for Windows to get a real-time stream of all file and registry activities, and this works fine (by consuming events from the NT kernel logger).
Now, I have to extend my tool to monitor all calls to some Windows API functions like WriteProcessMemory
, NtUnmapViewOfSection
or VirtualAllocEx
. I found many tools that allows me to trace all API calls from a single process, but hooking all processes isn't a good idea, is it?
Now I wonder if if there is a possibility to use ETW for this. Is there any provider provided by the kernel that notifies me of API calls? If not, what else can I do?
Summary: If I want to catch API calls, do I have to hook every single process?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一般来说,拦截系统API调用有两种方法:用户模式或内核模式拦截。对于用户模式 API 拦截,您必须挂钩每个进程,以准确捕获/重定向对所需 API 函数的每个调用。内核模式拦截避免了挂钩每个进程的需要,但也需要高级的低级知识(以及交叉签名的代码签名证书以在内核模式下运行代码)。
有许多可用的库可以提供 API 挂钩功能,但我相信我所知道的所有库主要在用户模式下工作,即需要将系统范围的 DLL 注入到进程中。
Generally speaking, there are two approaches to intercepting system API calls; either user mode or kernel mode interception. For user mode API interception, you will have to hook every process to accurately capture/redirect every call to your desired API function. Kernel mode interception circumvents the need to hook every process, but also requires advanced low-level knowledge (and a cross-signed code signing certificate to run your code in kernel mode).
There are a number of libraries available that will provide API hooking functionality, but I believe the ones I know of all work primarily in user mode, i.e. requiring system-wide DLL injection into processes.