forked from p34709852/monkey
Added some documentation
This commit is contained in:
parent
1f75b72a97
commit
2fae4905fe
|
@ -62,7 +62,18 @@ class AwsInstance(object):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _extract_account_id(instance_identity_document_response):
|
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]
|
return json.loads(instance_identity_document_response)[ACCOUNT_ID_KEY]
|
||||||
|
|
||||||
def get_account_id(self):
|
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
|
return self.account_id
|
||||||
|
|
|
@ -99,7 +99,7 @@ def init_app(mongo_url):
|
||||||
database.init()
|
database.init()
|
||||||
ConfigService.init_config()
|
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()
|
RemoteRunAwsService.init()
|
||||||
|
|
||||||
app.add_url_rule('/', 'serve_home', serve_home)
|
app.add_url_rule('/', 'serve_home', serve_home)
|
||||||
|
|
|
@ -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.environment.environment import load_server_configuration_from_file
|
||||||
from monkey_island.cc.resources.exporter import Exporter
|
from monkey_island.cc.resources.exporter import Exporter
|
||||||
|
|
||||||
__author__ = 'maor.rayzin'
|
__authors__ = ['maor.rayzin', 'shay.nehmad']
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
|
@ -77,26 +77,30 @@ class RunMonkeyPageComponent extends AuthComponent {
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
.then(res =>{
|
.then(res =>{
|
||||||
let is_aws = res['is_aws'];
|
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) {
|
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) {
|
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});
|
this.setState({isOnAws: true, isErrorWhileCollectingAwsMachines: true, awsMachineCollectionErrorMsg: res['error'], isLoadingAws: false});
|
||||||
} else {
|
} else {
|
||||||
|
// No error! Finish loading and display machines for user
|
||||||
this.setState({isOnAws: true, awsMachines: res['instances'], isLoadingAws: false});
|
this.setState({isOnAws: true, awsMachines: res['instances'], isLoadingAws: false});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// Not on AWS. Finish loading and don't display the AWS div.
|
||||||
this.setState({isOnAws: false, isLoadingAws: false});
|
this.setState({isOnAws: false, isLoadingAws: false});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
generateLinuxCmd(ip, is32Bit) {
|
static generateLinuxCmd(ip, is32Bit) {
|
||||||
let bitText = is32Bit ? '32' : '64';
|
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`
|
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';
|
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';`;
|
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 is32Bit = (this.state.selectedOs.split('-')[1] === '32');
|
||||||
let cmdText = '';
|
let cmdText = '';
|
||||||
if (isLinux) {
|
if (isLinux) {
|
||||||
cmdText = this.generateLinuxCmd(this.state.selectedIp, is32Bit);
|
cmdText = RunMonkeyPageComponent.generateLinuxCmd(this.state.selectedIp, is32Bit);
|
||||||
} else {
|
} else {
|
||||||
cmdText = this.generateWindowsCmd(this.state.selectedIp, is32Bit);
|
cmdText = RunMonkeyPageComponent.generateWindowsCmd(this.state.selectedIp, is32Bit);
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<Well key={'cmdDiv'+this.state.selectedIp} className="well-sm" style={{'margin': '0.5em'}}>
|
<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') {
|
if (state === 'running') {
|
||||||
return <Icon name="check" className="text-success" style={{'marginLeft': '5px'}}/>
|
return <Icon name="check" className="text-success" style={{'marginLeft': '5px'}}/>
|
||||||
} else if (state === 'installing') {
|
} else if (state === 'installing') {
|
||||||
|
@ -279,7 +283,7 @@ class RunMonkeyPageComponent extends AuthComponent {
|
||||||
disabled={this.state.runningOnIslandState !== 'not_running'}
|
disabled={this.state.runningOnIslandState !== 'not_running'}
|
||||||
>
|
>
|
||||||
Run on Monkey Island Server
|
Run on Monkey Island Server
|
||||||
{ this.renderIconByState(this.state.runningOnIslandState) }
|
{ RunMonkeyPageComponent.renderIconByState(this.state.runningOnIslandState) }
|
||||||
</button>
|
</button>
|
||||||
{
|
{
|
||||||
// TODO: implement button functionality
|
// TODO: implement button functionality
|
||||||
|
|
Loading…
Reference in New Issue