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 e90292406..aefa19921 100644 --- a/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage.js +++ b/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage.js @@ -1,5 +1,5 @@ import React from 'react'; -import {Button, Col, Well, Nav, NavItem, Collapse} from 'react-bootstrap'; +import {Button, Col, Well, Nav, NavItem, Collapse, Form, FormControl, FormGroup} from 'react-bootstrap'; import CopyToClipboard from 'react-copy-to-clipboard'; import {Icon} from 'react-fa'; import {Link} from 'react-router-dom'; @@ -20,8 +20,13 @@ class RunMonkeyPageComponent extends AuthComponent { showManual: false, showAws: false, isOnAws: false, + isAwsAuth: false, + awsUpdateClicked: false, + awsUpdateFailed: false, + awsKeyId: '', + awsSecretKey: '', awsMachines: [] - }; + }; } componentDidMount() { @@ -42,16 +47,13 @@ class RunMonkeyPageComponent extends AuthComponent { } }); - this.authFetch('/api/remote-monkey?action=list_aws') - .then(res => res.json()) - .then(res =>{ - let is_aws = res['is_aws']; - if (is_aws) { - let instances = res['instances']; - if (instances) { - this.setState({isOnAws: true, awsMachines: instances}); - } - } + this.fetchAwsInfo(); + this.fetchConfig() + .then(config => { + this.setState({ + awsKeyId: config['cnc']['aws_config']['aws_access_key_id'], + awsSecretKey: config['cnc']['aws_config']['aws_secret_access_key'] + }); }); this.authFetch('/api/client-monkey') @@ -67,6 +69,17 @@ class RunMonkeyPageComponent extends AuthComponent { this.props.onStatusChange(); } + fetchAwsInfo() { + return this.authFetch('/api/remote-monkey?action=list_aws') + .then(res => res.json()) + .then(res =>{ + let is_aws = res['is_aws']; + if (is_aws) { + this.setState({isOnAws: true, awsMachines: res['instances'], isAwsAuth: res['auth']}); + } + }); + } + 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` @@ -192,6 +205,60 @@ class RunMonkeyPageComponent extends AuthComponent { }); }; + updateAwsKeyId = (evt) => { + this.setState({ + awsKeyId: evt.target.value + }); + }; + + updateAwsSecretKey = (evt) => { + this.setState({ + awsSecretKey: evt.target.value + }); + }; + + fetchConfig() { + return this.authFetch('/api/configuration/island') + .then(res => res.json()) + .then(res => { + return res.configuration; + }) + } + + updateAwsKeys = () => { + this.setState({ + awsUpdateClicked: true, + awsUpdateFailed: false + }); + this.fetchConfig() + .then(config => { + let new_config = config; + new_config['cnc']['aws_config']['aws_access_key_id'] = this.state.awsKeyId; + new_config['cnc']['aws_config']['aws_secret_access_key'] = this.state.awsSecretKey; + return new_config; + }) + .then(new_config => { + this.authFetch('/api/configuration/island', + { + method: 'POST', + headers: {'Content-Type': 'application/json'}, + body: JSON.stringify(new_config) + }) + .then(res => res.json()) + .then(res => { + this.fetchAwsInfo() + .then(res => { + if (!this.state.isAwsAuth) { + this.setState({ + awsUpdateClicked: false, + awsUpdateFailed: true + }) + } + }); + }); + }); + }; + instanceIdToInstance = (instance_id) => { let instance = this.state.awsMachines.find( function (inst) { @@ -201,6 +268,80 @@ class RunMonkeyPageComponent extends AuthComponent { }; + renderAuthAwsDiv() { + return ( +
+

+ Select Island IP address +

+ { + this.state.ips.length > 1 ? + + :
+ } + + (this.awsTable = r)} + /> +
+ +
+
+ ) + } + + renderNotAuthAwsDiv() { + return ( +
+

+ You haven't set your AWS account details or they're incorrect. Please enter them below to proceed. +

+
+
+
+
+
+
+ this.updateAwsKeyId(evt)}/> + this.updateAwsSecretKey(evt)}/> + + { + this.state.awsUpdateFailed ? +
Authentication failed. Bad credentials.
+ : + null + } +
+
+
+
+
+
+
+ ) + } + render() { return ( @@ -282,31 +423,10 @@ class RunMonkeyPageComponent extends AuthComponent { null } -
-

- Select server IP address -

- { - this.state.ips.length > 1 ? - - :
- } + { + this.state.isAwsAuth ? this.renderAuthAwsDiv() : this.renderNotAuthAwsDiv() + } - (this.awsTable = r)} - /> - -