-
Notifications
You must be signed in to change notification settings - Fork 14
/
injector.c
764 lines (636 loc) · 19.9 KB
/
injector.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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
#include <fltKernel.h>
#include <wdm.h>
#include <ntddk.h>
#include <ntifs.h>
#include <ntstrsafe.h>
#include <Ntddk.h>
/*
Steps:
1. Collect information
2. Attach to the process
3. Allocate enough memory for our function
4. Write our function in the allocated memory
5. Hook a commonly used function
6. Unload
*/
// Structures
typedef struct
{
char DllPathway [250];
WCHAR wDllPathway [250];
DWORD dllEntrypoint;
SIZE_T dllSize;
} DLLSTRUCT;
//
// Library Structures
DLLSTRUCT MainLibrary;
DLLSTRUCT InjecTORLib;
// Debugging functions
NTSTATUS ntStatus;
int Check = 0;
// Type definitions
typedef BOOLEAN BOOL;
// Definitions
#define true 1
#define false 0
// Target
HANDLE hTarget;
CLIENT_ID clientId;
OBJECT_ATTRIBUTES objAttributes;
// Sleep
LARGE_INTEGER SleepVal;
// Lengths of specific strings in the settings.
SIZE_T szFile;
SIZE_T szMainDir;
SIZE_T dirLength;
// Handles to files.
HANDLE hCurrentDir = NULL;
HANDLE hGreenlight = NULL;
HANDLE hSettings = NULL;
HANDLE hInjecTOR = NULL;
// Library name and pathway.
char MainDir [250];
// 'MainLibrary' Variables.
char DllName [250];
char DllPathway [250];
// 'InjecTORLib' Variables.
char InjecTOR [] = "InjecTOR.dll";
char InjecTORPath [250];
// 'PsSetLoadImageNotifyRoutine' Variables.
char moddedPath [250];
char moddedDll [250];
WCHAR wDllPathway [250];
WCHAR wInjecTOR [250];
// Dll Memory
DWORD dllEntrypoint;
SIZE_T dllLength;
// Signature
BOOL FoundFirst = FALSE;
BOOL Signatures = FALSE;
// Variables for attaching
PEPROCESS targetProcess;
KAPC_STATE apcState;
// Allocation size variable
SIZE_T szAllocation = 5;
// Variables for allocation (void*)
PVOID funcEntrypoint;
PVOID pOriginalBytes;
PVOID pDllPath;
PVOID lpProtect;
PVOID lpLoadLib;
PVOID lpCreateThread;
PVOID lpVirtualProtect;
PVOID lpTargetFunc;
PVOID OldProtect;
PVOID lpDllPath;
PVOID Dummy;
// Variables for allocation (dword)
DWORD pLoadLibraryA;
DWORD pCreateThread;
DWORD pSleep;
DWORD pVirtualProtect;
DWORD dwProcessId;
DWORD DllSize;
// Memory protection
ULONG OldProtection;
// User processor information
BOOL Go8; // Windows 8 32 Bit
BOOL processor;
// Multibyte to Unicode size
ULONG UnicodeToWrite;
// UNICODE_STRING Variables
UNICODE_STRING uTestFunc;
// Addresses to kernel-mode functions
VOID* lpTestFunc;
VOID* lpTestFunc2;
// Settings information
char Characters [250];
char cProcessID [10];
char cCreateThread [10];
char cLoadLibrary [10];
char cSleep [10];
char cVirtualProtect [10];
char cDllSize [10];
char greenlight [10];
char injector [8];
// Variables for memory comparisons
unsigned char comparison [5];
unsigned char entrypoint [3];
unsigned char hook [5];
unsigned char FuncBytes [150];
// ZwProtectVirtualMemory
typedef NTSTATUS (__stdcall *ZWPROTECTMEM ) ( IN HANDLE ProcessHandle, IN PVOID * BaseAddress, IN SIZE_T * NumberOfBytesToProtect,
IN ULONG NewAccessProtection, OUT PULONG OldAccessProtection );
ZWPROTECTMEM ZwProtectVirtualMemory = NULL;
// Loop variables
SIZE_T loopNum;
int powNum;
// Other
LARGE_INTEGER largeInt;
IO_STATUS_BLOCK status;
// Locate ZwProtectVirtualMemory
VOID* LocateProtect32 ( VOID* ZwPulseEvent )
{
// Make a copy of lea edx, [esp+04]
memcpy ( &comparison, (void*) ( (unsigned int) ZwPulseEvent + 0x05 ), 5 );
if ( !Go8 )
{
// Locate the previous lea edx, [esp+04]
for ( loopNum = 0; loopNum < 40; loopNum ++ )
if ( !memcmp ( (void*) ( (unsigned int) ZwPulseEvent - loopNum ), &comparison, 5 ) )
break;
return ( (void*) ( (unsigned int) ZwPulseEvent - loopNum - 0x05 ) );
}
else
{
// Locate the next lea edx, [esp+04]
for ( loopNum = 0; loopNum < 40; loopNum ++ )
if ( !memcmp ( (void*) ( (unsigned int) ZwPulseEvent + 0x9 + loopNum ), &comparison, 5 ) )
break;
return ( (void*) ( (unsigned int) ZwPulseEvent + 0x9 + loopNum - 0x05 ) );
}
}
VOID* LocateProtect64 ( VOID* ZwQuerySection )
{
// Make a copy of ZwQuerySection
memcpy ( &entrypoint, (void*) ZwQuerySection, 3 );
// Scan for previous instance
for ( loopNum = 0; loopNum < 40; loopNum ++ )
if ( !memcmp ( &entrypoint, (void*) ( (unsigned __int64) ZwQuerySection - loopNum - 0x03 ), 3 ) )
break;
// Return
return (void*) ( (unsigned __int64) ZwQuerySection - loopNum - 0x03 );
}
//
// Memory Functions
int cmpMemory ( void* blockOne, void* blockTwo, size_t szComparison )
{
__try
{
return memcmp ( blockOne, blockTwo, szComparison );
}
__except ( true )
{
return 1;
}
}
void cpyMemory ( void* destination, void* source, size_t szCopy )
{
__try
{
memcpy ( destination, source, szCopy );
}
__except ( true )
{
return;
}
}
//
// Misc
UNICODE_STRING InitializeText ( PCWSTR Text )
{
UNICODE_STRING uString;
RtlInitUnicodeString ( &uString, Text );
return uString;
}
DWORD Power ( DWORD Value, int Exponent )
{
DWORD dwNewVal = 1;
for ( powNum = 0; powNum < Exponent; powNum ++ )
{
dwNewVal *= Value;
}
return dwNewVal;
}
DWORD ToDwordFromChar ( char* Text )
{
int number = 0;
DWORD decimal = 0;
for ( loopNum = 0; loopNum < strlen ( Text ); loopNum ++ )
{
if ( ( Text [loopNum] - 48 ) >= 0 &&
( Text [loopNum] - 48 ) <= 9 )
number = Text [loopNum] - 48;
else
{
if ( Text [loopNum] == 'A' )
number = 10;
else if ( Text [loopNum] == 'B' )
number = 11;
else if ( Text [loopNum] == 'C' )
number = 12;
else if ( Text [loopNum] == 'D' )
number = 13;
else if ( Text [loopNum] == 'E' )
number = 14;
else if ( Text [loopNum] == 'F' )
number = 15;
}
decimal += number * Power ( 16, strlen (Text) - 1 - loopNum );
}
return decimal;
}
//
// Open/Read/Write Files
HANDLE OpenFile ( PCWSTR FilePath )
{
HANDLE hFile;
IO_STATUS_BLOCK status;
OBJECT_ATTRIBUTES obj;
UNICODE_STRING pText;
// Define object-attributes
RtlInitUnicodeString ( &pText, FilePath );
// Initialize the object
InitializeObjectAttributes ( &obj, &pText, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, NULL, NULL );
// Open the file
ntStatus = ZwOpenFile ( &hFile, GENERIC_READ | GENERIC_WRITE, &obj, &status, 0, FILE_SYNCHRONOUS_IO_NONALERT );
if ( ntStatus != STATUS_SUCCESS )
return 0;
return hFile;
}
BOOL ReadFile ( HANDLE hFile, void* Buffer, ULONG Length )
{
largeInt.HighPart = 0;
largeInt.LowPart = 0;
ntStatus = ZwReadFile ( hFile, NULL, NULL, NULL, &status, Buffer, Length, &largeInt, NULL );
if ( ntStatus != STATUS_SUCCESS )
return FALSE;
else
return TRUE;
}
//
// 'PsSetLoadImageNotifyRoutine' Callback
VOID ViewMappedMemory ( PUNICODE_STRING FullImageName, HANDLE ProcessId, PIMAGE_INFO ImageInfo )
{
if ( ImageInfo->SystemModeImage == 0 )
{
if ( wcsstr ( FullImageName->Buffer, MainLibrary.wDllPathway ) != NULL )
{
// Grab information
MainLibrary.dllEntrypoint = (DWORD) ImageInfo->ImageBase;
MainLibrary.dllSize = ImageInfo->ImageSize;
}
if ( wcsstr ( FullImageName->Buffer, InjecTORLib.wDllPathway ) != NULL )
{
// Grab information
InjecTORLib.dllEntrypoint = (DWORD) ImageInfo->ImageBase;
InjecTORLib.dllSize = ImageInfo->ImageSize;
}
}
}
//
// Inject
VOID Inject ( DLLSTRUCT* dllStruct )
{
// Reset information
dllStruct->dllEntrypoint = 0;
dllStruct->dllSize = 0;
// Allocate memory
szAllocation = 144;
ZwAllocateVirtualMemory ( NtCurrentProcess (), &funcEntrypoint, 0, &szAllocation, MEM_COMMIT, PAGE_EXECUTE_READWRITE );
szAllocation = 4;
ZwAllocateVirtualMemory ( NtCurrentProcess (), &lpLoadLib, 0, &szAllocation, MEM_COMMIT, PAGE_EXECUTE_READWRITE );
ZwAllocateVirtualMemory ( NtCurrentProcess (), &lpCreateThread, 0, &szAllocation, MEM_COMMIT, PAGE_EXECUTE_READWRITE );
ZwAllocateVirtualMemory ( NtCurrentProcess (), &lpVirtualProtect, 0, &szAllocation, MEM_COMMIT, PAGE_EXECUTE_READWRITE );
ZwAllocateVirtualMemory ( NtCurrentProcess (), &lpTargetFunc, 0, &szAllocation, MEM_COMMIT, PAGE_EXECUTE_READWRITE );
ZwAllocateVirtualMemory ( NtCurrentProcess (), &OldProtect, 0, &szAllocation, MEM_COMMIT, PAGE_EXECUTE_READWRITE );
ZwAllocateVirtualMemory ( NtCurrentProcess (), &Dummy, 0, &szAllocation, MEM_COMMIT, PAGE_EXECUTE_READWRITE );
szAllocation = strlen ( dllStruct->DllPathway );
ZwAllocateVirtualMemory ( NtCurrentProcess (), &lpDllPath, 0, &szAllocation, MEM_COMMIT, PAGE_EXECUTE_READWRITE );
// Setup Variables
memcpy ( lpTargetFunc, &pSleep, 4 );
memcpy ( lpLoadLib, &pLoadLibraryA, 4 );
memcpy ( lpCreateThread, &pCreateThread, 4 );
memcpy ( lpVirtualProtect, &pVirtualProtect, 4 );
memcpy ( lpDllPath, &dllStruct->DllPathway, strlen ( dllStruct->DllPathway ) );
// Write the function
memcpy ( &FuncBytes [0], (void*) "\x55\x53\x52\x54\x51\x50\x54\x56\x57\x6A\x00\x6A\x00", 13 );
FuncBytes [13] = 0x68;
*(DWORD*) &FuncBytes [14] = (DWORD) lpDllPath;
FuncBytes [18] = 0xA1;
*(DWORD*) &FuncBytes [19] = (DWORD) lpLoadLib;
memcpy ( &FuncBytes [23], (void*) "\x50\x6A\x00\x6A\x00", 5 );
FuncBytes [28] = 0xFF;
FuncBytes [29] = 0x15;
*(DWORD*) &FuncBytes [30] = (DWORD) lpCreateThread;
FuncBytes [34] = 0x68;
*(DWORD*) &FuncBytes [35] = (DWORD) OldProtect;
memcpy ( &FuncBytes [39], (void*) "\x6A\x40\x6A\x05", 4 );
memcpy ( &FuncBytes [43], (void*) "\x8B\x0D", 2 );
*(DWORD*) &FuncBytes [45] = (DWORD) lpTargetFunc;
FuncBytes [49] = 0x51;
FuncBytes [50] = 0xFF;
FuncBytes [51] = 0x15;
*(DWORD*) &FuncBytes [52] = (DWORD) lpVirtualProtect;
FuncBytes [56] = 0x8B;
FuncBytes [57] = 0x15;
*(DWORD*) &FuncBytes [58] = (DWORD) lpTargetFunc;
memcpy ( &FuncBytes [62], (void*) "\xC6\x02\x8B", 3 );
FuncBytes [65] = 0xA1;
*(DWORD*) &FuncBytes [66] = (DWORD) lpTargetFunc;
memcpy ( &FuncBytes [70], (void*) "\xC6\x40\x01\xFF", 4 );
FuncBytes [74] = 0x8B;
FuncBytes [75] = 0x0D;
*(DWORD*) &FuncBytes [76] = (DWORD) lpTargetFunc;
memcpy ( &FuncBytes [80], (void*) "\xC6\x40\x02\x55", 4 );
FuncBytes [84] = 0x8B;
FuncBytes [85] = 0x15;
*(DWORD*) &FuncBytes [86] = (DWORD) lpTargetFunc;
memcpy ( &FuncBytes [90], (void*) "\xC6\x42\x03\x8B", 4 );
FuncBytes [94] = 0xA1;
*(DWORD*) &FuncBytes [95] = (DWORD) lpTargetFunc;
memcpy ( &FuncBytes [99], (void*) "\xC6\x40\x04\xEC", 4 );
FuncBytes [103] = 0x68;
*(DWORD*) &FuncBytes [104] = (DWORD) Dummy;
memcpy ( &FuncBytes [108], (void*) "\x6A\x40\x6A\x05", 4 );
FuncBytes [112] = 0x8B;
FuncBytes [113] = 0x0D;
*(DWORD*) &FuncBytes [114] = (DWORD) lpTargetFunc;
FuncBytes [118] = 0x51;
FuncBytes [119] = 0xFF;
FuncBytes [120] = 0x15;
*(DWORD*) &FuncBytes [121] = (DWORD) lpVirtualProtect;
memcpy ( &FuncBytes [125], (void*) "\x5F\x5E\x5C\x58\x59\x5C\x5A\x5B\x5D", 9 );
FuncBytes [134] = 0xFF;
FuncBytes [135] = 0x25;
*(DWORD*) &FuncBytes [136] = (DWORD) lpTargetFunc;
memcpy ( &FuncBytes [140], "\xCC\xCC\xCC\xCC", 4 );
// Set the function
memcpy ( funcEntrypoint, &FuncBytes, 144 );
// Write the hook
hook [0] = 0xE9;
*(DWORD*) &hook [1] = (DWORD) funcEntrypoint - ( (DWORD) pSleep + 0x05 );
szAllocation = 5;
// Set the hook
__try
{
lpProtect = (void*) pSleep;
// Protect memory
ntStatus = ZwProtectVirtualMemory ( NtCurrentProcess (), &lpProtect, &szAllocation, PAGE_EXECUTE_READWRITE, &OldProtection );
// Attempt to write hook
if ( ntStatus == STATUS_SUCCESS )
memcpy ( (void*) pSleep, &hook, 5 );
}
__except ( 1 )
{
DbgPrint ( "Failed to use ZwProtectVirtualMemory ()" );
}
// Wait for the DLL to Inject
SleepVal.QuadPart = -1;
while ( !dllStruct->dllEntrypoint )
KeDelayExecutionThread ( KernelMode, FALSE, &SleepVal );
// Free the allocations
szAllocation = 144;
ntStatus = ZwFreeVirtualMemory ( NtCurrentProcess (), &funcEntrypoint, &szAllocation, MEM_RELEASE );
szAllocation = 4;
ZwFreeVirtualMemory ( NtCurrentProcess (), &lpLoadLib, &szAllocation, MEM_RELEASE );
ZwFreeVirtualMemory ( NtCurrentProcess (), &lpCreateThread, &szAllocation, MEM_RELEASE );
ZwFreeVirtualMemory ( NtCurrentProcess (), &lpVirtualProtect, &szAllocation, MEM_RELEASE );
ZwFreeVirtualMemory ( NtCurrentProcess (), &lpTargetFunc, &szAllocation, MEM_RELEASE );
ZwFreeVirtualMemory ( NtCurrentProcess (), &OldProtect, &szAllocation, MEM_RELEASE );
ZwFreeVirtualMemory ( NtCurrentProcess (), &Dummy, &szAllocation, MEM_RELEASE );
szAllocation = strlen ( dllStruct->DllPathway );
ZwFreeVirtualMemory ( NtCurrentProcess (), &lpDllPath, &szAllocation, MEM_RELEASE );
// Reset variables
funcEntrypoint = NULL;
lpLoadLib = NULL;
lpCreateThread = NULL;
lpVirtualProtect = NULL;
lpTargetFunc = NULL;
OldProtect = NULL;
Dummy = NULL;
lpDllPath = NULL;
return;
}
//
// Wait for the result of InjecTOR.dll
BOOL Wait ()
{
// Edit 'SleepVal'
SleepVal.QuadPart = -3;
// Open the file
hInjecTOR = OpenFile ( L"\\DosDevices\\C:\\injector.txt" );
// Check to see if the file exists
while ( !hInjecTOR )
{
hInjecTOR = OpenFile ( L"\\DosDevices\\C:\\injector.txt" );
KeDelayExecutionThread ( KernelMode, FALSE, &SleepVal );
}
if ( !hInjecTOR )
return FALSE;
else
{
// Empty and read
RtlZeroMemory ( &injector, 8 );
ReadFile ( hInjecTOR, injector, 8 );
// Close the file
ZwClose ( hInjecTOR );
// Output
if ( strstr ( injector, "injector" ) != 0 )
return TRUE;
else
return FALSE;
}
return FALSE;
}
//
// Collect information from Usermode Application
BOOL CollectInformation ()
{
// Check to see if the file exists
hGreenlight = OpenFile ( L"\\DosDevices\\C:\\Windows\\greenlight.txt" );
if ( hGreenlight != 0 )
{
// Empty and read
RtlZeroMemory ( &greenlight, 10 );
ReadFile ( hGreenlight, greenlight, 10 );
// Close the file
ZwClose ( hGreenlight );
// Check for greenlight
if ( !strcmp ( greenlight, "greenlight" ) )
{
hSettings = OpenFile ( L"\\DosDevices\\C:\\Settings.ini" );
if ( hSettings != 0 )
{
// Empty and read
RtlZeroMemory ( &Characters, 250 );
ReadFile ( hSettings, Characters, 250 );
// Close the file
ZwClose ( hSettings );
// Determine the length of the directory
for ( loopNum = 56; loopNum < 250; loopNum ++ )
if ( Characters [loopNum] == '\n' )
break;
dirLength = loopNum - 56 - 1;
// Determine the length of the DLL
for ( loopNum = ( 56 + dirLength + 2 ); loopNum < 250; loopNum ++ )
if ( Characters [loopNum] == '\n' )
break;
dllLength = loopNum - 56 - dirLength - 3;
// Determine the size of the file
for ( loopNum = 0; loopNum < 250; loopNum ++ )
if ( Characters [loopNum] == 'e' )
if ( Characters [loopNum+1] == 'n' )
if ( Characters [loopNum+2] == 'd' )
break;
szFile = loopNum - 2;
// Pass out information
if ( Characters [0] == '1' )
processor = TRUE;
else
processor = FALSE;
if ( Characters [3] == '1' )
if ( !processor )
Go8 = TRUE;
for ( loopNum = 0; loopNum < 8; loopNum ++ )
cProcessID [loopNum] = Characters [6 + loopNum];
for ( loopNum = 0; loopNum < 8; loopNum ++ )
cCreateThread [loopNum] = Characters [16 + loopNum];
for ( loopNum = 0; loopNum < 8; loopNum ++ )
cLoadLibrary [loopNum] = Characters [26 + loopNum];
for ( loopNum = 0; loopNum < 8; loopNum ++ )
cSleep [loopNum] = Characters [36 + loopNum];
for ( loopNum = 0; loopNum < 8; loopNum ++ )
cVirtualProtect [loopNum] = Characters [46 + loopNum];
for ( loopNum = 56; loopNum < ( 56 + dirLength ); loopNum ++ )
MainDir [loopNum - 56] = Characters [loopNum];
for ( loopNum = ( 56 + dirLength + 2 ); loopNum < ( 56 + dirLength + 2 + dllLength ); loopNum ++ )
DllName [ loopNum - ( 56 + dirLength + 2 ) ] = Characters [ loopNum ];
for ( loopNum = ( 56 + dirLength + 2 + dllLength + 2 ); loopNum < szFile; loopNum ++ )
cDllSize [ loopNum - ( 56 + dirLength + 2 + dllLength + 2 ) ] = Characters [ loopNum ];
szMainDir = strlen ( MainDir );
// Setup variables
pLoadLibraryA = ToDwordFromChar ( cLoadLibrary );
pCreateThread = ToDwordFromChar ( cCreateThread );
pSleep = ToDwordFromChar ( cSleep );
dwProcessId = ToDwordFromChar ( cProcessID );
pVirtualProtect = ToDwordFromChar ( cVirtualProtect );
DllSize = ToDwordFromChar ( cDllSize );
// Setup dll pathway
memcpy ( &DllPathway, &MainDir, szMainDir );
memcpy ( &InjecTORPath, &MainDir, szMainDir );
memcpy ( &DllPathway [szMainDir], &DllName, strlen ( DllName ) );
memcpy ( &InjecTORPath [szMainDir], &InjecTOR, strlen ( InjecTOR ) );
memcpy ( &moddedPath, &DllName, strlen ( DllName ) );
memcpy ( &moddedDll, &InjecTOR, strlen ( InjecTOR ) );
// Convert multi-byte to unicode
if ( RtlMultiByteToUnicodeSize ( &UnicodeToWrite, moddedPath, (ULONG) strlen ( moddedPath ) ) == STATUS_SUCCESS )
{
if ( RtlMultiByteToUnicodeN ( wDllPathway, UnicodeToWrite, NULL, moddedPath, (ULONG) strlen ( moddedPath ) ) != STATUS_SUCCESS )
return FALSE;
}
else
return FALSE;
if ( RtlMultiByteToUnicodeSize ( &UnicodeToWrite, moddedDll, (ULONG) strlen ( moddedDll ) ) == STATUS_SUCCESS )
{
if ( RtlMultiByteToUnicodeN ( wInjecTOR, UnicodeToWrite, NULL, moddedDll, (ULONG) strlen ( moddedDll ) ) != STATUS_SUCCESS )
return FALSE;
}
else
return FALSE;
// Debug variables
/*DbgPrint ( "%s", "Printing.." );
DbgPrint ( "%x", (void*) processor );
DbgPrint ( "%x", (void*) Go8 );
DbgPrint ( "%x", (void*) pLoadLibraryA );
DbgPrint ( "%x", (void*) pCreateThread );
DbgPrint ( "%x", (void*) pSleep );
DbgPrint ( "%x", (void*) dwProcessId );
DbgPrint ( "%x", (void*) pVirtualProtect );
DbgPrint ( "%d", DllSize );
DbgPrint ( "%s", MainDir );
DbgPrint ( "%ws", wDllPathway );
DbgPrint ( "%ws", wInjecTOR );*/
return TRUE;
}
else
return FALSE;
}
else
return FALSE;
}
return FALSE;
}
//
// Driver Unload
NTSTATUS DriverUnload ( struct _DRIVER_OBJECT *DriverObject )
{
// Message
DbgPrint ( "Successfully unloaded!" );
// Return
return STATUS_SUCCESS;
}
//
// Driver Entry
NTSTATUS DriverEntry (PDRIVER_OBJECT pDriverObject, PUNICODE_STRING pRegistryPath)
{
// Setup 'DriverUnload'
pDriverObject->DriverUnload = DriverUnload;
// Collect information from settings
if ( CollectInformation () )
{
// Setup target function based off processor
if ( processor == TRUE )
uTestFunc = InitializeText ( L"ZwQuerySection" );
else
uTestFunc = InitializeText ( L"ZwPulseEvent" );
// Locate the kernel mode function
lpTestFunc = MmGetSystemRoutineAddress ( &uTestFunc );
if ( processor == TRUE )
lpTestFunc2 = LocateProtect64 ( lpTestFunc );
else
lpTestFunc2 = LocateProtect32 ( lpTestFunc );
// Set 'ZwProtectVirtualMemory'
ZwProtectVirtualMemory = (ZWPROTECTMEM) lpTestFunc2;
// Attach to the process
ntStatus = PsLookupProcessByProcessId ( (HANDLE) dwProcessId, &targetProcess );
if ( ntStatus != STATUS_SUCCESS )
DbgPrint ( "%s%x%s", "Error: ", ntStatus, " target." );
else
{
// Open the handle
ntStatus = ObOpenObjectByPointer ( targetProcess, 0, NULL, PROCESS_ALL_ACCESS, *PsProcessType, KernelMode, &hTarget );
if ( ( hTarget != NULL ) &&
( ntStatus == STATUS_SUCCESS ) )
{
// Add the callback
PsSetLoadImageNotifyRoutine ( ViewMappedMemory );
// Attach to the process
KeStackAttachProcess ( targetProcess, &apcState );
// Setup 'InjecTORLib'
memcpy ( &InjecTORLib.DllPathway, &InjecTORPath, strlen ( InjecTORPath ) );
memcpy ( &InjecTORLib.wDllPathway, &wInjecTOR, 250 );
// Setup 'MainLibrary'
memcpy ( &MainLibrary.DllPathway, &DllPathway, strlen ( DllPathway ) );
memcpy ( &MainLibrary.wDllPathway, &wDllPathway, 250 );
// Inject 'InjecTOR.dll'
Inject ( &InjecTORLib );
// Inject the main library
Inject ( &MainLibrary );
// Wait for the file
Signatures = Wait ();
// Unattach from the process
KeUnstackDetachProcess ( &apcState );
// Remove the callback
PsRemoveLoadImageNotifyRoutine ( ViewMappedMemory );
// Terminate
__try
{
if ( !Signatures )
ZwTerminateProcess ( hTarget, STATUS_SUCCESS );
}
__except ( true )
{
DbgPrint ( "%s", "ZwTerminateProcess () Failed." );
}
// Close the handle
ZwClose ( hTarget );
}
else
DbgPrint ( "%s", "Bad handle." );
}
}
DbgPrint ( "%s", "The driver has finished loading." );
return STATUS_SUCCESS;
}
//