-
-
[旧帖] [分享]dll注入简化2 0.00雪花
-
发表于: 2012-6-21 11:24 1182
-
dll简化注入2
(错误请指正,谢谢了)
仿照《dll简化注入》三步
3步:
1,运行目标(被插入的)进程FlashPlayer.exe
2, 生成想插入的块,Inject.dll
3. 生成主线程main.exe,运行main.exe
这里的函数BOOL Inject(DWORD dwProcessId/*进程ID*/, PCWSTR pszLibFile/*DLL路径和名称*/);dwProcessId参数由函数DWORD GetTaskManagerProcessID( HWND hwnd )返回得到,GetTaskManagerProcessID()内部调用GetWindowThreadProcessId(hwnd, &pID),而GetWindowThreadProcessId()是VC++平台SDK函数,2个参数hwnd,&pID,pID 是GetTaskManagerProcessID()内部栈内设定的参数,被GetWindowThreadProcessId()得到所需的线程ID,返回到pID的地址处,再由GetTaskManagerProcessID()返回其值,具体见代码,而hwnd是由
HWND FindWindow(
LPCTSTR lpClassName, // class name
LPCTSTR lpWindowName // window name
) ,得到,其中lpClassName
是类名,对于本例是FlashPlayer的 "ShockwaveFlash",要有引号,lpWindowName是 所打开的进程的窗口名,这里是"Adobe Flash Player 10",这 2个参数可以由VC++的spy++得到,看:运行FlashPlayer.exe程序,打开spy++,
点击spy++的spy下拉菜单的windows,得到句柄008D050E ,Caption是"Adobe Flash Player 10",类是"ShockwaveFlash",(注:这里的引号是西文字符,)如果没运行FlashPlayer.exe,只是简单的给个弹出消息,并返回,
Main.exe程序的代码:
#include <iostream.h>
#include "stdafx.h"
#include <tlhelp32.h>
#include <stdio.h>
#include <Windows.h>
BOOL Inject(DWORD dwProcessId/*进程ID*/, PCWSTR pszLibFile/*DLL路径和名称*/);
DWORD GetTaskManagerProcessID( HWND hwnd );
void main(void)
{
HWND hwnd = FindWindow("ShockwaveFlash","Adobe Flash Player 10");
if(hwnd==NULL)
{
MessageBox(NULL,"Error,No thread running!","Error",MB_OK);
return ;
}
DWORD processId = GetTaskManagerProcessID( hwnd );
Inject(processId,L"D:\\123\\Inject1\\Debug\\Inject1.dll");
//这里的目录要变成你的*.dll的具体目录,不要忘前加 L
//processId由DWORD processId = GetTaskManagerProcessID( hwnd )返回得到,
}
BOOL Inject(DWORD dwProcessId/*进程ID*/, PCWSTR pszLibFile/*DLL路径和名称*/)
{
BOOL bOk = FALSE;
HANDLE hProcess = NULL, hThread = NULL;
PWSTR pszLibFileRemote = NULL;
__try {
// 获取目标进程的句柄
hProcess = OpenProcess(
PROCESS_QUERY_INFORMATION | // Required by Alpha
PROCESS_CREATE_THREAD | // For CreateRemoteThread
PROCESS_VM_OPERATION | // For VirtualAllocEx/VirtualFreeEx
PROCESS_VM_WRITE, // For WriteProcessMemory
FALSE, dwProcessId);
if (hProcess == NULL) __leave;
// 计算DLL路径的长度
int cch = 1 + lstrlenW(pszLibFile);
int cb = cch * sizeof(wchar_t);
//在远程进程为DLL的名字和路径分配内存
pszLibFileRemote = (PWSTR)
VirtualAllocEx(hProcess, NULL, cb, MEM_COMMIT, PAGE_READWRITE);
if (pszLibFileRemote == NULL) __leave;
//把路径复制的远程进程的内存中
if (!WriteProcessMemory(hProcess, pszLibFileRemote,
(PVOID) pszLibFile, cb, NULL)) __leave;
//获取LoadLibraryW 在Kernel32.dll中的实际内存地址
PTHREAD_START_ROUTINE pfnThreadRtn = (PTHREAD_START_ROUTINE)
GetProcAddress(GetModuleHandle(TEXT("Kernel32")), "LoadLibraryW");
if (pfnThreadRtn == NULL) __leave;
//创建远程线程
hThread = CreateRemoteThread(hProcess, NULL, 0,
pfnThreadRtn, pszLibFileRemote, 0, NULL);
if (hThread == NULL) __leave;
// 等待线程结束
WaitForSingleObject(hThread, INFINITE);
bOk = TRUE;
}
__finally {
// 释放内存
if (pszLibFileRemote != NULL)
VirtualFreeEx(hProcess, pszLibFileRemote, 0, MEM_RELEASE);
if (hThread != NULL)
CloseHandle(hThread);
if (hProcess != NULL)
CloseHandle(hProcess);
}
return(bOk);
}
DWORD GetTaskManagerProcessID( HWND hwnd )
{
DWORD pID = 0;
GetWindowThreadProcessId( hwnd, &pID );
return pID;
}
FlashPlayer.exe,main.exe,Inject1文件夹,dll注入简化2.doc 都打包在dll注入简化2.rar 里 ,
都是抄的,没什么技术含量,大牛笑笑!全当备份了!
(错误请指正,谢谢了)
仿照《dll简化注入》三步
3步:
1,运行目标(被插入的)进程FlashPlayer.exe
2, 生成想插入的块,Inject.dll
3. 生成主线程main.exe,运行main.exe
这里的函数BOOL Inject(DWORD dwProcessId/*进程ID*/, PCWSTR pszLibFile/*DLL路径和名称*/);dwProcessId参数由函数DWORD GetTaskManagerProcessID( HWND hwnd )返回得到,GetTaskManagerProcessID()内部调用GetWindowThreadProcessId(hwnd, &pID),而GetWindowThreadProcessId()是VC++平台SDK函数,2个参数hwnd,&pID,pID 是GetTaskManagerProcessID()内部栈内设定的参数,被GetWindowThreadProcessId()得到所需的线程ID,返回到pID的地址处,再由GetTaskManagerProcessID()返回其值,具体见代码,而hwnd是由
HWND FindWindow(
LPCTSTR lpClassName, // class name
LPCTSTR lpWindowName // window name
) ,得到,其中lpClassName
是类名,对于本例是FlashPlayer的 "ShockwaveFlash",要有引号,lpWindowName是 所打开的进程的窗口名,这里是"Adobe Flash Player 10",这 2个参数可以由VC++的spy++得到,看:运行FlashPlayer.exe程序,打开spy++,
点击spy++的spy下拉菜单的windows,得到句柄008D050E ,Caption是"Adobe Flash Player 10",类是"ShockwaveFlash",(注:这里的引号是西文字符,)如果没运行FlashPlayer.exe,只是简单的给个弹出消息,并返回,
Main.exe程序的代码:
#include <iostream.h>
#include "stdafx.h"
#include <tlhelp32.h>
#include <stdio.h>
#include <Windows.h>
BOOL Inject(DWORD dwProcessId/*进程ID*/, PCWSTR pszLibFile/*DLL路径和名称*/);
DWORD GetTaskManagerProcessID( HWND hwnd );
void main(void)
{
HWND hwnd = FindWindow("ShockwaveFlash","Adobe Flash Player 10");
if(hwnd==NULL)
{
MessageBox(NULL,"Error,No thread running!","Error",MB_OK);
return ;
}
DWORD processId = GetTaskManagerProcessID( hwnd );
Inject(processId,L"D:\\123\\Inject1\\Debug\\Inject1.dll");
//这里的目录要变成你的*.dll的具体目录,不要忘前加 L
//processId由DWORD processId = GetTaskManagerProcessID( hwnd )返回得到,
}
BOOL Inject(DWORD dwProcessId/*进程ID*/, PCWSTR pszLibFile/*DLL路径和名称*/)
{
BOOL bOk = FALSE;
HANDLE hProcess = NULL, hThread = NULL;
PWSTR pszLibFileRemote = NULL;
__try {
// 获取目标进程的句柄
hProcess = OpenProcess(
PROCESS_QUERY_INFORMATION | // Required by Alpha
PROCESS_CREATE_THREAD | // For CreateRemoteThread
PROCESS_VM_OPERATION | // For VirtualAllocEx/VirtualFreeEx
PROCESS_VM_WRITE, // For WriteProcessMemory
FALSE, dwProcessId);
if (hProcess == NULL) __leave;
// 计算DLL路径的长度
int cch = 1 + lstrlenW(pszLibFile);
int cb = cch * sizeof(wchar_t);
//在远程进程为DLL的名字和路径分配内存
pszLibFileRemote = (PWSTR)
VirtualAllocEx(hProcess, NULL, cb, MEM_COMMIT, PAGE_READWRITE);
if (pszLibFileRemote == NULL) __leave;
//把路径复制的远程进程的内存中
if (!WriteProcessMemory(hProcess, pszLibFileRemote,
(PVOID) pszLibFile, cb, NULL)) __leave;
//获取LoadLibraryW 在Kernel32.dll中的实际内存地址
PTHREAD_START_ROUTINE pfnThreadRtn = (PTHREAD_START_ROUTINE)
GetProcAddress(GetModuleHandle(TEXT("Kernel32")), "LoadLibraryW");
if (pfnThreadRtn == NULL) __leave;
//创建远程线程
hThread = CreateRemoteThread(hProcess, NULL, 0,
pfnThreadRtn, pszLibFileRemote, 0, NULL);
if (hThread == NULL) __leave;
// 等待线程结束
WaitForSingleObject(hThread, INFINITE);
bOk = TRUE;
}
__finally {
// 释放内存
if (pszLibFileRemote != NULL)
VirtualFreeEx(hProcess, pszLibFileRemote, 0, MEM_RELEASE);
if (hThread != NULL)
CloseHandle(hThread);
if (hProcess != NULL)
CloseHandle(hProcess);
}
return(bOk);
}
DWORD GetTaskManagerProcessID( HWND hwnd )
{
DWORD pID = 0;
GetWindowThreadProcessId( hwnd, &pID );
return pID;
}
FlashPlayer.exe,main.exe,Inject1文件夹,dll注入简化2.doc 都打包在dll注入简化2.rar 里 ,
都是抄的,没什么技术含量,大牛笑笑!全当备份了!
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课
赞赏
他的文章
- PE文件头所在页面的属性如何设置? 913
- [分享]几个内核结构1 983
- [分享]dll注入简化2 1183
- [分享][分享]dll简化注入 1996
- 托盘程序(Tray) 1092
看原图
赞赏
雪币:
留言: