UI: Add field for ransomed file extension

This commit is contained in:
Kekoa Kaaikala 2022-08-17 20:10:23 +00:00
parent 639fb26445
commit 4f776f0102
3 changed files with 33 additions and 20 deletions

View File

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

View File

@ -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 `$`
@ -19,27 +20,29 @@ 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() {

View File

@ -20,6 +20,14 @@ const RANSOMWARE_SCHEMA = {
'info': 'No files will be encrypted if a directory is not specified or doesn\'t ' +
'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',
'type': 'object',