From d970271016557da705482c3a03fbe7bfdca7f2dc Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Mon, 28 Feb 2022 08:29:04 -0500 Subject: [PATCH] Agent: Fix get_target_monkey() bug when running from source --- monkey/infection_monkey/exploit/tools/helpers.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/monkey/infection_monkey/exploit/tools/helpers.py b/monkey/infection_monkey/exploit/tools/helpers.py index f519e554f..47057b63f 100644 --- a/monkey/infection_monkey/exploit/tools/helpers.py +++ b/monkey/infection_monkey/exploit/tools/helpers.py @@ -1,4 +1,5 @@ import logging +from pathlib import Path logger = logging.getLogger(__name__) @@ -20,7 +21,15 @@ def get_target_monkey(host): return None if host.os.get("type") == platform.system().lower(): - return sys.executable + try: + # When running from source, sys.executable will be "python", not an agent. + if "monkey" in Path(sys.executable).name: + return sys.executable + except Exception as ex: + logger.warning( + "Unable to retrieve this executable's path, downloading executable from the island " + f"instead: {ex}" + ) return ControlClient.download_monkey_exe(host)