forked from p15670423/monkey
cc, common: Split ransomware dir path validator regex expressions and rename related stuff to accurately describe it
This commit is contained in:
parent
54072b6632
commit
3496c717a9
|
@ -1,5 +1,5 @@
|
||||||
# Defined in UI on ValidationFormats.js
|
# Defined in UI on ValidationFormats.js
|
||||||
IP_RANGE = "ip-range"
|
IP_RANGE = "ip-range"
|
||||||
IP = "ip"
|
IP = "ip"
|
||||||
VALID_DIR_LINUX = "valid-directory-linux"
|
VALID_RANSOMWARE_TARGET_PATH_LINUX = "valid-ransomware-target-path-linux"
|
||||||
VALID_DIR_WINDOWS = "valid-directory-windows"
|
VALID_RANSOMWARE_TARGET_PATH_WINDOWS = "valid-ransomware-target-path-windows"
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
from common.common_consts.validation_formats import VALID_DIR_LINUX, VALID_DIR_WINDOWS
|
from common.common_consts.validation_formats import (
|
||||||
|
VALID_RANSOMWARE_TARGET_PATH_LINUX,
|
||||||
|
VALID_RANSOMWARE_TARGET_PATH_WINDOWS,
|
||||||
|
)
|
||||||
|
|
||||||
RANSOMWARE = {
|
RANSOMWARE = {
|
||||||
"title": "Ransomware",
|
"title": "Ransomware",
|
||||||
|
@ -22,7 +25,7 @@ RANSOMWARE = {
|
||||||
"linux_target_dir": {
|
"linux_target_dir": {
|
||||||
"title": "Linux target directory",
|
"title": "Linux target directory",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"format": VALID_DIR_LINUX,
|
"format": VALID_RANSOMWARE_TARGET_PATH_LINUX,
|
||||||
"default": "",
|
"default": "",
|
||||||
"description": "A path to a directory on Linux systems that contains "
|
"description": "A path to a directory on Linux systems that contains "
|
||||||
"files that you will allow Infection Monkey to encrypt. If no "
|
"files that you will allow Infection Monkey to encrypt. If no "
|
||||||
|
@ -31,7 +34,7 @@ RANSOMWARE = {
|
||||||
"windows_target_dir": {
|
"windows_target_dir": {
|
||||||
"title": "Windows target directory",
|
"title": "Windows target directory",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"format": VALID_DIR_WINDOWS,
|
"format": VALID_RANSOMWARE_TARGET_PATH_WINDOWS,
|
||||||
"default": "",
|
"default": "",
|
||||||
"description": "A path to a directory on Windows systems that contains "
|
"description": "A path to a directory on Windows systems that contains "
|
||||||
"files that you will allow Infection Monkey to encrypt. If no "
|
"files that you will allow Infection Monkey to encrypt. If no "
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import {IP, IP_RANGE, VALID_DIR_LINUX, VALID_DIR_WINDOWS} from './ValidationFormats';
|
import {IP, IP_RANGE, 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.';
|
let invalidDirMessage = 'Invalid directory. Path should be absolute or begin with an environment variable.';
|
||||||
|
|
||||||
|
@ -10,9 +10,9 @@ export default function transformErrors(errors) {
|
||||||
error.message = 'Invalid IP range, refer to description for valid examples.'
|
error.message = 'Invalid IP range, refer to description for valid examples.'
|
||||||
} else if (error.name === 'format' && error.params.format === IP) {
|
} else if (error.name === 'format' && error.params.format === IP) {
|
||||||
error.message = 'Invalid IP.'
|
error.message = 'Invalid IP.'
|
||||||
} else if (error.name === 'format' && error.params.format === VALID_DIR_LINUX) {
|
} else if (error.name === 'format' && error.params.format === VALID_RANSOMWARE_TARGET_PATH_LINUX) {
|
||||||
error.message = invalidDirMessage
|
error.message = invalidDirMessage
|
||||||
} else if (error.name === 'format' && error.params.format === VALID_DIR_WINDOWS) {
|
} else if (error.name === 'format' && error.params.format === VALID_RANSOMWARE_TARGET_PATH_WINDOWS) {
|
||||||
error.message = invalidDirMessage
|
error.message = invalidDirMessage
|
||||||
}
|
}
|
||||||
return error;
|
return error;
|
||||||
|
|
|
@ -1,22 +1,26 @@
|
||||||
const ipRegex = '((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)'
|
const ipRegex = '((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)'
|
||||||
const cidrNotationRegex = '([0-9]|1[0-9]|2[0-9]|3[0-2])'
|
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 hostnameRegex = '^([A-Za-z0-9]*[A-Za-z]+[A-Za-z0-9]*.?)*([A-Za-z0-9]*[A-Za-z]+[A-Za-z0-9]*)$'
|
||||||
// path is empty, or starts with `/` OR `$`
|
|
||||||
const linuxDirRegex = '(^\\s*$)|^/|^\\$'
|
const linuxAbsolutePathRegex = '^/' // path starts with `/`
|
||||||
// path is empty, or starts like `C:\` OR `C:/` OR `$` OR `%abc%`
|
const linuxPathStartsWithEnvVariableRegex = '^\\$' // path starts with `$`
|
||||||
const windowsDirRegex = '(^\\s*$)|^([A-Za-z]:(\\\\|\\/))|^\\$|^(%\\w*\\d*\\s*%)'
|
|
||||||
|
const windowsAbsolutePathRegex = '^([A-Za-z]:(\\\\|\\/))' // path starts like `C:\` OR `C:/`
|
||||||
|
const windowsPathStartsWithEnvVariableRegex = '^\\$|^(%\\w*\\d*\\s*%)' // path starts like `$` OR `%abc%`
|
||||||
|
|
||||||
|
const whitespacesOnlyRegex = '^\\s*$'
|
||||||
|
|
||||||
|
|
||||||
export const IP_RANGE = 'ip-range';
|
export const IP_RANGE = 'ip-range';
|
||||||
export const IP = 'ip';
|
export const IP = 'ip';
|
||||||
export const VALID_DIR_LINUX = 'valid-directory-linux'
|
export const VALID_RANSOMWARE_TARGET_PATH_LINUX = 'valid-ransomware-target-path-linux'
|
||||||
export const VALID_DIR_WINDOWS = 'valid-directory-windows'
|
export const VALID_RANSOMWARE_TARGET_PATH_WINDOWS = 'valid-ransomware-target-path-windows'
|
||||||
|
|
||||||
export const formValidationFormats = {
|
export const formValidationFormats = {
|
||||||
[IP_RANGE]: buildIpRangeRegex(),
|
[IP_RANGE]: buildIpRangeRegex(),
|
||||||
[IP]: buildIpRegex(),
|
[IP]: buildIpRegex(),
|
||||||
[VALID_DIR_LINUX]: buildValidDirLinuxRegex(),
|
[VALID_RANSOMWARE_TARGET_PATH_LINUX]: buildValidRansomwarePathLinuxRegex(),
|
||||||
[VALID_DIR_WINDOWS]: buildValidDirWindowsRegex()
|
[VALID_RANSOMWARE_TARGET_PATH_WINDOWS]: buildValidRansomwarePathWindowsRegex()
|
||||||
};
|
};
|
||||||
|
|
||||||
function buildIpRangeRegex(){
|
function buildIpRangeRegex(){
|
||||||
|
@ -32,10 +36,18 @@ function buildIpRegex(){
|
||||||
return new RegExp('^'+ipRegex+'$')
|
return new RegExp('^'+ipRegex+'$')
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildValidDirLinuxRegex() {
|
function buildValidRansomwarePathLinuxRegex() {
|
||||||
return new RegExp(linuxDirRegex)
|
return new RegExp([
|
||||||
|
whitespacesOnlyRegex,
|
||||||
|
linuxAbsolutePathRegex,
|
||||||
|
linuxPathStartsWithEnvVariableRegex
|
||||||
|
].join('|'))
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildValidDirWindowsRegex() {
|
function buildValidRansomwarePathWindowsRegex() {
|
||||||
return new RegExp(windowsDirRegex)
|
return new RegExp([
|
||||||
|
whitespacesOnlyRegex,
|
||||||
|
windowsAbsolutePathRegex,
|
||||||
|
windowsPathStartsWithEnvVariableRegex
|
||||||
|
].join('|'))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue