def __init__(self, host='localhost', port=DEFAULT_LOGGING_CONFIG_PORT, handler=None): ThreadingTCPServer.__init__(self, (host, port), handler) logging._acquireLock() self.abort = 0 logging._releaseLock() self.timeout = 1
def __init__(self, server_address, session, probe): self._session = session self._probe = probe ThreadingTCPServer.__init__(self, server_address, DebugProbeRequestHandler, bind_and_activate=False)
def on_server_start(self): """Start banner service.""" requestHandler = BannerRequestHandler requestHandler.banner = self.service_args.get(BANNER) requestHandler.alert = self._send_alert port = int(self.service_args.get(PORT)) self.server = ThreadingTCPServer(("", port), requestHandler) self.signal_ready() self.logger.info("Starting Banner service on port {}".format(port)) self.server.serve_forever()
def run(self, port): # noqa: D102 requestHandler = SSHRequestHandler requestHandler.alert = self.alert self.server = ThreadingTCPServer(("", port), requestHandler) # This prevents the timewait on the socket that prevents us from restarting the honeypot right # away after closing self.server.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.server.socket.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER, struct.pack('ii', 1, 0)) self.server.serve_forever()
class BannerService(ServerCustomService): """Simple service that will print out banner and hang.""" def __init__(self, *args, **kwargs): """Initialize service.""" super(BannerService, self).__init__(*args, **kwargs) self.server = None def _send_alert(self, originating_ip, originating_port): params = { "event_type": BANNER_ALERT_TYPE_NAME, "originating_ip": originating_ip, "originating_port": originating_port, } self.add_alert_to_queue(params) def on_server_start(self): """Start banner service.""" requestHandler = BannerRequestHandler requestHandler.banner = self.service_args.get(BANNER) requestHandler.alert = self._send_alert port = int(self.service_args.get(PORT)) self.server = ThreadingTCPServer(("", port), requestHandler) self.signal_ready() self.logger.info("Starting Banner service on port {}".format(port)) self.server.serve_forever() def on_server_shutdown(self): """Stop banner service.""" if self.server: self.server.shutdown() self.logger.info("Banner service stopped") self.server = None def test(self): """Test service alerts and return a list of triggered event types.""" event_types = list() self.logger.debug("executing service test") s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.settimeout(3) s.connect(("127.0.0.1", int(self.service_args.get(PORT)))) s.close() event_types.append(BANNER_ALERT_TYPE_NAME) return event_types def __str__(self): """Service name.""" return "Banner"
class SockListener(BaseListener): handlerCls = SockServiceHandler def __init__(self, *args, **kwargs): super(SockListener, self).__init__(*args, **kwargs) # inject service_handler SockBoltHandler.service_handler = self.handler self.server = ThreadingTCPServer(self.address, SockBoltHandler) def run_forever(self): self.server.serve_forever() def shutdown(self): self.server.shutdown()
def start_server(sync): # type: (bool) -> int """Start the TCP server.""" # N.B. port = 0 chooses any arbitrary open one CoqtailHandler.sync = sync CoqtailServer.serv = ThreadingTCPServer(("localhost", 0), CoqtailHandler) CoqtailServer.serv.daemon_threads = True _, port = CoqtailServer.serv.server_address serv_thread = threading.Thread(target=CoqtailServer.serv.serve_forever) serv_thread.daemon = True serv_thread.start() return port
def __init__(self, *args, **kwargs): super(SockListener, self).__init__(*args, **kwargs) # inject service_handler SockBoltHandler.service_handler = self.handler self.server = ThreadingTCPServer(self.address, SockBoltHandler)