-
Notifications
You must be signed in to change notification settings - Fork 29
/
ZeusCommon.cpp
312 lines (281 loc) · 7.95 KB
/
ZeusCommon.cpp
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
/*
* ZeusCommon.cpp : Contains routines that are used
* many times throughout the code.
*
* Written By : @Ice3man
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "Zeus.h"
#include <TlHelp32.h> //Required for process Enumeration
/*
* ZeusOpenProcess : Opens a process for operation
* @Arguments :
* @ProcID : Process Identifier
*
* @Return :
* @HANDLE : Handle to target process
*/
HANDLE ZeusOpenProcess(int ProcID)
{
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, ProcID);
if (hProcess == NULL)
{
#ifdef _DEBUG_
printf("\n[!] Error : Could Not Open A Handle to the process %i !", ProcID);
#endif
ExitProcess(1);
}
/*
* If correct handle, return it.
*/
return hProcess;
}
/*
* ZeusWriteDllStrMemory : Writes the Dll Location String
* to a process memory. It uses the local API's to write a
* dll location string.
*
* @Arguments :
* @szDllLoc : Dll Location String
* @hProcess : HANDLE to the Target Process
*
* @Return :
* @LPVOID : A Pointer to the dll string location in target process
*/
LPVOID ZeusWriteDllStrMemory(char *szDllLoc, HANDLE hProcess)
{
/*
* Allocate some memory for dll location string
*/
LPVOID arg = (LPVOID)VirtualAllocEx(hProcess, NULL, strlen(szDllLoc), MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
if(arg==NULL)
{
#ifdef _DEBUG_
printf("\n[!] Error : Could Not Allocate Memory for Dll !");
#endif
ExitProcess(1);
}
printf("\n[+] Allocated %d Bytes in Target Process !", strlen(szDllLoc));
/*
* Write the location to the target process's memory
*/
int ret = WriteProcessMemory(hProcess, arg, szDllLoc, strlen(szDllLoc), NULL);
if(ret == 0)
{
#ifdef _DEBUG_
printf("\n[!] Error : No bytes were written to the target process !");
#endif
ExitProcess(1);
}
printf("\n[+] Wrote %d Bytes to the Target Process !", strlen(szDllLoc));
return arg;
}
/*
* ZeusSetDebugPrivileges : Enables SeDebugPrivilege on
* the program. Requires Administrator Rights
*
* @Arg : None
: @Ret : None
*/
int ZeusSetDebugPrivileges(void) {
TOKEN_PRIVILEGES priv = {0};
HANDLE hToken = NULL;
/*
* Open Token for adjusting privileges and then
* apply the new token using Adjust Token privileges
* NOTE : Not my own code. Taken from github
*/
if( OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken ) ) {
priv.PrivilegeCount = 1;
priv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if( LookupPrivilegeValue( NULL, SE_DEBUG_NAME, &priv.Privileges[0].Luid ) ) {
if(AdjustTokenPrivileges( hToken, FALSE, &priv, 0, NULL, NULL ) == 0) {
#ifdef _DEBUG_
printf("\n[!] Error : An error occured Setting Debug Privileges ! [%u]\n",GetLastError());
#endif
ExitProcess(1);
}
}
printf("\n[+] Successfully enabled SeDebugPrivilege !");
CloseHandle( hToken );
}
return GetLastError();
}
/*
* ZeusListProcess : Lists all the processes running
* on the system.
* It prints all the processes with their process id .
*
* @Arg and @Ret : Void
*/
int ZeusListProcess()
{
PROCESSENTRY32 pe;
HANDLE thSnapshot;
BOOL retval, ProcFound = FALSE;
thSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if(thSnapshot == INVALID_HANDLE_VALUE)
{
#ifdef _DEBUG_
printf("\n[!] Error: unable to create toolhelp snapshot");
#endif
ExitProcess(1);
}
pe.dwSize = sizeof(PROCESSENTRY32);
retval = Process32First(thSnapshot, &pe);
printf("\n\n[*] Process List :-\n");
while(retval)
{
/*
* Prints the running process Here. It could
* be used in any kind of program
*/
printf("\n[+] Process Name : %s", pe.szExeFile);
printf("\t Process ID : %d", pe.th32ProcessID);
retval = Process32Next(thSnapshot,&pe);
pe.dwSize = sizeof(PROCESSENTRY32);
}
}
/*
* ZeusGetProcessIdFromName : Returns the process ID Of any
* given process given it's name.
*
* @Arguments :
* @procName : A String containing name of the process
*
* @Return :
* @pe.th32ProcessId : Process Id Associated with that process
*/
unsigned long ZeusGetProcessIdFromName(char *procName)
{
PROCESSENTRY32 pe;
HANDLE thSnapshot;
BOOL retval, ProcFound = FALSE;
thSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if(thSnapshot == INVALID_HANDLE_VALUE)
{
#ifdef _DEBUG_
printf("\n[!] Error: unable to create toolhelp snapshot");
#endif
ExitProcess(1);
}
pe.dwSize = sizeof(PROCESSENTRY32);
retval = Process32First(thSnapshot, &pe);
while(retval)
{
/*
* Compare the String given with enumerated
* one.
*/
if(strstr(pe.szExeFile, procName) )
{
// Found
ProcFound = TRUE;
break;
}
retval = Process32Next(thSnapshot,&pe);
pe.dwSize = sizeof(PROCESSENTRY32);
}
return pe.th32ProcessID;
}
/*
* ZeusPrintInfo : Prints the current version
* and other information of the operating system.
*
* @Arg And @Ret : VOID
*/
void ZeusPrintInfo()
{
char szMachine[128];
char szUser[128];
DWORD dw;
OSVERSIONINFO os_version;
os_version.dwOSVersionInfoSize = sizeof(os_version);
if (GetVersionEx(&os_version))
{
if (os_version.dwMajorVersion == 5)
{
#ifdef _DEBUG_
printf("\n[+] OS version: Windows XP");
#endif
}
else if (os_version.dwMajorVersion == 6 && os_version.dwMinorVersion == 0)
{
#ifdef _DEBUG_
printf("\n[+] OS version: Windows Vista");
#endif
}
else if (os_version.dwMajorVersion == 6 && os_version.dwMinorVersion == 1)
{
#ifdef _DEBUG_
printf("\n[+] OS version: Windows 7");
#endif
}
}
else
printf("\n[-] OS version detect failed.");
GetComputerName(szMachine, &dw);
printf("\n[+] Computer Name : %s", szMachine);
GetUserName(szUser, &dw);
printf("\n[+] User Name : %s", szUser);
return;
}
/*
* ZeusGetThreadID : Get's a thread ID from
* a process.
*
* @Args : Process ID
* @Ret : Thread ID
*/
DWORD ZeusGetThreadID(DWORD pid)
{
HANDLE h = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
if (h != INVALID_HANDLE_VALUE)
{
THREADENTRY32 te;
te.dwSize = sizeof(te);
if (Thread32First(h, &te))
{
do
{
if (te.dwSize >= FIELD_OFFSET(THREADENTRY32, th32OwnerProcessID) + sizeof(te.th32OwnerProcessID))
{
if (te.th32OwnerProcessID == pid)
{
HANDLE hThread = OpenThread(READ_CONTROL, FALSE, te.th32ThreadID);
if (!hThread)
{
printf("\n[-] Error: Couldn't get thread handle\n");
ExitProcess(1);
}
else
return te.th32ThreadID;
}
}
} while (Thread32Next(h, &te));
}
}
CloseHandle(h);
return (DWORD)0;
}