From fe02e42ea0013fe3be4f46dfcf56bb3c9ba29c0f Mon Sep 17 00:00:00 2001 From: Ilija Lazoroski Date: Mon, 9 Aug 2021 18:18:47 +0200 Subject: [PATCH] Agent: Fix linux command line for http request --- CHANGELOG.md | 2 ++ .../post_breach/actions/communicate_as_new_user.py | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e224ceaa1..019768075 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,8 @@ Changelog](https://keepachangelog.com/en/1.0.0/). - Create/check data directory on Island initialization. #1170 - Format some log messages to make them more readable. #1283 - Improve runtime of some unit tests. #1125 +- Run curl OR wget (not both) when attempting to communicate as a new user on + Linux. #1407 ### Removed - Relevant dead code as reported by Vulture. #1149 diff --git a/monkey/infection_monkey/post_breach/actions/communicate_as_new_user.py b/monkey/infection_monkey/post_breach/actions/communicate_as_new_user.py index d82b412d3..161adfb0d 100644 --- a/monkey/infection_monkey/post_breach/actions/communicate_as_new_user.py +++ b/monkey/infection_monkey/post_breach/actions/communicate_as_new_user.py @@ -1,5 +1,6 @@ import logging import random +import shutil import string import subprocess @@ -64,11 +65,13 @@ class CommunicateAsNewUser(PBA): 'Invoke-WebRequest {url} -UseBasicParsing"' ) else: - # true || false -> 0. false || true -> 0. false || false -> 1. So: # if curl works, we're good. # If curl doesn't exist or fails and wget work, we're good. # And if both don't exist: we'll call it a win. - format_string = "curl {url} || wget -O/dev/null -q {url}" + if shutil.which("curl") is not None: + format_string = "curl {url}" + else: + format_string = "wget -O/dev/null -q {url}" return format_string.format(url=url) def send_result_telemetry(self, exit_status, commandline, username):