From 9002c47d5601bfb373529878c816ce73c0f679ca Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Mon, 12 Sep 2022 16:29:19 -0400 Subject: [PATCH] Agent: Add a timeout on TCPPipeSpawner dest socket --- monkey/infection_monkey/network/relay/consts.py | 1 + monkey/infection_monkey/network/relay/sockets_pipe.py | 5 +++-- monkey/infection_monkey/network/relay/tcp_pipe_spawner.py | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 monkey/infection_monkey/network/relay/consts.py diff --git a/monkey/infection_monkey/network/relay/consts.py b/monkey/infection_monkey/network/relay/consts.py new file mode 100644 index 000000000..eb5d3f75a --- /dev/null +++ b/monkey/infection_monkey/network/relay/consts.py @@ -0,0 +1 @@ +SOCKET_TIMEOUT = 10 diff --git a/monkey/infection_monkey/network/relay/sockets_pipe.py b/monkey/infection_monkey/network/relay/sockets_pipe.py index 394adef52..ad1307a05 100644 --- a/monkey/infection_monkey/network/relay/sockets_pipe.py +++ b/monkey/infection_monkey/network/relay/sockets_pipe.py @@ -5,8 +5,9 @@ from logging import getLogger from threading import Thread from typing import Callable +from .consts import SOCKET_TIMEOUT + READ_BUFFER_SIZE = 8192 -SOCKET_READ_TIMEOUT = 10 logger = getLogger(__name__) @@ -19,7 +20,7 @@ class SocketsPipe(Thread): source, dest, pipe_closed: Callable[[SocketsPipe], None], - timeout=SOCKET_READ_TIMEOUT, + timeout=SOCKET_TIMEOUT, ): self.source = source self.dest = dest diff --git a/monkey/infection_monkey/network/relay/tcp_pipe_spawner.py b/monkey/infection_monkey/network/relay/tcp_pipe_spawner.py index 8e702d374..e4c48b77f 100644 --- a/monkey/infection_monkey/network/relay/tcp_pipe_spawner.py +++ b/monkey/infection_monkey/network/relay/tcp_pipe_spawner.py @@ -3,6 +3,7 @@ from ipaddress import IPv4Address from threading import Lock from typing import Set +from .consts import SOCKET_TIMEOUT from .sockets_pipe import SocketsPipe @@ -25,6 +26,7 @@ class TCPPipeSpawner: :raises OSError: If a socket to the configured client could not be created. """ dest = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + dest.settimeout(SOCKET_TIMEOUT) try: dest.connect((str(self._target_addr), self._target_port)) except OSError as err: