|
所在平台: Udemy |
课程主页: https://www.udemy.com/course/windows-api-hooking/
课程评论:没有评论
《Windows API Hooking》课程总结 本课程深入探讨了Windows API Hooking技术,这是一种强大的过程控制机制,允许开发者在不修改源代码的情况下,拦截和修改函数调用。课程从一个生动的类比开始,将Hooking比作“控制”——通过拦截函数调用来检查传入的参数,从而实现对程序的行为进行分析和干预。 **核心概念与技术:** * **5字节内联Hooking (5-Byte Inline Hooking):** * **原理:** 将目标函数的前5个字节替换为一个跳转指令,该指令指向自定义的Hook函数。 * **流程:** 当目标函数被调用时,控制权首先转移到Hook函数。在Hook函数中,可以检查原始函数接收到的参数,然后将原始的5个字节恢复到目标函数中,再调用原始函数。最后,根据检查结果决定是允许还是阻止该函数调用。 * **IAT Hooking (Import Address Table Hooking):** * **原理:** 修改导入地址表(IAT)中的函数指针。IAT记录了程序调用外部DLL函数时的实际地址。 * **流程:** 将IAT中指向合法函数的地址修改为指向自定义的Hook函数。Hook函数接收参数,然后可以选择调用原始函数。 * **进程隐藏 (Hiding Processes from User Mode Processes):** * **技术:** 利用`NtQuerySystemInformation`函数中的`SYSTEM_PROCESS_INFORMATION`枚举来隐藏进程。 * **方法:** `SYSTEM_PROCESS_INFORMATION`以链表形式存储进程信息。通过修改链表中前一个进程的“下一个进程”指针,使其直接指向当前进程的“下一个进程”,可以有效地将目标进程从系统中移除,使其在任务管理器等用户模式进程监视工具中不可见。 * **DLL 解Hooking (DLL Unhooking):** * **机制:** 当DLL被Hook时,由于杀毒软件(AV)/终端检测与响应(EDR)通常不会直接修改磁盘上的DLL(以免影响系统性能),它们会在内存中对其进行Hook。 * **方法:** 可以通过获取DLL的干净版本(可以从磁盘加载或从一个挂起的进程中获取),然后将干净的`.text`(代码)段复制到自己的进程内存中,来解除Hook。 **应用场景:** Hooking技术在网络安全领域有着广泛的应用,例如: * **杀毒软件/EDR:** 监控和阻止恶意软件的行为,如内存写入、远程线程创建等。 * **调试与分析:** 检查程序运行时的参数和执行流程,用于软件调试和逆向工程。 * **功能扩展:** 在不修改原始程序的情况下,增加新的功能或修改现有功能。 本课程为学习者提供了理解和实践Windows API Hooking所需的核心知识和技术,对于网络安全研究人员、恶意软件分析师和系统程序员来说,是一门非常有价值的课程。
We often hear the words in movies "he has hooks on you". this means he is controlling you.In same analogy, hooking here means controlling the function flow to examine the parameters that are being passed to the function.AV/EDR hooks some important functions in various dlls.NtVirtualAllocateMemory, ZwWriteVirtualMemory, NtCreateRemoteThread, etc are hooked5 BYTE INLINE HOOKINGIn this inline hooking, we replace first 5 bytes of legit function with a jump offset to our function.When the legit function is called, the control flow redirects to our address along with the original arguments.Now we restore those 5 bytes at legit function and then inspect the arguments for any malicious usage.we can then proceed to block or allow the functionIAT HOOKINGFirstthunk address in import descriptor table points to address of legit functions.We can overwrite this address to our malicious function.we receive arguments and then call legit functionHIDING PROCESSES FROM USER MODE PROCESSProcesses like task manager uses NtQuerySystemInformation with SYSTEM_PROCESS_INFORMATION to get all processes information.All of these processes are in linked list.We can hide our desired process by modifying the next link of previous process to the next process.DLL UNHOOKINGWe can unhook the hooked dlls by copying clean version of dll's.text section into our process.AV/EDR does not hook dlls on disk because it slows down the system heavily.We can acquire clean copy from disk or from a suspended process