From b8006a62747c696e9427df953b076da1011f0fae Mon Sep 17 00:00:00 2001 From: vakarisz Date: Wed, 11 May 2022 14:32:39 +0300 Subject: [PATCH] Island: Add instance ID to AWSCommandResults Instance id tells us where the command was launched --- monkey/monkey_island/cc/resources/remote_run.py | 6 +++++- monkey/monkey_island/cc/services/aws/aws_command_runner.py | 2 ++ .../cc/services/aws/test_aws_command_runner.py | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/monkey/monkey_island/cc/resources/remote_run.py b/monkey/monkey_island/cc/resources/remote_run.py index 8f02ee066..df4b808e2 100644 --- a/monkey/monkey_island/cc/resources/remote_run.py +++ b/monkey/monkey_island/cc/resources/remote_run.py @@ -67,7 +67,11 @@ class RemoteRun(flask_restful.Resource): for result in results: results_copy.append( AWSCommandResults( - result.response_code, result.stdout, result.stderr, result.status.name.lower() + result.instance_id, + result.response_code, + result.stdout, + result.stderr, + result.status.name.lower(), ) ) return results_copy diff --git a/monkey/monkey_island/cc/services/aws/aws_command_runner.py b/monkey/monkey_island/cc/services/aws/aws_command_runner.py index 6e88c0e21..9a85ba49a 100644 --- a/monkey/monkey_island/cc/services/aws/aws_command_runner.py +++ b/monkey/monkey_island/cc/services/aws/aws_command_runner.py @@ -23,6 +23,7 @@ class AWSCommandStatus(Enum): @dataclass(frozen=True) class AWSCommandResults: + instance_id: str response_code: int stdout: str stderr: str @@ -137,6 +138,7 @@ def _fetch_command_results( aws_command_result_status = AWSCommandStatus.ERROR return AWSCommandResults( + target_instance_id, command_results["ResponseCode"], command_results["StandardOutputContent"], command_results["StandardErrorContent"], diff --git a/monkey/tests/unit_tests/monkey_island/cc/services/aws/test_aws_command_runner.py b/monkey/tests/unit_tests/monkey_island/cc/services/aws/test_aws_command_runner.py index 3386772ed..f04932b93 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/services/aws/test_aws_command_runner.py +++ b/monkey/tests/unit_tests/monkey_island/cc/services/aws/test_aws_command_runner.py @@ -228,5 +228,5 @@ def test_failed_command(send_command_response, error_response): ], ) def test_command_resuls_status(status, success): - results = AWSCommandResults(0, "", "", status) + results = AWSCommandResults(INSTANCE_ID, 0, "", "", status) assert results.success == success