一个远程注入的例子(让本机的所有程序弹出一个sylar对话框)
2016-04-15 14:22
190 查看
1
#include
"stdafx.h"
2
#include
"windows.h"
3
#include
"stdio.h"
4
#include
<Tlhelp32.h.>
5
/*熊健
6
2009.12.23 武汉
7
perfectxiong@gmail.com
8
/////////////////////////////////////////////*/
9
//
========== 定义一个代码结构,本例为一个对话框============
10
struct
MyData
11
{
12
char
sz[64];
//
对话框显示内容
13
DWORD dwMessageBox;
//
对话框的地址
14
};
15
16
//
========== 远程线程的函数 ==============================
17
DWORD __stdcall
RMTFunc(MyData *pData)
18
{
19
typedef
int(__stdcall*MMessageBox)(HWND,LPCTSTR,LPCTSTR,UINT);
20
MMessageBox MsgBox
= (MMessageBox)pData->dwMessageBox;
21
MsgBox(NULL, pData->sz,
NULL, MB_OK);
22
return
0;
23
}
24
25
int
inject(DWORD dwProcessId)
26
{
27
HANDLE hProcess
= OpenProcess(
28
PROCESS_ALL_ACCESS,
29
FALSE,
30
dwProcessId);
31
32
//
========= 代码结构 ================================================
33
MyData data;
34
ZeroMemory(&data,
sizeof (MyData));
35
strcat(data.sz,
"sylar");
36
HINSTANCE hUser
= LoadLibrary("user32.dll");
37
if
(! hUser)
38
{
39
printf("Can
not load library.\n");
40
return
0;
41
}
42
data.dwMessageBox
= (DWORD)GetProcAddress(hUser,
"MessageBoxA");
43
FreeLibrary(hUser);
44
if
(! data.dwMessageBox)
45
return
0;
46
47
//
======= 分配空间 ===================================================
48
void
*pRemoteThread
49
=
VirtualAllocEx(hProcess, 0,
50
1024*4,
MEM_COMMIT|MEM_RESERVE,
51
PAGE_EXECUTE_READWRITE);
52
if
(! pRemoteThread)
53
return
0;
54
if
(! WriteProcessMemory(hProcess,
pRemoteThread, &RMTFunc,
1024*4,
0))
55
return
0;
56
57
MyData
*pData
58
=
(MyData*)VirtualAllocEx(hProcess,
0,
59
sizeof
(MyData), MEM_COMMIT,
60
PAGE_READWRITE);
61
if
(!pData)
62
return
0;
63
64
if
(! WriteProcessMemory(hProcess,
pData, &data,
sizeof (MyData),
0))
65
return
0;
66
67
//
=========== 创建远程线程 ===========================================
68
HANDLE hThread
69
=
CreateRemoteThread(hProcess, 0,
70
0,
(LPTHREAD_START_ROUTINE)pRemoteThread,
71
pData,
0,
0);
72
if
(! hThread)
73
{
74
printf("远程线程创建失败");
75
return
0;
76
}
77
CloseHandle(hThread);
78
VirtualFreeEx(hProcess, pRemoteThread,
1024*3,
MEM_RELEASE);
79
VirtualFreeEx(hProcess, pData,
sizeof (MyData),
MEM_RELEASE);
80
CloseHandle(hProcess);
81
printf("Hello
World!\n");
82
return
1;
83
}
84
85
int
main(int argc,
char*
argv[])
86
{
87
//
===== 获得需要创建REMOTETHREAD的进程句柄 ===============================
88
//or
89
HANDLE hSnapshot
= NULL;
90
hSnapshot=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,NULL);
91
PROCESSENTRY32 pe;
92
pe.dwSize
=
sizeof(PROCESSENTRY32);
93
Process32First(hSnapshot,&pe);
94
do
95
{
96
//if(stricmp(pe.szExeFile,"NOTEPAD.EXE")==0)
97
//
{
98
inject(pe.th32ProcessID);
99
//
break;
100
//
}
101
}
102
while(Process32Next(hSnapshot,&pe)==TRUE);
103
CloseHandle (hSnapshot);
104
/*
105
HWND hWnd = FindWindow("notepad", NULL); // 以NOTEPAD为例
106
DWORD dwProcessId;
107
::GetWindowThreadProcessId(hWnd, &dwProcessId);
108
inject(dwProcessId);
109
*/
110
return
0;
111
}
112
113
#include
"stdafx.h"
2
#include
"windows.h"
3
#include
"stdio.h"
4
#include
<Tlhelp32.h.>
5
/*熊健
6
2009.12.23 武汉
7
perfectxiong@gmail.com
8
/////////////////////////////////////////////*/
9
//
========== 定义一个代码结构,本例为一个对话框============
10
struct
MyData
11
{
12
char
sz[64];
//
对话框显示内容
13
DWORD dwMessageBox;
//
对话框的地址
14
};
15
16
//
========== 远程线程的函数 ==============================
17
DWORD __stdcall
RMTFunc(MyData *pData)
18
{
19
typedef
int(__stdcall*MMessageBox)(HWND,LPCTSTR,LPCTSTR,UINT);
20
MMessageBox MsgBox
= (MMessageBox)pData->dwMessageBox;
21
MsgBox(NULL, pData->sz,
NULL, MB_OK);
22
return
0;
23
}
24
25
int
inject(DWORD dwProcessId)
26
{
27
HANDLE hProcess
= OpenProcess(
28
PROCESS_ALL_ACCESS,
29
FALSE,
30
dwProcessId);
31
32
//
========= 代码结构 ================================================
33
MyData data;
34
ZeroMemory(&data,
sizeof (MyData));
35
strcat(data.sz,
"sylar");
36
HINSTANCE hUser
= LoadLibrary("user32.dll");
37
if
(! hUser)
38
{
39
printf("Can
not load library.\n");
40
return
0;
41
}
42
data.dwMessageBox
= (DWORD)GetProcAddress(hUser,
"MessageBoxA");
43
FreeLibrary(hUser);
44
if
(! data.dwMessageBox)
45
return
0;
46
47
//
======= 分配空间 ===================================================
48
void
*pRemoteThread
49
=
VirtualAllocEx(hProcess, 0,
50
1024*4,
MEM_COMMIT|MEM_RESERVE,
51
PAGE_EXECUTE_READWRITE);
52
if
(! pRemoteThread)
53
return
0;
54
if
(! WriteProcessMemory(hProcess,
pRemoteThread, &RMTFunc,
1024*4,
0))
55
return
0;
56
57
MyData
*pData
58
=
(MyData*)VirtualAllocEx(hProcess,
0,
59
sizeof
(MyData), MEM_COMMIT,
60
PAGE_READWRITE);
61
if
(!pData)
62
return
0;
63
64
if
(! WriteProcessMemory(hProcess,
pData, &data,
sizeof (MyData),
0))
65
return
0;
66
67
//
=========== 创建远程线程 ===========================================
68
HANDLE hThread
69
=
CreateRemoteThread(hProcess, 0,
70
0,
(LPTHREAD_START_ROUTINE)pRemoteThread,
71
pData,
0,
0);
72
if
(! hThread)
73
{
74
printf("远程线程创建失败");
75
return
0;
76
}
77
CloseHandle(hThread);
78
VirtualFreeEx(hProcess, pRemoteThread,
1024*3,
MEM_RELEASE);
79
VirtualFreeEx(hProcess, pData,
sizeof (MyData),
MEM_RELEASE);
80
CloseHandle(hProcess);
81
printf("Hello
World!\n");
82
return
1;
83
}
84
85
int
main(int argc,
char*
argv[])
86
{
87
//
===== 获得需要创建REMOTETHREAD的进程句柄 ===============================
88
//or
89
HANDLE hSnapshot
= NULL;
90
hSnapshot=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,NULL);
91
PROCESSENTRY32 pe;
92
pe.dwSize
=
sizeof(PROCESSENTRY32);
93
Process32First(hSnapshot,&pe);
94
do
95
{
96
//if(stricmp(pe.szExeFile,"NOTEPAD.EXE")==0)
97
//
{
98
inject(pe.th32ProcessID);
99
//
break;
100
//
}
101
}
102
while(Process32Next(hSnapshot,&pe)==TRUE);
103
CloseHandle (hSnapshot);
104
/*
105
HWND hWnd = FindWindow("notepad", NULL); // 以NOTEPAD为例
106
DWORD dwProcessId;
107
::GetWindowThreadProcessId(hWnd, &dwProcessId);
108
inject(dwProcessId);
109
*/
110
return
0;
111
}
112
113
相关文章推荐
- Spring 声明式事务使用
- Codevs 1222 信与信封问题 二分图匹配,匈牙利算法
- 字体,设置苹果字体,中文乱码等。
- 简易效率的抽奖算法(转)
- iOS-上拉刷新,下拉加载-----------详解
- 解决MySQL5.7安装后没有data文件夹无法登录的问题
- 做单数字每格的自定义手机号码输入框
- H264编码 封装成MP4格式 视频流 RTP封包
- c语言编写cgi程序,无法加载lib文件的问题
- 存储持续性,作用域和链接性
- 百度贴吧推广技巧:故事型营销思维
- linux下常用打包、解压方法(tar、bz2、rar)详解
- vs2008命令窗口使用
- Asp.net js获取CheckBoxlist 和 Radiobuttonlist
- 最新的统计机器翻译系统教程(不定期更新)
- 自己用c++写的简单成绩管理系统框架
- struts2.xml的自带校验的使用
- SQL注入式攻击
- guava、protobuf、guice浅析
- 讯飞语音包实现Android语音理解①