Agent: Add a timeout on TCPPipeSpawner dest socket

This commit is contained in:
Mike Salvatore 2022-09-12 16:29:19 -04:00
parent 77c97062eb
commit 9002c47d56
3 changed files with 6 additions and 2 deletions

View File

@ -0,0 +1 @@
SOCKET_TIMEOUT = 10

View File

@ -5,8 +5,9 @@ from logging import getLogger
from threading import Thread from threading import Thread
from typing import Callable from typing import Callable
from .consts import SOCKET_TIMEOUT
READ_BUFFER_SIZE = 8192 READ_BUFFER_SIZE = 8192
SOCKET_READ_TIMEOUT = 10
logger = getLogger(__name__) logger = getLogger(__name__)
@ -19,7 +20,7 @@ class SocketsPipe(Thread):
source, source,
dest, dest,
pipe_closed: Callable[[SocketsPipe], None], pipe_closed: Callable[[SocketsPipe], None],
timeout=SOCKET_READ_TIMEOUT, timeout=SOCKET_TIMEOUT,
): ):
self.source = source self.source = source
self.dest = dest self.dest = dest

View File

@ -3,6 +3,7 @@ from ipaddress import IPv4Address
from threading import Lock from threading import Lock
from typing import Set from typing import Set
from .consts import SOCKET_TIMEOUT
from .sockets_pipe import SocketsPipe from .sockets_pipe import SocketsPipe
@ -25,6 +26,7 @@ class TCPPipeSpawner:
:raises OSError: If a socket to the configured client could not be created. :raises OSError: If a socket to the configured client could not be created.
""" """
dest = socket.socket(socket.AF_INET, socket.SOCK_STREAM) dest = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
dest.settimeout(SOCKET_TIMEOUT)
try: try:
dest.connect((str(self._target_addr), self._target_port)) dest.connect((str(self._target_addr), self._target_port))
except OSError as err: except OSError as err: