From 299a2613870b7e5e6b6afa301b54e15677aa36fa Mon Sep 17 00:00:00 2001 From: vakarisz Date: Mon, 28 Mar 2022 17:07:10 +0300 Subject: [PATCH] Agent: Refactor puppet and tools to use CONNECTION_TIMEOUT --- monkey/common/common_consts/timeouts.py | 3 ++- monkey/infection_monkey/network/tools.py | 3 ++- monkey/infection_monkey/puppet/puppet.py | 5 +++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/monkey/common/common_consts/timeouts.py b/monkey/common/common_consts/timeouts.py index f315e7518..de9e6edc5 100644 --- a/monkey/common/common_consts/timeouts.py +++ b/monkey/common/common_consts/timeouts.py @@ -1,3 +1,4 @@ -SHORT_REQUEST_TIMEOUT = 2.5 # Seconds. Use where we expect timeout. +SHORT_REQUEST_TIMEOUT = 2.5 # Seconds. Use where we expect timeout and for small data transactions. MEDIUM_REQUEST_TIMEOUT = 5 # Seconds. Use where we don't expect timeout. LONG_REQUEST_TIMEOUT = 15 # Seconds. Use where we don't expect timeout and operate heavy data. +CONNECTION_TIMEOUT = 3 # Seconds. Use for TCP, SSH and other connections that shouldn't take long. diff --git a/monkey/infection_monkey/network/tools.py b/monkey/infection_monkey/network/tools.py index 7a863ea7d..c612a7e48 100644 --- a/monkey/infection_monkey/network/tools.py +++ b/monkey/infection_monkey/network/tools.py @@ -4,9 +4,10 @@ import socket import struct import sys +from common.common_consts.timeouts import CONNECTION_TIMEOUT from infection_monkey.network.info import get_routes -DEFAULT_TIMEOUT = 10 +DEFAULT_TIMEOUT = CONNECTION_TIMEOUT BANNER_READ = 1024 logger = logging.getLogger(__name__) diff --git a/monkey/infection_monkey/puppet/puppet.py b/monkey/infection_monkey/puppet/puppet.py index d8bc8e0eb..87c5ee348 100644 --- a/monkey/infection_monkey/puppet/puppet.py +++ b/monkey/infection_monkey/puppet/puppet.py @@ -2,6 +2,7 @@ import logging import threading from typing import Dict, List, Sequence +from common.common_consts.timeouts import CONNECTION_TIMEOUT from infection_monkey import network_scanning from infection_monkey.i_puppet import ( Credentials, @@ -38,11 +39,11 @@ class Puppet(IPuppet): def run_pba(self, name: str, options: Dict) -> PostBreachData: return self._mock_puppet.run_pba(name, options) - def ping(self, host: str, timeout: float = 1) -> PingScanData: + def ping(self, host: str, timeout: float = CONNECTION_TIMEOUT) -> PingScanData: return network_scanning.ping(host, timeout) def scan_tcp_ports( - self, host: str, ports: List[int], timeout: float = 3 + self, host: str, ports: List[int], timeout: float = CONNECTION_TIMEOUT ) -> Dict[int, PortScanData]: return network_scanning.scan_tcp_ports(host, ports, timeout)