From 1355c038b5970f4f59294420bcf750ef2d420743 Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Tue, 20 Sep 2022 14:56:10 +0530 Subject: [PATCH] Agent: Add and use HTTPIslandAPIClient.get_agent_binary() --- .../exploit/caching_agent_binary_repository.py | 14 +------------- .../island_api_client/http_island_api_client.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/monkey/infection_monkey/exploit/caching_agent_binary_repository.py b/monkey/infection_monkey/exploit/caching_agent_binary_repository.py index 72ff61446..f74648eff 100644 --- a/monkey/infection_monkey/exploit/caching_agent_binary_repository.py +++ b/monkey/infection_monkey/exploit/caching_agent_binary_repository.py @@ -2,10 +2,7 @@ import io import threading from functools import lru_cache -import requests - from common import OperatingSystem -from common.common_consts.timeouts import MEDIUM_REQUEST_TIMEOUT from infection_monkey.island_api_client import IIslandAPIClient from . import IAgentBinaryRepository @@ -36,13 +33,4 @@ class CachingAgentBinaryRepository(IAgentBinaryRepository): @lru_cache(maxsize=None) def _download_binary_from_island(self, operating_system: OperatingSystem) -> bytes: os_name = operating_system.value - - response = requests.get( # noqa: DUO123 - f"{self._island_url}/api/agent-binaries/{os_name}", - verify=False, - timeout=MEDIUM_REQUEST_TIMEOUT, - ) - - response.raise_for_status() - - return response.content + return self._island_api_client.get_agent_binary(os_name) diff --git a/monkey/infection_monkey/island_api_client/http_island_api_client.py b/monkey/infection_monkey/island_api_client/http_island_api_client.py index 37feb8942..92ac1ce41 100644 --- a/monkey/infection_monkey/island_api_client/http_island_api_client.py +++ b/monkey/infection_monkey/island_api_client/http_island_api_client.py @@ -76,3 +76,14 @@ class HTTPIslandAPIClient(IIslandAPIClient): response.raise_for_status() return response.content + + @handle_island_errors + def get_agent_binary(self, os_name: str): + response = requests.get( # noqa: DUO123 + f"{self._api_url}/api/agent-binaries/{os_name}", + verify=False, + timeout=MEDIUM_REQUEST_TIMEOUT, + ) + response.raise_for_status() + + return response.content