Added some documentation

This commit is contained in:
Shay Nehmad 2019-04-24 10:41:52 +03:00
parent 1f75b72a97
commit 2fae4905fe
4 changed files with 25 additions and 10 deletions

View File

@ -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

View File

@ -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)

View File

@ -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__)

View File

@ -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 (
<Well key={'cmdDiv'+this.state.selectedIp} className="well-sm" style={{'margin': '0.5em'}}>
@ -159,7 +163,7 @@ class RunMonkeyPageComponent extends AuthComponent {
});
};
renderIconByState(state) {
static renderIconByState(state) {
if (state === 'running') {
return <Icon name="check" className="text-success" style={{'marginLeft': '5px'}}/>
} 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) }
</button>
{
// TODO: implement button functionality