From 4f776f0102d0934efdbb88c248b0511fa24fa59f Mon Sep 17 00:00:00 2001 From: Kekoa Kaaikala Date: Wed, 17 Aug 2022 20:10:23 +0000 Subject: [PATCH] UI: Add field for ransomed file extension --- .../ValidationErrorMessages.js | 4 ++- .../ValidationFormats.js | 21 ++++++++------ .../src/services/configuration/ransomware.js | 28 ++++++++++++------- 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/monkey/monkey_island/cc/ui/src/components/configuration-components/ValidationErrorMessages.js b/monkey/monkey_island/cc/ui/src/components/configuration-components/ValidationErrorMessages.js index 3c7280f97..deae004c9 100644 --- a/monkey/monkey_island/cc/ui/src/components/configuration-components/ValidationErrorMessages.js +++ b/monkey/monkey_island/cc/ui/src/components/configuration-components/ValidationErrorMessages.js @@ -1,4 +1,4 @@ -import {IP, IP_RANGE, VALID_RANSOMWARE_TARGET_PATH_LINUX, VALID_RANSOMWARE_TARGET_PATH_WINDOWS} from './ValidationFormats'; +import { IP, IP_RANGE, VALID_FILE_EXTENSION, VALID_RANSOMWARE_TARGET_PATH_LINUX, VALID_RANSOMWARE_TARGET_PATH_WINDOWS } from './ValidationFormats'; let invalidDirMessage = 'Invalid directory. Path should be absolute or begin with an environment variable.'; @@ -10,6 +10,8 @@ export default function transformErrors(errors) { error.message = 'Invalid IP range, refer to description for valid examples.' } else if (error.name === 'format' && error.params.format === IP) { error.message = 'Invalid IP.' + } else if (error.name === 'format' && error.params.format === VALID_FILE_EXTENSION) { + error.message = 'Invalid file extension.' } else if (error.name === 'format' && error.params.format === VALID_RANSOMWARE_TARGET_PATH_LINUX) { error.message = invalidDirMessage } else if (error.name === 'format' && error.params.format === VALID_RANSOMWARE_TARGET_PATH_WINDOWS) { diff --git a/monkey/monkey_island/cc/ui/src/components/configuration-components/ValidationFormats.js b/monkey/monkey_island/cc/ui/src/components/configuration-components/ValidationFormats.js index 70d9f82fd..f6539e24a 100644 --- a/monkey/monkey_island/cc/ui/src/components/configuration-components/ValidationFormats.js +++ b/monkey/monkey_island/cc/ui/src/components/configuration-components/ValidationFormats.js @@ -2,6 +2,7 @@ const ipRegex = '((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0 const cidrNotationRegex = '([0-9]|1[0-9]|2[0-9]|3[0-2])' const hostnameRegex = '^([A-Za-z0-9]*[A-Za-z]+[A-Za-z0-9]*.?)*([A-Za-z0-9]*[A-Za-z]+[A-Za-z0-9]*)$' +const fileExtensionRegex = /^(\.[A-Za-z0-9_]+)*$/ const linuxAbsolutePathRegex = /^\// // path starts with `/` const linuxPathStartsWithEnvVariableRegex = /^\$/ // path starts with `$` @@ -11,7 +12,7 @@ const linuxPathStartsWithTildeRegex = /^~/ // path starts with `~` const windowsAbsolutePathRegex = /^([A-Za-z]:(\\|\/))/ // path starts like `C:\` OR `C:/` const windowsEnvVarNonNumeric = '[A-Za-z#\\$\'\\(\\)\\*\\+,\\-\\.\\?@\\[\\]_`\\{\\}~ ]' const windowsPathStartsWithEnvVariableRegex = new RegExp( - `^%(${windowsEnvVarNonNumeric}+(${windowsEnvVarNonNumeric}|\\d)*)%` + `^%(${windowsEnvVarNonNumeric}+(${windowsEnvVarNonNumeric}|\\d)*)%` ) // path starts like `$` OR `%abc%` const windowsUncPathRegex = /^\\{2}/ // Path starts like `\\` const emptyRegex = /^$/ @@ -19,32 +20,34 @@ const emptyRegex = /^$/ export const IP_RANGE = 'ip-range'; export const IP = 'ip'; +export const VALID_FILE_EXTENSION = 'valid-file-extension' export const VALID_RANSOMWARE_TARGET_PATH_LINUX = 'valid-ransomware-target-path-linux' export const VALID_RANSOMWARE_TARGET_PATH_WINDOWS = 'valid-ransomware-target-path-windows' export const formValidationFormats = { [IP_RANGE]: buildIpRangeRegex(), [IP]: buildIpRegex(), + [VALID_FILE_EXTENSION]: fileExtensionRegex, [VALID_RANSOMWARE_TARGET_PATH_LINUX]: buildValidRansomwarePathLinuxRegex(), [VALID_RANSOMWARE_TARGET_PATH_WINDOWS]: buildValidRansomwarePathWindowsRegex() }; -function buildIpRangeRegex(){ +function buildIpRangeRegex() { return new RegExp([ - '^'+ipRegex+'$|', // Single: IP - '^'+ipRegex+'-'+ipRegex+'$|', // IP range: IP-IP - '^'+ipRegex+'/'+cidrNotationRegex+'$|', // IP range with cidr notation: IP/cidr + '^' + ipRegex + '$|', // Single: IP + '^' + ipRegex + '-' + ipRegex + '$|', // IP range: IP-IP + '^' + ipRegex + '/' + cidrNotationRegex + '$|', // IP range with cidr notation: IP/cidr hostnameRegex // Hostname: target.tg ].join('')) } -function buildIpRegex(){ - return new RegExp('^'+ipRegex+'$') +function buildIpRegex() { + return new RegExp('^' + ipRegex + '$') } function buildValidRansomwarePathLinuxRegex() { return new RegExp([ - emptyRegex.source, + emptyRegex.source, linuxAbsolutePathRegex.source, linuxPathStartsWithEnvVariableRegex.source, linuxPathStartsWithTildeRegex.source @@ -53,7 +56,7 @@ function buildValidRansomwarePathLinuxRegex() { function buildValidRansomwarePathWindowsRegex() { return new RegExp([ - emptyRegex.source, + emptyRegex.source, windowsAbsolutePathRegex.source, windowsPathStartsWithEnvVariableRegex.source, windowsUncPathRegex.source diff --git a/monkey/monkey_island/cc/ui/src/services/configuration/ransomware.js b/monkey/monkey_island/cc/ui/src/services/configuration/ransomware.js index ea0262b69..2e0d0b804 100644 --- a/monkey/monkey_island/cc/ui/src/services/configuration/ransomware.js +++ b/monkey/monkey_island/cc/ui/src/services/configuration/ransomware.js @@ -1,24 +1,32 @@ const RANSOMWARE_SCHEMA = { - 'title': 'Payloads', + 'title': 'Payloads', 'properties': { 'encryption': { 'title': 'Ransomware simulation', 'type': 'object', 'description': 'To simulate ransomware encryption, you\'ll need to provide Infection ' + - 'Monkey with files that it can safely encrypt. On each machine where you would like ' + - 'the ransomware simulation to run, create a directory and put some files in it.' + - '\n\nProvide the path to the directory that was created on each machine.', + 'Monkey with files that it can safely encrypt. On each machine where you would like ' + + 'the ransomware simulation to run, create a directory and put some files in it.' + + '\n\nProvide the path to the directory that was created on each machine.', 'properties': { 'enabled': { 'title': 'Encrypt files', 'type': 'boolean', 'default': true, 'description': 'Ransomware encryption will be simulated by flipping every bit ' + - 'in the files contained within the target directories.' + 'in the files contained within the target directories.' }, 'info_box': { 'info': 'No files will be encrypted if a directory is not specified or doesn\'t ' + - 'exist on a victim machine.' + 'exist on a victim machine.' + }, + 'file_extension': { + 'title': 'File extension', + 'type': 'string', + 'format': 'valid-file-extension', + 'default': '.m0nk3y', + 'description': 'The file extension that the Infection Monkey will use for the ' + + 'encrypted file.' }, 'directories': { 'title': 'Directories to encrypt', @@ -30,8 +38,8 @@ const RANSOMWARE_SCHEMA = { 'format': 'valid-ransomware-target-path-linux', 'default': '', 'description': 'A path to a directory on Linux systems that contains ' + - 'files that you will allow Infection Monkey to encrypt. If no ' + - 'directory is specified, no files will be encrypted.' + 'files that you will allow Infection Monkey to encrypt. If no ' + + 'directory is specified, no files will be encrypted.' }, 'windows_target_dir': { 'title': 'Windows target directory', @@ -39,8 +47,8 @@ const RANSOMWARE_SCHEMA = { 'format': 'valid-ransomware-target-path-windows', 'default': '', 'description': 'A path to a directory on Windows systems that contains ' + - 'files that you will allow Infection Monkey to encrypt. If no ' + - 'directory is specified, no files will be encrypted.' + 'files that you will allow Infection Monkey to encrypt. If no ' + + 'directory is specified, no files will be encrypted.' } } },