查看: 5028|回复: 18
收起左侧

[讨论] 杀软和EDR常用的R3钩子(ntdll hook)的原理介绍

[复制链接]
00006666
发表于 2025-7-29 10:34:57 | 显示全部楼层 |阅读模式
本帖最后由 00006666 于 2025-7-29 10:37 编辑

杀软和EDR常用的R3钩子(ntdll hook)的原理介绍,转载自之前看到的一篇技术文章  原文地址

Since Microsoft introduced Kernel Patch Protection (aka PatchGuard) in 2005, many modifications to the kernel are now prevented. Previously, security products monitored user mode calls from inside the kernel by hooking the SSDT. Since all Nt/Zw functions are implemented in the kernel, all user mode calls must go through the SSDT, and are therefore subject to SSDT hooks. Patch guard makes SSDT hooking off-limits, so many EDRs resorted to hooking ntdll.


A look at where security products place hooks before and after patch guard.

Since the SSDT exists in the kernel, user mode applications were not able to interfere with these hooks without loading a kernel driver. Now, the hooks are placed in user mode, alongside the application.

So, what does a user mode hook look like?


An example of a ntdll function before and after hooking.

To hook a function in ntdll.dll, most EDRs just overwrite the first 5 bytes of the function’s code with a jmp instruction. The jmp instruction will redirect code execution to some code within the EDR’s own DLL (which is automatically loaded into every process). After the CPU has been redirected to the EDR’s DLL, the EDR can perform security checks by inspecting the function parameters and return address. Once the EDR is done, it can resume the ntdll call by executing the overwritten instructions, then jumping to the location in ntdll right after the hook (jmp instruction).


Control flow example for hooked ntdll function.

In the above example, NtWriteFile is hooked. The green instructions are the original instructions from NtWriteFile. The first 3 instructions of NtWriteFile have been overwritten by the EDR’s hook (a jmp that redirects execution to a function named NtWriteFile in edr.dll). Whenever the EDR wants to call the real NtWriteFile, it executes the 3 overwritten instructions, then jumps to the 4th instruction of the hooked function to complete the syscall.

Whilst EDR hooks may vary slightly from vendor to vendor, the principal is still the same, and all share the same weakness: they’re located in user mode. Since both the hooks and the EDR’s DLL have to be placed inside every process’s address space, a malicious process can tamper with them.

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?快速注册

x

评分

参与人数 3经验 +16 人气 +5 收起 理由
yexo + 2 版区有你更精彩: )
白露为霜 + 16 感谢支持,欢迎常来: )
HEMM + 3 不明觉厉

查看全部评分

kafn_killer
发表于 2025-7-29 11:11:02 | 显示全部楼层
原来是这样
GDHJDSYDH
发表于 2025-7-29 11:35:03 | 显示全部楼层
怕重载NTDLL吧
00006666
 楼主| 发表于 2025-7-29 12:58:34 | 显示全部楼层

EDR Unhooking、Manually Mapping DLLs、Direct Syscalls、Indirect syscalls 都有可能绕过R3钩子
神龟Turmi
发表于 2025-7-29 16:13:42 | 显示全部楼层


更怕游戏反作弊(
我都在想会不会有什么黑产投递Battleye来致盲EDR


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?快速注册

x

评分

参与人数 1人气 +1 收起 理由
HEMM + 1 反作弊有用吗?怎么感觉好多作弊的

查看全部评分

GDHJDSYDH
发表于 2025-7-29 22:22:57 | 显示全部楼层
神龟Turmi 发表于 2025-7-29 16:13
更怕游戏反作弊(
我都在想会不会有什么黑产投递Battleye来致盲EDR

R3钩子还是太容易被绕了
驭龙
发表于 2025-7-29 22:40:02 | 显示全部楼层
现在的McAfee大部分功能都是R3的DLL从NTDLL.DLL输出,基本上可以说是弱不禁风的存在,只是没人针对而已

评分

参与人数 1人气 +3 收起 理由
辔繇 + 3 感谢提供分享

查看全部评分

隔山打空气
发表于 2025-7-30 10:29:17 | 显示全部楼层
这只是个例子 如有雷同请立刻打死厂商

想起了以前见过某个样本对NtWriteFile搞idsc的 太有生活了
00006666
 楼主| 发表于 2025-7-30 16:47:49 | 显示全部楼层
隔山打空气 发表于 2025-7-30 10:29
这只是个例子 如有雷同请立刻打死厂商

想起了以前见过某个样本对NtWriteFile搞idsc的 太有生活了

嗯,这个文章也说了  Whilst EDR hooks may vary slightly from vendor to vendor, the principal is still the same, and all share the same weakness
tdsskiller
发表于 2025-8-6 01:30:37 | 显示全部楼层
神龟Turmi 发表于 2025-7-29 16:13
更怕游戏反作弊(
我都在想会不会有什么黑产投递Battleye来致盲EDR

国内早就这么干了,360虚拟化被wegame腐乳
您需要登录后才可以回帖 登录 | 快速注册

本版积分规则

手机版|杀毒软件|软件论坛| 卡饭论坛

Copyright © KaFan  KaFan.cn All Rights Reserved.

Powered by Discuz! X3.4( 沪ICP备2020031077号-2 ) GMT+8, 2025-11-6 22:22 , Processed in 0.124150 second(s), 20 queries .

卡饭网所发布的一切软件、样本、工具、文章等仅限用于学习和研究,不得将上述内容用于商业或者其他非法用途,否则产生的一切后果自负,本站信息来自网络,版权争议问题与本站无关,您必须在下载后的24小时之内从您的电脑中彻底删除上述信息,如有问题请通过邮件与我们联系。

快速回复 客服 返回顶部 返回列表