diff --git a/monkey/common/cloud/aws_instance.py b/monkey/common/cloud/aws_instance.py index f40b0bbec..748bd8d04 100644 --- a/monkey/common/cloud/aws_instance.py +++ b/monkey/common/cloud/aws_instance.py @@ -62,7 +62,18 @@ class AwsInstance(object): @staticmethod def _extract_account_id(instance_identity_document_response): + """ + Extracts the account id from the dynamic/instance-identity/document metadata path. + Based on https://forums.aws.amazon.com/message.jspa?messageID=409028 which has a few more solutions, + in case Amazon break this mechanism. + :param instance_identity_document_response: json returned via the web page ../dynamic/instance-identity/document + :return: The account id + """ return json.loads(instance_identity_document_response)[ACCOUNT_ID_KEY] def get_account_id(self): + """ + :return: the AWS account ID which "owns" this instance. + See https://docs.aws.amazon.com/general/latest/gr/acct-identifiers.html + """ return self.account_id diff --git a/monkey/monkey_island/cc/app.py b/monkey/monkey_island/cc/app.py index e6f6c2ed3..c23213eac 100644 --- a/monkey/monkey_island/cc/app.py +++ b/monkey/monkey_island/cc/app.py @@ -99,7 +99,7 @@ def init_app(mongo_url): database.init() ConfigService.init_config() - # If on AWS, this will set the instance - for usage later in the code. + # If running on AWS, this will initialize the instance data, which is used "later" in the execution of the island. RemoteRunAwsService.init() app.add_url_rule('/', 'serve_home', serve_home) diff --git a/monkey/monkey_island/cc/resources/aws_exporter.py b/monkey/monkey_island/cc/resources/aws_exporter.py index c8a75ec34..7e1f17c48 100644 --- a/monkey/monkey_island/cc/resources/aws_exporter.py +++ b/monkey/monkey_island/cc/resources/aws_exporter.py @@ -9,7 +9,7 @@ from common.cloud.aws_instance import AwsInstance from monkey_island.cc.environment.environment import load_server_configuration_from_file from monkey_island.cc.resources.exporter import Exporter -__author__ = 'maor.rayzin' +__authors__ = ['maor.rayzin', 'shay.nehmad'] logger = logging.getLogger(__name__) diff --git a/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage.js b/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage.js index 420e1c457..e67b40728 100644 --- a/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage.js +++ b/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage.js @@ -77,26 +77,30 @@ class RunMonkeyPageComponent extends AuthComponent { .then(res => res.json()) .then(res =>{ let is_aws = res['is_aws']; - // Checks if there was an error while collecting the aws machines. - let is_error_while_collecting_aws_machines = (res['error'] != null); if (is_aws) { + // On AWS! + // Checks if there was an error while collecting the aws machines. + let is_error_while_collecting_aws_machines = (res['error'] != null); if (is_error_while_collecting_aws_machines) { + // There was an error. Finish loading, and display error message. this.setState({isOnAws: true, isErrorWhileCollectingAwsMachines: true, awsMachineCollectionErrorMsg: res['error'], isLoadingAws: false}); } else { + // No error! Finish loading and display machines for user this.setState({isOnAws: true, awsMachines: res['instances'], isLoadingAws: false}); } } else { + // Not on AWS. Finish loading and don't display the AWS div. this.setState({isOnAws: false, isLoadingAws: false}); } }); } - generateLinuxCmd(ip, is32Bit) { + static generateLinuxCmd(ip, is32Bit) { let bitText = is32Bit ? '32' : '64'; return `wget --no-check-certificate https://${ip}:5000/api/monkey/download/monkey-linux-${bitText}; chmod +x monkey-linux-${bitText}; ./monkey-linux-${bitText} m0nk3y -s ${ip}:5000` } - generateWindowsCmd(ip, is32Bit) { + static generateWindowsCmd(ip, is32Bit) { let bitText = is32Bit ? '32' : '64'; return `powershell [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}; (New-Object System.Net.WebClient).DownloadFile('https://${ip}:5000/api/monkey/download/monkey-windows-${bitText}.exe','.\\monkey.exe'); ;Start-Process -FilePath '.\\monkey.exe' -ArgumentList 'm0nk3y -s ${ip}:5000';`; } @@ -129,9 +133,9 @@ class RunMonkeyPageComponent extends AuthComponent { let is32Bit = (this.state.selectedOs.split('-')[1] === '32'); let cmdText = ''; if (isLinux) { - cmdText = this.generateLinuxCmd(this.state.selectedIp, is32Bit); + cmdText = RunMonkeyPageComponent.generateLinuxCmd(this.state.selectedIp, is32Bit); } else { - cmdText = this.generateWindowsCmd(this.state.selectedIp, is32Bit); + cmdText = RunMonkeyPageComponent.generateWindowsCmd(this.state.selectedIp, is32Bit); } return ( @@ -159,7 +163,7 @@ class RunMonkeyPageComponent extends AuthComponent { }); }; - renderIconByState(state) { + static renderIconByState(state) { if (state === 'running') { return } else if (state === 'installing') { @@ -279,7 +283,7 @@ class RunMonkeyPageComponent extends AuthComponent { disabled={this.state.runningOnIslandState !== 'not_running'} > Run on Monkey Island Server - { this.renderIconByState(this.state.runningOnIslandState) } + { RunMonkeyPageComponent.renderIconByState(this.state.runningOnIslandState) } { // TODO: implement button functionality