ui: generalize isUnsafeOptionSelected

This commit is contained in:
Mike Salvatore 2021-02-26 14:33:42 -05:00
parent dd7c1bb08c
commit 67e142f4fe
3 changed files with 51 additions and 41 deletions

View File

@ -11,6 +11,9 @@ from monkey_island.cc.services.config_schema.monkey import MONKEY
SCHEMA = {
"title": "Monkey",
"type": "object",
# Newly added definitions should also be added to
# monkey/monkey_island/cc/ui/src/components/utils/SafeOptionValidator.js so that
# users will not accidentally chose unsafe options
"definitions": {
"exploiter_classes": EXPLOITER_CLASSES,
"system_info_collector_classes": SYSTEM_INFO_COLLECTOR_CLASSES,

View File

@ -12,25 +12,13 @@ import {formValidationFormats} from '../configuration-components/ValidationForma
import transformErrors from '../configuration-components/ValidationErrorMessages';
import InternalConfig from '../configuration-components/InternalConfig';
import UnsafeOptionsConfirmationModal from '../configuration-components/UnsafeOptionsConfirmationModal.js';
import isUnsafeOptionSelected from '../utils/SafeOptionValidator.js'
const ATTACK_URL = '/api/attack';
const CONFIG_URL = '/api/configuration/island';
export const API_PBA_LINUX = '/api/fileUpload/PBAlinux';
export const API_PBA_WINDOWS = '/api/fileUpload/PBAwindows';
function isUnsafeItemSelected(allOptions, selectedOptions) {
let optionSafety = new Map();
allOptions.forEach(i => optionSafety[i.enum[0]] = i.safe);
for (let selected of selectedOptions) {
if (!optionSafety[selected]) {
return true;
}
}
return false;
}
class ConfigurePageComponent extends AuthComponent {
constructor(props) {
@ -122,34 +110,7 @@ class ConfigurePageComponent extends AuthComponent {
};
canSafelySubmitConfig(config) {
return !this.unsafeOptionsSelected(config);
}
unsafeOptionsSelected(config) {
return (this.unsafeExploiterSelected(config)
|| this.unsafePostBreachActionSelected(config)
|| this.unsafeSystemInfoCollectorSelected(config));
}
unsafeExploiterSelected(config) {
return isUnsafeItemSelected(
this.state.schema.definitions.exploiter_classes.anyOf,
config.basic.exploiters.exploiter_classes
);
}
unsafePostBreachActionSelected(config) {
return isUnsafeItemSelected(
this.state.schema.definitions.post_breach_actions.anyOf,
config.monkey.post_breach.post_breach_actions
);
}
unsafeSystemInfoCollectorSelected(config) {
return isUnsafeItemSelected(
this.state.schema.definitions.system_info_collector_classes.anyOf,
config.monkey.system_info.system_info_collector_classes
);
return !isUnsafeOptionSelected(this.state.schema, config);
}
matrixSubmit = () => {

View File

@ -0,0 +1,46 @@
function getPluginDescriptors(schema, config) {
return ([
{
name: 'Exploiters',
allPlugins: schema.definitions.exploiter_classes.anyOf,
selectedPlugins: config.basic.exploiters.exploiter_classes
},
{
name: 'PostBreachActions',
allPlugins: schema.definitions.post_breach_actions.anyOf,
selectedPlugins: config.monkey.post_breach.post_breach_actions
},
{
name: 'SystemInfoCollectors',
allPlugins: schema.definitions.system_info_collector_classes.anyOf,
selectedPlugins: config.monkey.system_info.system_info_collector_classes
}
]);
}
function isUnsafeOptionSelected(schema, config) {
let pluginDescriptors = getPluginDescriptors(schema, config);
for (let descriptor of pluginDescriptors) {
if (isUnsafePluginSelected(descriptor)) {
return true;
}
}
return false;
}
function isUnsafePluginSelected(pluginDescriptor) {
let pluginSafety = new Map();
pluginDescriptor.allPlugins.forEach(i => pluginSafety[i.enum[0]] = i.safe);
for (let selected of pluginDescriptor.selectedPlugins) {
if (!pluginSafety[selected]) {
return true;
}
}
return false;
}
export default isUnsafeOptionSelected;