vc++进程注入钩子DLL通用模块开源
2021/4/26 7:28:03
本文主要是介绍vc++进程注入钩子DLL通用模块开源,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
vc++进程注入钩子DLL通用模块开源
#include "stdafx.h"
#include
#define DEF_BUF_SIZE 1024
// 用于存储注入模块DLL的路径全名
char szDllPath[DEF_BUF_SIZE] = {0} ;
// 使用远程线程向指定ID的进程注入模块
BOOL InjectModuleToProcessById ( DWORD dwProcessId )
{
if ( dwProcessId == 0 )
return FALSE ;
// 打开进程
HANDLE hProcess = OpenProcess ( PROCESS_ALL_ACCESS, FALSE, dwProcessId ) ;
if ( hProcess == NULL )
return FALSE ;
//申请存放文件名的空间
UINT nLen = (UINT)strlen ( szDllPath ) + 1;
LPVOID lpRemoteDllName = VirtualAllocEx ( hProcess, NULL, nLen, MEM_COMMIT, PAGE_READWRITE ) ;
if ( lpRemoteDllName == NULL )
{
printf ( "[ERROR]VirtualAllocEx(%d)/n", GetLastError() );
return FALSE ;
}
//把dll文件名写入申请的空间
if ( WriteProcessMemory ( hProcess, lpRemoteDllName, szDllPath, nLen, NULL) == FALSE )
{
printf ( "[ERROR]WriteProcessMemory(%d)/n", GetLastError() );
return FALSE ;
}
//获取动态链接库函数地址
HMODULE hModule = GetModuleHandle ( L"kernel32.dll" ) ;
LPTHREAD_START_ROUTINE fnStartAddr = ( LPTHREAD_START_ROUTINE )GetProcAddress(hModule,"LoadLibraryA") ;
if ( (DWORD)fnStartAddr == 0 )
{
printf ( "[ERROR]GetProcAddress(%d)/n", GetLastError() );
return FALSE ;
}
//创建远程线程
HANDLE hRemoteThread = CreateRemoteThread ( hProcess, NULL, 0,fnStartAddr, lpRemoteDllName, 0, NULL ) ;
if ( hRemoteThread == NULL )
{
printf ( "[ERROR]CreateRemoteThread(%d)/n", GetLastError() );
return FALSE ;
}
// 等待远程线程结束
if ( WaitForSingleObject ( hRemoteThread, INFINITE ) != WAIT_OBJECT_0 )
{
printf ( "[ERROR]WaitForSingleObject(%d)/n", GetLastError() );
return FALSE ;
}
CloseHandle ( hRemoteThread ) ;
CloseHandle ( hModule ) ;
CloseHandle ( hProcess ) ;
return TRUE ;
}
int _tmain(int argc, _TCHAR* argv[])
{
// 取得当前工作目录路径
GetCurrentDirectoryA ( DEF_BUF_SIZE, szDllPath ) ;
// 生成注入模块DLL的路径全名
strcat ( szDllPath, "//DLL.dll" ) ;
DWORD dwProcessId = 0 ;
// 接收用户输入的目标进程ID
while ( printf ( "请输入目标进程ID:" ) && cin >> dwProcessId && dwProcessId > 0 )
{
BOOL bRet = InjectModuleToProcessById ( dwProcessId ) ;
printf ( bRet ? "注入成功!/n":"注入失败!/n") ;
}
return 0;
}
这篇关于vc++进程注入钩子DLL通用模块开源的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-29Elasticsearch慢查询日志配置
- 2024-05-29揭秘华为如此多成功项目的产品关键——Charter模板
- 2024-05-29海外IDC业务拓展的7大挑战
- 2024-05-29InLine Chat功能优化对标Github Copilot,CodeGeeX带来更高效、更直观的编程体验!
- 2024-05-29CodeGeeX 智能编程助手 6 项功能升级,在Visual Studio插件市场霸榜2周!
- 2024-05-29AutoMQ 生态集成 Apache Doris
- 2024-05-292024年IDC行业的深度挖掘:机遇、挑战与未来展望
- 2024-05-29五款扩展组件齐发 —— Volcano、Keda、Crane-scheduler 等,邀你体验
- 2024-05-29AutoMQ 对象存储数据高效组织的秘密: Compaction
- 2024-05-29活动预告|来 GIAC 大会听大数据降本利器:AutoMQ 基于云原生重新设计的 Kafka