vc++进程注入钩子DLL通用模块开源
2009-04-14 11:11
483 查看
#include "stdafx.h"
#include <windows.h>
#include <string>
#include "stdio.h"
#include <iostream>
using namespace std;
#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;
}
#include <windows.h>
#include <string>
#include "stdio.h"
#include <iostream>
using namespace std;
#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通用模块开源
- vc++进程注入钩子DLL通用模块
- VC dll 注入之钩子注入
- 进程注入(把DLL注入到进程)( 通过钩子、线程等方式)
- 通过安装WH_CALLWNDPROC全局钩子将DLL注入所有进行窗口过程的进程
- (开源) Ring3下的DLL注入工具 x86&x64(NtCreateThreadEx + LdrLoadDll方式实现,可以注入系统进程)
- VC DLL远程进程注入
- VC++实现监视系统的键盘操作(2) 创建记录键盘动作的全局钩子DLL
- VC++实现枚举进程与模块
- 远程注入DLL实现进程隐藏以及键盘记录器
- FastCGI进程意外退出,http错误404.3-NotFound 由于扩展配置问题 dll找不到找定的模块等 dz问题总结
- VC 利用DLL共享区间在进程间共享数据及进程间广播消息
- 进程监控模块配置与使用 ------ACE(开源项目)
- ring3层面函数HOOK从头来之(一)——无dll远程进程代码注入
- 企业管理平台开发项目(开源)功能模块 dll 基准源代码
- Hook任务栏时钟窗口(原理其实很简单,就是注入DLL到时钟窗口进程(explorer.exe))
- 无Dll插入进程,下载者VC源代码
- 无dll插入进程,下载者vc源代码
- 将dll从进程模块列表中移除并保持正常运行