有没有办法使用内核模式驱动程序在 64 位版本上挂钩 Windows 系统调用? (不禁用PG)

问题描述 投票:0回答:1

有没有办法在 64 位 Windows 版本上挂钩 WinAPI 系统调用,而不禁用 PG(补丁防护)?使用内核模式驱动程序进行 SSDT 挂钩不是一种选择,因为补丁防护在检测到挂钩时会使系统崩溃。

例如,一个进程想要调用

CreateProcessA
,我如何根据传递给它的参数来阻止(或允许)它? (但是,我想具体了解如何挂钩任何或大多数 API 函数)

Windows Defender 会执行此操作,如果您尝试运行

sc query
它将起作用,但运行
sc stop WinDefend
将触发威胁警报。

windows winapi hook system-calls wdk
1个回答
0
投票

我可以根据我的理解为您提供一个伪代码,这对于创建系统范围的钩子来说有点高级。显然,实际的实施将是一个乏味且漫长的过程。

// Define a function pointer type for the original CreateProcessA function
// This is necessary to call the original function after interception
Define function pointer LPFN_CREATEPROCESSA

// Declare a global pointer to the original CreateProcessA function
Declare pOriginalCreateProcessA as LPFN_CREATEPROCESSA

// Define the detoured function for CreateProcessA
// This function will replace the original CreateProcessA and perform custom logic
Define function MyCreateProcessA with the same signature as CreateProcessA:
    Log information about the process being created
    Call the original CreateProcessA function to create the process
    Return the result of the original CreateProcessA function

// Entry point for the DLL
Define function DllMain:
    If DLL_PROCESS_ATTACH:
        // Initialize Detours library
        Begin transaction for Detours library
        Update thread for Detours library
        
        // Detour the CreateProcessA function
        Save the address of the original CreateProcessA function
        Attach the detoured function MyCreateProcessA to CreateProcessA
        
        // Finalize the transaction
        Commit the transaction for Detours library
    End if

    Return TRUE to indicate successful initialization
© www.soinside.com 2019 - 2024. All rights reserved.