【问题标题】:C++ Hooking kernel32.dll OpenProcess with detoursC ++ Hook kernel32.dll OpenProcess 与弯路
【发布时间】:2016-02-07 06:33:08
【问题描述】:

我正在尝试从 Kernel32.dll 中挂钩 OpenProcess,以防止所谓的“injector”程序注入其他 dll进入我的流程:

// -------------------------------------------------------------------
HANDLE WINAPI myOpenProcess(DWORD dwDesiredAccess, BOOL  bInheritHandle, DWORD dwProcessId)
{
    //

    if (dwDesiredAccess == PROCESS_ALL_ACCESS || dwDesiredAccess == PROCESS_VM_OPERATION ||
        dwDesiredAccess == PROCESS_VM_READ || dwDesiredAccess == PROCESS_VM_WRITE)
    {
        printf("Blcoked Process ID : %d , DesiredAccess : %d ", dwProcessId, dwDesiredAccess);

        return false;
    }

    //

    return dOpenProcess(dwDesiredAccess, bInheritHandle, dwProcessId);
}

如果有人打开“injecting”的过程,我需要添加什么才能“检测”? 我不想“预防”,我想“检测”注射并决定做什么。

【问题讨论】:

标签: c++ windows winapi dll hook


【解决方案1】:

该图描述了注入器通常将 dll 注入另一个进程的步骤。你的程序应该做行为分析来决定它是否注入。您需要挂钩其他 api,例如 VirtualAlloc \ WriteProcessMemoryCreateRemoteThread 等。

下面显示了分析喷油器流量和 在需要时阻止执行。喷油器使用多种技术 注入 dll,以下内容不足以满足所有方法。

//
//HookOpenProcess keep track of opened process handle
//
HANDLE process = OpenProcess(PROCESS_ALL_ACCESS, FALSE, procID);

/*
HookVirtualAlloc  Check whether the first param is openprocess handle :: Make the suspicion level 3
*/
LPVOID arg = (LPVOID)VirtualAllocEx(process, NULL, ...);

/*
HookWriteProcessMemory  Check whether the first param is openprocess handle :: Make the suspicion level 2
*/
int n = WriteProcessMemory(process, .....);

/*
HookCreateRemoteThread Check whether the first param is openprocess handle :: Make the suspicion level 1 and block it from execution
*/
HANDLE threadID = CreateRemoteThread(process, .........);

【讨论】:

  • 非常感谢您的回答,没问题,我可以钩任何东西,您有时间给我展示和示例吗?
  • 我似乎无法做你写给我的事情......“检查第一个参数是否是 openprocess 句柄”我应该如何对 VirtualAllocEx 执行此操作......
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-26
  • 2010-11-12
  • 2015-04-09
  • 1970-01-01
  • 2010-12-28
  • 1970-01-01
相关资源
最近更新 更多