线程注入 根据进程名字来实现注入
来源:互联网 发布:苹果拍照软件搞怪2016 编辑:程序博客网 时间:2024/06/06 08:24
#include "stdafx.h"
#include "windows.h"
#include <TlHelp32.h>
#include "stdio.h"
// ========== 定义一个代码结构,本例为一个对话框============
struct MyData
{
int can1;
char sz[64]; // 对话框显示内容
DWORD dwMessageBox; // 对话框的地址
};
// ========== 远程线程的函数 ==============================
DWORD __stdcall RMTFunc(MyData *pData)
{
typedef int(__stdcall*MMessageBox)(HWND,LPCTSTR,LPCTSTR,UINT);
MMessageBox MsgBox = (MMessageBox)pData->dwMessageBox;
pData->can1=101010101;
MsgBox(NULL,_itoa(pData->can1,pData->sz,10), NULL, MB_OK);
return 0;
}
DWORD processNameToId(LPCTSTR lpszProcessName)
{
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
PROCESSENTRY32 pe;
pe.dwSize = sizeof(PROCESSENTRY32);
if (!Process32First(hSnapshot, &pe)) {
MessageBox(NULL,
"The frist entry of the process list has not been copyied to the buffer",
"Notice", MB_ICONINFORMATION | MB_OK);
return 0;
}
while (Process32Next(hSnapshot, &pe)) {
if (!strcmp(lpszProcessName, pe.szExeFile)) {
return pe.th32ProcessID;
}
}
return 0;
}
//提升进程访问权限
bool enableDebugPriv()
{
HANDLE hToken;
LUID sedebugnameValue;
TOKEN_PRIVILEGES tkp;
if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) {
return false;
}
if (!LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &sedebugnameValue)) {
CloseHandle(hToken);
return false;
}
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Luid = sedebugnameValue;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if (!AdjustTokenPrivileges(hToken, FALSE, &tkp, sizeof(tkp), NULL, NULL)) {
CloseHandle(hToken);
return false;
}
return true;
}
int main(int argc, char* argv[])
{
//提升进程访问权限
enableDebugPriv();
char szExeName[MAX_PATH] = { 0 };
printf("输入要插入的进程名字/n");
gets(szExeName);
printf("%c/n",szExeName);
//上面填写进程名字
DWORD dwProcessId = processNameToId(szExeName);
if (dwProcessId == 0) {
MessageBox(NULL, "The target process have not been found !",
"Notice", MB_ICONINFORMATION | MB_OK);
return -1;
}
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcessId);
if (!hProcess) {
MessageBox(NULL, "Open target process failed !", "Notice", MB_ICONINFORMATION | MB_OK);
return 0;
}
// ===== 获得需要创建REMOTETHREAD的进程句柄 ===============================
// ========= 代码结构 ================================================
MyData data;
ZeroMemory(&data, sizeof (MyData));
strcat(data.sz, "伙终于成功了 呵呵!!");
HINSTANCE hUser = LoadLibrary("user32.dll");
if (! hUser)
{
printf("Can not load library./n");
return 0;
}
data.dwMessageBox = (DWORD)GetProcAddress(hUser, "MessageBoxA");
FreeLibrary(hUser);
if (! data.dwMessageBox)
return 0;
// ======= 分配空间 ===================================================
void *pRemoteThread
= VirtualAllocEx(hProcess, 0,
1024*4, MEM_COMMIT|MEM_RESERVE,
PAGE_EXECUTE_READWRITE);
if (! pRemoteThread)
return 0;
if (! WriteProcessMemory(hProcess, pRemoteThread, &RMTFunc, 1024*4, 0))
return 0;
MyData *pData
= (MyData*)VirtualAllocEx(hProcess, 0,
sizeof (MyData), MEM_COMMIT,
PAGE_READWRITE);
if (!pData)
return 0;
if (! WriteProcessMemory(hProcess, pData, &data, sizeof (MyData), 0))
return 0;
// =========== 创建远程线程 ===========================================
HANDLE hThread
= CreateRemoteThread(hProcess, 0,
0, (LPTHREAD_START_ROUTINE)pRemoteThread,
pData, 0, 0);
if (! hThread)
{
printf("远程线程创建失败");
return 0;
}
CloseHandle(hThread);
VirtualFreeEx(hProcess, pRemoteThread, 1024*3, MEM_RELEASE);
VirtualFreeEx(hProcess, pData, sizeof (MyData), MEM_RELEASE);
CloseHandle(hProcess);
printf("Hello World!/n");
printf("插入%c进程成功/n输入回车退出程序。/n",szExeName);
gets(szExeName);
return 0;
}
- 线程注入 根据进程名字来实现注入
- Win XP下用远程线程注入来隐藏进程
- 注入进程 远程线程注入 与 hook注入
- .net实现线程注入
- VC++ 实现线程注入
- 用进程注入来实现一个壳(原理)
- 进程注入DLL实现(APC和远程线程创建)
- 使用远程线程来注入DLL
- 创建远程线程注入指定进程
- 进程枚举、线程注入,注册表等示例
- 线程注入
- 线程注入
- 线程注入
- 线程注入
- 线程注入
- 将注入进行到底--------远程线程实现 Dll 注入 汇编实现
- 使用annotation来实现依赖注入
- Dll注入-远线程注入
- 前言
- 如何在页面Page_Load时自动触发Button按钮的Command事件
- 初识APPFUSE
- 可不可以在page_load里判定是哪个控件引发的呢?
- Watsonxu Utility免费网络服务汇总
- 线程注入 根据进程名字来实现注入
- 关于制作TrueType字体(1)
- 今天正式决定,每天简短的几个字记录自己准备系统分析员考试的过程。
- .NET和J2EE该相互学习什么
- Task 5 Complete
- 六度分隔、六度空间(Six Degrees of Separation)理论
- 电磁辐射污染:让我们离你更远
- ADO.NET 的最佳实践技巧
- 删除的时候弹出提示的各种方法