Repository navigation
Expand file tree
/
Copy pathStringFunctions.c
More file actions
588 lines (524 loc) · 23.5 KB
/
Copy pathStringFunctions.c
File metadata and controls
588 lines (524 loc) · 23.5 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
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
#include <Windows.h>
#include <stdio.h>
#include "Common.h"
// =======================================
// == RC4 Decryption Source Code ==
// =======================================
char _Rc4Decryption[] =
"#include <windows.h>\n"
"#include <stdio.h>\n\n"
"// Define SystemFunction032 USTRING struct parameter\n"
"typedef struct\n"
"{\n"
" DWORD Length; // Payload's size\n"
" DWORD MaximumLength; // Max size (often equal to Length)\n"
" PVOID Buffer; // Payload's base address\n"
"} USTRING;\n\n"
"// Define how the function look (later API Hashing discussion...)\n"
"typedef NTSTATUS(NTAPI* fnSystemFunction032)(\n"
" struct USTRING* Data, // Buffer\n"
" struct USTRING* Key // Key\n"
"); \n\n"
"BOOL Rc4EncryptionViaSystemFunc032(IN PBYTE pRc4Key, IN PBYTE pPayloadData, IN DWORD dwRc4KeySize, IN DWORD sPayloadSize) {\n"
" NTSTATUS STATUS = NULL;\n"
" USTRING Data = {\n"
" .Length = sPayloadSize,\n"
" .MaximumLength = sPayloadSize,\n"
" .Buffer = pPayloadData\n"
" };\n"
" USTRING Key = {\n"
" .Length = dwRc4KeySize,\n"
" .MaximumLength = dwRc4KeySize,\n"
" .Buffer = pRc4Key\n"
" };\n\n"
" // Grab 'SystemFunction032' exported from 'Advapi32.dll' module\n"
" fnSystemFunction032 SystemFunction032 = (fnSystemFunction032)GetProcAddress(LoadLibraryA(\"Advapi32\"), \"SystemFunction032\"); \n\n"
" if ((STATUS = SystemFunction032(&Data, &Key)) != 0x0) {\n"
" printf(\"[!] SystemFunction032 FAILED With Error : 0x%0.8X\\n\", STATUS);\n"
" return FALSE;\n"
" }\n\n"
" return TRUE;\n"
"}\n\n\n";
// =======================================
// == AES Decryption Source Code ==
// =======================================
char _AesDecryption[] =
"#include <windows.h>\n"
"#include <stdio.h>\n"
"#include <bcrypt.h>\n"
"#pragma comment(lib, \"Bcrypt.lib\")\n\n"
"#define NT_SUCCESS(status) (((NTSTATUS)(status)) >= 0)\n"
"#define KEYSIZE 32\n"
"#define IVSIZE 16\n\n"
"typedef struct _AES {\n"
" PBYTE pPlainText; // Plaintext's base\n"
" DWORD dwPlainSize; // Its size\n\n"
" PBYTE pCipherText; // Ciphertext's base\n"
" DWORD dwCipherSize; // Its size (higher than dwPlainSize if padded)\n\n"
" PBYTE pKey; // 32 byte Key\n"
" PBYTE pIv; // 16 byte IV\n"
" }AES, *PAES; \n\n"
"// bCrypt AES Decryption, for real !\n"
"BOOL InstallAesDecryption(PAES pAes) {\n"
" BOOL bSTATE = TRUE;\n\n"
" BCRYPT_ALG_HANDLE hAlgorithm = NULL;\n"
" BCRYPT_KEY_HANDLE hKey = NULL;\n\n"
" ULONG cbResult = NULL;\n"
" DWORD dwBlockSize = NULL;\n\n"
" DWORD cbKeyObject = NULL;\n"
" PBYTE pbKeyObject = NULL;\n\n"
" PBYTE pbPlainText = NULL;\n"
" DWORD cbPlainText = NULL;\n\n"
" NTSTATUS STATUS = NULL;\n\n"
" // Intialize hAlgorithm AES algorithm Handle\n"
" STATUS = BCryptOpenAlgorithmProvider(&hAlgorithm, BCRYPT_AES_ALGORITHM, NULL, 0);\n"
" if (!NT_SUCCESS(STATUS)) {\n"
" printf(\"[!] BCryptOpenAlgorithmProvider Failed With Error: 0x%0.8X \\n\", STATUS);\n"
" bSTATE = FALSE; goto _EndOfFunc;\n"
" }\n\n"
" // Get pbKeyObject size for later BCryptGenerateSymmetricKey()\n"
" STATUS = BCryptGetProperty(hAlgorithm, BCRYPT_OBJECT_LENGTH, (PBYTE)&cbKeyObject, sizeof(DWORD), &cbResult, 0);\n"
" if (!NT_SUCCESS(STATUS)) {\n"
" printf(\"[!] BCryptGetProperty[1] Failed With Error: 0x%0.8X \\n\", STATUS);\n"
" bSTATE = FALSE; goto _EndOfFunc;\n"
" }\n\n"
" // Get block size used for decryption (AES: it MUST be 16 bytes)\n"
" STATUS = BCryptGetProperty(hAlgorithm, BCRYPT_BLOCK_LENGTH, (PBYTE)&dwBlockSize, sizeof(DWORD), &cbResult, 0);\n"
" if (!NT_SUCCESS(STATUS)) {\n"
" printf(\"[!] BCryptGetProperty[2] Failed With Error: 0x%0.8X \\n\", STATUS);\n"
" bSTATE = FALSE; goto _EndOfFunc;\n"
" }\n"
" if (dwBlockSize != 16) {\n"
" bSTATE = FALSE; goto _EndOfFunc;\n"
" }\n\n"
" // Allocate memory for the key object\n"
" pbKeyObject = (PBYTE)HeapAlloc(GetProcessHeap(), 0, cbKeyObject);\n"
" if (pbKeyObject == NULL) {\n"
" bSTATE = FALSE; goto _EndOfFunc;\n"
" }\n\n"
" //Use CBC Block Cipher Mode (32 byte key & 16 byte IV)\n"
" STATUS = BCryptSetProperty(hAlgorithm, BCRYPT_CHAINING_MODE, (PBYTE)BCRYPT_CHAIN_MODE_CBC, sizeof(BCRYPT_CHAIN_MODE_CBC), 0);\n"
" if (!NT_SUCCESS(STATUS)) {\n"
" printf(\"[!] BCryptSetProperty Failed With Error: 0x%0.8X \\n\", STATUS);\n"
" bSTATE = FALSE; goto _EndOfFunc;\n"
" }\n\n"
" //Save key object (generated from pAes->pKey) in pbKeyObject, and its size in cbKeyObject\n"
" STATUS = BCryptGenerateSymmetricKey(hAlgorithm, &hKey, pbKeyObject, cbKeyObject, (PBYTE)pAes->pKey, KEYSIZE, 0);\n"
" if (!NT_SUCCESS(STATUS)) {\n"
" printf(\"[!] BCryptGenerateSymmetricKey Failed With Error: 0x%0.8X \\n\", STATUS);\n"
" bSTATE = FALSE; goto _EndOfFunc;\n"
" }\n\n"
" // Run BCryptDecrypt with NULL OUTs to save the output buffer's size in cbPlainText\n"
" STATUS = BCryptDecrypt(hKey, (PUCHAR)pAes->pCipherText, (ULONG)pAes->dwCipherSize, NULL, pAes->pIv, IVSIZE, NULL, 0, &cbPlainText, BCRYPT_BLOCK_PADDING);\n"
" if (!NT_SUCCESS(STATUS)) {\n"
" printf(\"[!] BCryptDecrypt[1] Failed With Error: 0x%0.8X \\n\", STATUS);\n"
" bSTATE = FALSE; goto _EndOfFunc;\n"
" }\n\n"
" // Allocate cbPlainText memory size for the output buffer\n"
" pbPlainText = (PBYTE)HeapAlloc(GetProcessHeap(), 0, cbPlainText);\n"
" if (pbPlainText == NULL) {\n"
" bSTATE = FALSE; goto _EndOfFunc;\n"
" }\n\n"
" // Run BCryptDecrypt again with pbPlainText as the output buffer\n"
" STATUS = BCryptDecrypt(hKey, (PUCHAR)pAes->pCipherText, (ULONG)pAes->dwCipherSize, NULL, pAes->pIv, IVSIZE, pbPlainText, cbPlainText, &cbResult, BCRYPT_BLOCK_PADDING);\n"
" if (!NT_SUCCESS(STATUS)) {\n"
" printf(\"[!] BCryptDecrypt[2] Failed With Error: 0x%0.8X \\n\", STATUS);\n"
" bSTATE = FALSE; goto _EndOfFunc;\n"
" }\n\n"
" // Clean up\n"
"_EndOfFunc:\n"
" if (hKey)\n"
" BCryptDestroyKey(hKey);\n"
" if (hAlgorithm)\n"
" BCryptCloseAlgorithmProvider(hAlgorithm, 0);\n"
" if (pbKeyObject)\n"
" HeapFree(GetProcessHeap(), 0, pbKeyObject);\n"
" // If everything is OK, save pbPlainText & cbPlainText\n"
" if (pbPlainText != NULL && bSTATE) {\n"
" pAes->pPlainText = pbPlainText;\n"
" pAes->dwPlainSize = cbPlainText;\n"
" }\n"
" return bSTATE;\n"
"}\n\n"
"// SimpleDecryption Wrapper for InstallAesDecryption()\n"
"BOOL SimpleDecryption(IN PVOID pCipherTextData, IN DWORD sCipherTextSize, IN PBYTE pKey, IN PBYTE pIv, OUT PVOID* pPlainTextData, OUT DWORD* sPlainTextSize) {\n"
" if (pCipherTextData == NULL || sCipherTextSize == NULL || pKey == NULL || pIv == NULL)\n"
" return FALSE; \n\n"
" // Intialize the struct\n"
" AES Aes = {\n"
" .pKey = pKey,\n"
" .pIv = pIv,\n"
" .pCipherText = pCipherTextData,\n"
" .dwCipherSize = sCipherTextSize\n"
" }; \n\n"
" if (!InstallAesDecryption(&Aes)) {\n"
" return FALSE;\n"
" }\n\n"
" // Save the output\n"
" *pPlainTextData = Aes.pPlainText;\n"
" *sPlainTextSize = Aes.dwPlainSize;\n"
" return TRUE;\n"
"}\n\n\n";
// ==========================================
// == IPv4Deobfuscation Source Code ==
// ==========================================
char _Ipv4Deobfuscation[] =
"#include <windows.h>\n"
"#include <stdio.h>\n\n"
"typedef NTSTATUS (NTAPI* fnRtlIpv4StringToAddressA)(\n"
" PCSTR S,\n"
" BOOLEAN Strict,\n"
" PCSTR* Terminator,\n"
" PVOID Addr\n"
"); \n\n"
"/*\n"
" IPv4Deobfuscate addresses in Ipv4Array into ppDAddress\n"
" * Ipv4Array - Array of IPv4 addresses\n"
" * NmbrOfElements - Its number of elements\n"
" * ppDAddress - OUT'ed IPv4Deobfuscated buffer\n"
" * pDSize - Its size\n"
"*/\n"
"BOOL Ipv4Deobfuscation(IN CHAR * Ipv4Array[], IN SIZE_T NmbrOfElements, OUT PBYTE * ppDAddress, OUT SIZE_T * pDSize) {\n"
" PBYTE pBuffer = NULL;\n"
" PBYTE TmpBuffer = NULL;\n"
" SIZE_T sBuffSize = NULL;\n"
" PCSTR Terminator = NULL;\n"
" NTSTATUS STATUS = NULL;\n\n"
" // // Get 'RtlIpv4StringToAddressA' address from NTDLL\n"
" fnRtlIpv4StringToAddressA pRtlIpv4StringToAddressA = (fnRtlIpv4StringToAddressA)GetProcAddress(GetModuleHandle(TEXT(\"NTDLL\")), \"RtlIpv4StringToAddressA\");\n"
" if (pRtlIpv4StringToAddressA == NULL) {\n"
" printf(\"[!] GetProcAddress Failed With Error : %d \\n\", GetLastError());\n"
" return FALSE;\n"
" }\n\n"
" // Get the obfuscated payload's size (i.e. number of IPs * 4)\n"
" sBuffSize = NmbrOfElements * 4; \n\n"
" // Allocate memory for the deobfuscated payload\n"
" pBuffer = (PBYTE)HeapAlloc(GetProcessHeap(), 0, sBuffSize);\n"
" if (pBuffer == NULL) {\n"
" printf(\"[!] HeapAlloc Failed With Error : %d \\n\", GetLastError());\n"
" return FALSE;\n"
" }\n\n"
" TmpBuffer = pBuffer; \n\n"
" // Loop through IPs of Ipv4Array\n"
" for (int i = 0; i < NmbrOfElements; i++) {\n"
" // Deobfuscate one IP at a time\n"
" if ((STATUS = pRtlIpv4StringToAddressA(Ipv4Array[i], FALSE, &Terminator, TmpBuffer)) != 0x0) {\n"
" printf(\"[!] RtlIpv4StringToAddressA Failed At [%s] With Error 0x%0.8X\\n\", Ipv4Array[i], STATUS);\n"
" return FALSE;\n"
" }\n"
" // Write the deobfuscated 4-byte buffer into TmpBuffer, and increase TmpBuffer by 4 to resume deobfuscation\n"
" TmpBuffer = (PBYTE)(TmpBuffer + 4);\n"
" }\n\n"
" // Out the deobfuscated buffer's base address & size\n"
" *ppDAddress = pBuffer;\n"
" *pDSize = sBuffSize;\n"
" return TRUE;\n"
"}\n\n\n";
// ==========================================
// == IPv6Deobfuscation Source Code ==
// ==========================================
char _Ipv6Deobfuscation[] =
"#include <windows.h>\n"
"#include <stdio.h>\n\n"
"typedef NTSTATUS (NTAPI* fnRtlIpv6StringToAddressA)(\n"
" PCSTR S,\n"
" PCSTR* Terminator,\n"
" PVOID Addr\n"
"); \n\n"
"/*\n"
" IPv6Deobfuscate addresses in Ipv6Array into ppDAddress\n"
" * Ipv6Array - Array of IPv6 addresses\n"
" * NmbrOfElements - Its number of elements\n"
" * ppDAddress - OUT'ed IPv6Deobfuscated buffer\n"
" * pDSize - Its size\n"
"*/\n"
"BOOL Ipv6Deobfuscation(IN CHAR* Ipv6Array[], IN SIZE_T NmbrOfElements, OUT PBYTE * ppDAddress, OUT SIZE_T * pDSize) {\n\n"
" PBYTE pBuffer = NULL;\n"
" PBYTE TmpBuffer = NULL;\n"
" SIZE_T sBuffSize = NULL;\n"
" PCSTR Terminator = NULL;\n"
" NTSTATUS STATUS = NULL;\n\n"
" // Get 'RtlIpv6StringToAddressA' address from NTDLL\n"
" fnRtlIpv6StringToAddressA pRtlIpv6StringToAddressA = (fnRtlIpv6StringToAddressA)GetProcAddress(GetModuleHandle(TEXT(\"NTDLL\")), \"RtlIpv6StringToAddressA\");\n"
" if (pRtlIpv6StringToAddressA == NULL) {\n"
" printf(\"[!] GetProcAddress Failed With Error : %d \\n\", GetLastError());\n"
" return FALSE;\n"
" }\n\n"
" // Get the obfuscated payload's size (i.e. number of IPs * 16)\n"
" sBuffSize = NmbrOfElements * 16;\n"
" // Allocate memory for the deobfuscated payload\n"
" pBuffer = (PBYTE)HeapAlloc(GetProcessHeap(), 0, sBuffSize);\n"
" if (pBuffer == NULL) {\n"
" printf(\"[!] HeapAlloc Failed With Error : %d \\n\", GetLastError());\n"
" return FALSE;\n"
" }\n\n"
" TmpBuffer = pBuffer; \n\n"
" // Loop through IPs of Ipv6Array\n"
" for (int i = 0; i < NmbrOfElements; i++) {\n"
" // Deobfuscate one IP at a time\n"
" if ((STATUS = pRtlIpv6StringToAddressA(Ipv6Array[i], &Terminator, TmpBuffer)) != 0x0) {\n"
" printf(\"[!] RtlIpv6StringToAddressA Failed At [%s] With Error 0x%0.8X\\n\", Ipv6Array[i], STATUS);\n"
" return FALSE;\n"
" }\n"
" // Write the deobfuscated 16-byte buffer into TmpBuffer, and increase TmpBuffer by 16 to resume deobfuscation\n"
" TmpBuffer = (PBYTE)(TmpBuffer + 16);\n"
" }\n\n"
" // Out the deobfuscated buffer's base address & size\n"
" *ppDAddress = pBuffer;\n"
" *pDSize = sBuffSize;\n"
" return TRUE;\n"
"}\n\n\n";
// =========================================
// == MACDeobfuscation Source Code ==
// =========================================
char _MacDeobfuscation[] =
"#include <windows.h>\n"
"#include <stdio.h>\n\n"
"typedef NTSTATUS (NTAPI* fnRtlEthernetStringToAddressA)(\n"
" PCSTR S,\n"
" PCSTR* Terminator,\n"
" PVOID Addr\n"
");\n\n"
"/*\n"
" MacDeobfuscate addresses in MacArray into ppDAddress\n"
" * MacArray - Array of MAC addresses\n"
" * NmbrOfElements - Its number of elements\n"
" * ppDAddress - OUT'ed MacDeobfuscated buffer\n"
" * pDSize - Its size\n"
"*/\n"
"BOOL MacDeobfuscation(IN CHAR* MacArray[], IN SIZE_T NmbrOfElements, OUT PBYTE * ppDAddress, OUT SIZE_T * pDSize) {\n\n"
" PBYTE pBuffer = NULL;\n"
" PBYTE TmpBuffer = NULL;\n"
" SIZE_T sBuffSize = NULL;\n"
" PCSTR Terminator = NULL;\n"
" NTSTATUS STATUS = NULL;\n\n"
" // Get 'RtlEthernetStringToAddressA' address from NTDLL\n"
" fnRtlEthernetStringToAddressA pRtlEthernetStringToAddressA = (fnRtlEthernetStringToAddressA)GetProcAddress(GetModuleHandle(TEXT(\"NTDLL\")), \"RtlEthernetStringToAddressA\");\n"
" if (pRtlEthernetStringToAddressA == NULL) {\n"
" printf(\"[!] GetProcAddress Failed With Error : %d \\n\", GetLastError());\n"
" return FALSE;\n"
" }\n\n"
" // Get the obfuscated payload's size (i.e. number of MACs * 6)\n"
" sBuffSize = NmbrOfElements * 6; \n\n"
" // Allocate memory for the deobfuscated payload\n"
" pBuffer = (PBYTE)HeapAlloc(GetProcessHeap(), 0, sBuffSize);\n"
" if (pBuffer == NULL) {\n"
" printf(\"[!] HeapAlloc Failed With Error : %d \\n\", GetLastError());\n"
" return FALSE;\n"
" }\n\n"
" TmpBuffer = pBuffer; \n\n"
" // Loop through MACs of MacArray\n"
" for (int i = 0; i < NmbrOfElements; i++) {\n"
" // Deobfuscate one MAC at a time\n"
" if ((STATUS = pRtlEthernetStringToAddressA(MacArray[i], &Terminator, TmpBuffer)) != 0x0) {\n"
" printf(\"[!] RtlEthernetStringToAddressA Failed At [%s] With Error 0x%0.8X\\n\", MacArray[i], STATUS);\n"
" return FALSE;\n"
" }\n"
" // Write the deobfuscated 6-byte buffer into TmpBuffer, and increase TmpBuffer by 6 to resume deobfuscation\n"
" TmpBuffer = (PBYTE)(TmpBuffer + 6);\n"
" }\n\n"
" // Out the deobfuscated buffer's base address & size\n"
" *ppDAddress = pBuffer;\n"
" *pDSize = sBuffSize;\n"
" return TRUE;\n"
"}\n\n\n";
// ==========================================
// == UUIDDeobfuscation Source Code ==
// ==========================================
char _UuidDeobfuscation[] =
"#include <windows.h>\n"
"#include <stdio.h>\n\n"
"typedef RPC_STATUS (WINAPI* fnUuidFromStringA)(\n"
" RPC_CSTR StringUuid,\n"
" UUID* Uuid\n"
"); \n\n"
"/*\n"
" UUIDDeobfuscate addresses in UuidArray into ppDAddress\n"
" * UuidArray - Array of UUID strings\n"
" * NmbrOfElements - Its number of elements\n"
" * ppDAddress - OUT'ed UUIDDeobfuscated buffer\n"
" * pDSize - Its size\n"
"*/\n"
"BOOL UuidDeobfuscation(IN CHAR* UuidArray[], IN SIZE_T NmbrOfElements, OUT PBYTE * ppDAddress, OUT SIZE_T * pDSize) {\n\n"
" PBYTE pBuffer = NULL;\n"
" PBYTE TmpBuffer = NULL;\n"
" SIZE_T sBuffSize = NULL;\n"
" RPC_STATUS STATUS = NULL;\n\n"
" // Get 'UuidFromStringA' address from Rpcrt4.dll\n"
" fnUuidFromStringA pUuidFromStringA = (fnUuidFromStringA)GetProcAddress(LoadLibrary(TEXT(\"RPCRT4\")), \"UuidFromStringA\");\n"
" if (pUuidFromStringA == NULL) {\n"
" printf(\"[!] GetProcAddress Failed With Error : %d \\n\", GetLastError());\n"
" return FALSE;\n"
" }\n"
" // Get the obfuscated payload's size (i.e. number of UUIDs * 16)\n"
" sBuffSize = NmbrOfElements * 16; \n\n"
" // Allocate memory for the deobfuscated payload\n"
" pBuffer = (PBYTE)HeapAlloc(GetProcessHeap(), 0, sBuffSize);\n"
" if (pBuffer == NULL) {\n"
" printf(\"[!] HeapAlloc Failed With Error : %d \\n\", GetLastError());\n"
" return FALSE;\n"
" }\n\n"
" TmpBuffer = pBuffer; \n\n"
" // Loop through UUIDs of UuidArray\n"
" for (int i = 0; i < NmbrOfElements; i++) {\n"
" // Deobfuscate one UUID at a time\n"
" if ((STATUS = pUuidFromStringA((RPC_CSTR)UuidArray[i], (UUID*)TmpBuffer)) != RPC_S_OK) {\n"
" printf(\"[!] UuidFromStringA Failed At [%s] With Error 0x%0.8X\\n\", UuidArray[i], STATUS);\n"
" return FALSE;\n"
" }\n\n"
" // Write the deobfuscated 16-byte buffer into TmpBuffer, and increase TmpBuffer by 16 to resume deobfuscation\n"
" TmpBuffer = (PBYTE)(TmpBuffer + 16);\n"
" }\n\n"
" // Out the deobfuscated buffer's base address & size\n"
" *ppDAddress = pBuffer;\n"
" *pDSize = sBuffSize;\n"
" return TRUE;\n"
"}\n\n\n";
// ===============================
// == Source Code Decoder ==
// ===============================
VOID PrintDecodeFunctionality(IN INT TYPE) {
if (TYPE == 0){
printf("[!] Missing Input Type (StringFunctions:PrintDecodeFunctionality)\n");
return;
}
switch (TYPE){
case RC4ENCRYPTION:
printf("%s\n", _Rc4Decryption);
break;
case AESENCRYPTION:
printf("%s\n", _AesDecryption);
break;
case IPV4FUSCATION:
printf("%s\n", _Ipv4Deobfuscation);
break;
case IPV6FUSCATION:
printf("%s\n", _Ipv6Deobfuscation);
break;
case MACFUSCATION:
printf("%s\n", _MacDeobfuscation);
break;
case UUIDFUSCATION:
printf("%s\n", _UuidDeobfuscation);
break;
default:
printf("[!] Unsupported Type Entered : 0x%0.8X\n", TYPE);
break;
}
}
// ===============================
// == Main Function Printer ==
// ===============================
VOID PrintMainFunction(IN INT TYPE) {
if (TYPE == 0) {
printf("[!] Missing Input Type (StringFunctions:PrintXDeobfuscationMainFunction)\n");
return;
}
PCHAR _MainFunctionStr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 1000);
switch (TYPE) {
case RC4ENCRYPTION:
_MainFunctionStr = "int main() {\n"
" // RC4 DECRYPTION !\n"
" if (!Rc4EncryptionViaSystemFunc032(Rc4Key, Rc4CipherText, sizeof(Rc4Key), sizeof(Rc4CipherText))) {\n"
" printf(\"[-] Rc4EncryptionViaSystemFunc032 (Decryption) Failed With Error: 0x%0.8X\", GetLastError());\n"
" return -1;\n"
" }\n\n"
" printf(\"RC4 Decrypted PlainText Is At: 0x%p\\n\", Rc4CipherText);\n\n"
" system(\"PAUSE\");\n"
" return 0;\n"
"}\n";
printf("%s", _MainFunctionStr);
break;
case AESENCRYPTION:
_MainFunctionStr = "int main() {\n"
" // Output buffer and size\n"
" PVOID pPlainText = NULL;\n"
" DWORD dwPlainSize = NULL;\n\n"
" // AES DECRYPTION !\n"
" if (!SimpleDecryption(AesCipherText, sizeof(AesCipherText), AesKey, AesIv, &pPlainText, &dwPlainSize)) {\n"
" printf(\"[-] AES SimpleDecryption Failed With Error: 0x%0.8X\", GetLastError());\n"
" return -1;\n"
" }\n\n"
" printf(\"AES Decrypted PlainText Is At: 0x%p\\n\", pPlainText);\n\n"
" // Finally Free !\n"
" HeapFree(GetProcessHeap(), 0, pPlainText);\n"
" system(\"PAUSE\");\n"
" return 0;\n"
"}\n";
printf("%s", _MainFunctionStr);
break;
case IPV4FUSCATION:
_MainFunctionStr = "int main() {\n"
" // Output buffer and size\n"
" PBYTE pDAddress = NULL;\n"
" SIZE_T sDSize = NULL;\n\n"
" if (!Ipv4Deobfuscation(Ipv4Array, NumberOfElements, &pDAddress, &sDSize)) {\n"
" printf(\"[-] Ipv4Deobfuscation Failed\\n\");\n"
" return -1;\n"
" }\n\n"
" printf(\"IPv4Deobfuscated Payload Is At: 0x%p\\n\", pDAddress);\n\n"
" // Finally Free !\n"
" HeapFree(GetProcessHeap(), 0, pDAddress);\n"
" system(\"PAUSE\");\n"
" return 0;\n"
"}\n";
printf("%s", _MainFunctionStr);
break;
case IPV6FUSCATION:
_MainFunctionStr = "int main() {\n"
" // Output buffer and size\n"
" PBYTE pDAddress = NULL;\n"
" SIZE_T sDSize = NULL;\n\n"
" if (!Ipv6Deobfuscation(Ipv6Array, NumberOfElements, &pDAddress, &sDSize)) {\n"
" printf(\"[-] Ipv6Deobfuscation Failed\\n\");\n"
" return -1;\n"
" }\n\n"
" printf(\"IPv6Deobfuscated Payload Is At: 0x%p\\n\", pDAddress);\n\n"
" // Finally Free !\n"
" HeapFree(GetProcessHeap(), 0, pDAddress);\n"
" system(\"PAUSE\");\n"
" return 0;\n"
"}\n";
printf("%s", _MainFunctionStr);
break;
case MACFUSCATION:
_MainFunctionStr = "int main() {\n"
" // Output buffer and size\n"
" PBYTE pDAddress = NULL;\n"
" SIZE_T sDSize = NULL;\n\n"
" if (!MacDeobfuscation(MacArray, NumberOfElements, &pDAddress, &sDSize)) {\n"
" printf(\"[-] MACDeobfuscation Failed\\n\");\n"
" return -1;\n"
" }\n\n"
" printf(\"MACDeobfuscated Payload Is At: 0x%p\\n\", pDAddress);\n\n"
" // Finally Free !\n"
" HeapFree(GetProcessHeap(), 0, pDAddress);\n"
" system(\"PAUSE\");\n"
" return 0;\n"
"}\n";
printf("%s", _MainFunctionStr);
break;
case UUIDFUSCATION:
_MainFunctionStr = "int main() {\n"
" // Output buffer and size\n"
" PBYTE pDAddress = NULL;\n"
" SIZE_T sDSize = NULL;\n\n"
" if (!UuidDeobfuscation(UuidArray, NumberOfElements, &pDAddress, &sDSize)) {\n"
" printf(\"[-] UUIDeobfuscation Failed\\n\");\n"
" return -1;\n"
" }\n\n"
" printf(\"UUIDDeobfuscated Payload Is At: 0x%p\\n\", pDAddress);\n\n"
" // Finally Free !\n"
" HeapFree(GetProcessHeap(), 0, pDAddress);\n"
" system(\"PAUSE\");\n"
" return 0;\n"
"}\n";
printf("%s", _MainFunctionStr);
break;
default:
printf("[!] Unsupported Type Entered : 0x%0.8X\n", TYPE);
break;
}
// Finally Free !
HeapFree(GetProcessHeap(), 0, _MainFunctionStr);
}