From b08097b131e8bff5a3e91e862c3315a7b62e5954 Mon Sep 17 00:00:00 2001 From: vakaris_zilius Date: Tue, 6 Sep 2022 13:24:03 +0000 Subject: [PATCH] Island, Common: Small style improvements --- monkey/common/credentials/lm_hash.py | 2 +- monkey/common/credentials/nt_hash.py | 2 +- .../configuration-components/ReformatHook.js | 48 +++++++++++-------- .../report-components/credentialParsing.js | 8 ++-- 4 files changed, 35 insertions(+), 25 deletions(-) diff --git a/monkey/common/credentials/lm_hash.py b/monkey/common/credentials/lm_hash.py index 02525d386..9dd201536 100644 --- a/monkey/common/credentials/lm_hash.py +++ b/monkey/common/credentials/lm_hash.py @@ -12,5 +12,5 @@ class LMHash(BaseModel): @validator("lm_hash") def validate_hash_format(cls, nt_hash): if not re.match(ntlm_hash_regex, nt_hash): - raise ValueError(f"Invalid lm hash provided: {nt_hash}") + raise ValueError(f"Invalid LM hash provided: {nt_hash}") return nt_hash diff --git a/monkey/common/credentials/nt_hash.py b/monkey/common/credentials/nt_hash.py index dd288afba..5a5dacd97 100644 --- a/monkey/common/credentials/nt_hash.py +++ b/monkey/common/credentials/nt_hash.py @@ -12,5 +12,5 @@ class NTHash(InfectionMonkeyBaseModel): @validator("nt_hash") def validate_hash_format(cls, nt_hash): if not re.match(ntlm_hash_regex, nt_hash): - raise ValueError(f"Invalid nt hash provided: {nt_hash}") + raise ValueError(f"Invalid NT hash provided: {nt_hash}") return nt_hash diff --git a/monkey/monkey_island/cc/ui/src/components/configuration-components/ReformatHook.js b/monkey/monkey_island/cc/ui/src/components/configuration-components/ReformatHook.js index 239d0c5a0..5792a82ba 100644 --- a/monkey/monkey_island/cc/ui/src/components/configuration-components/ReformatHook.js +++ b/monkey/monkey_island/cc/ui/src/components/configuration-components/ReformatHook.js @@ -6,16 +6,21 @@ export function reformatConfig(config, reverse = false) { let formattedConfig = _.clone(config); if (reverse) { - if(formattedConfig['payloads'].length === 1){ + if (formattedConfig['payloads'].length === 1) { // Second click on Export - formattedConfig['payloads'] = [{'name': 'ransomware', 'options': formattedConfig['payloads'][0]['options']}]; + formattedConfig['payloads'] = [{ + 'name': 'ransomware', + 'options': formattedConfig['payloads'][0]['options'] + }]; } else { - formattedConfig['payloads'] = [{'name': 'ransomware', 'options': formattedConfig['payloads']}]; + formattedConfig['payloads'] = [{ + 'name': 'ransomware', + 'options': formattedConfig['payloads'] + }]; } formattedConfig['keep_tunnel_open_time'] = formattedConfig['advanced']['keep_tunnel_open_time']; } else { - if(formattedConfig['payloads'].length !== 0) - { + if (formattedConfig['payloads'].length !== 0) { formattedConfig['payloads'] = formattedConfig['payloads'][0]['options']; } else { formattedConfig['payloads'] = {'encryption': {}, 'other_behaviors': {}} @@ -30,23 +35,26 @@ export function formatCredentialsForForm(credentials) { let formattedCredentials = _.clone(defaultCredentials); for (let i = 0; i < credentials.length; i++) { let identity = credentials[i]['identity']; - if(identity !== null) { + if (identity !== null) { formattedCredentials['exploit_user_list'].push(identity.username) } let secret = credentials[i]['secret']; - if(secret !== null){ - if (secret.hasOwnProperty(SecretTypes.Password)) { + if (secret !== null) { + if (Object.prototype.hasOwnProperty.call(secret, SecretTypes.Password)) { formattedCredentials['exploit_password_list'].push(secret[SecretTypes.Password]) } - if (secret.hasOwnProperty(SecretTypes.NTHash)) { + if (Object.prototype.hasOwnProperty.call(secret, SecretTypes.NTHash)) { formattedCredentials['exploit_ntlm_hash_list'].push(secret[SecretTypes.NTHash]) } - if (secret.hasOwnProperty(SecretTypes.LMHash)) { + if (Object.prototype.hasOwnProperty.call(secret, SecretTypes.LMHash)) { formattedCredentials['exploit_lm_hash_list'].push(secret[SecretTypes.LMHash]) } - if (secret.hasOwnProperty(SecretTypes.PrivateKey)) { - let keypair = {'public_key': secret[PlaintextTypes.PublicKey], 'private_key': secret[SecretTypes.PrivateKey]} + if (Object.prototype.hasOwnProperty.call(secret, SecretTypes.PrivateKey)) { + let keypair = { + 'public_key': secret[PlaintextTypes.PublicKey], + 'private_key': secret[SecretTypes.PrivateKey] + } formattedCredentials['exploit_ssh_keys'].push(keypair) } } @@ -78,8 +86,10 @@ export function formatCredentialsForIsland(credentials) { for (let i = 0; i < ssh_keys.length; i++) { formattedCredentials.push({ 'identity': null, - 'secret': {'private_key': ssh_keys[i]['private_key'], - 'public_key': ssh_keys[i]['public_key']} + 'secret': { + 'private_key': ssh_keys[i]['private_key'], + 'public_key': ssh_keys[i]['public_key'] + } }) } @@ -89,10 +99,10 @@ export function formatCredentialsForIsland(credentials) { function getFormattedCredentials(credentials, keyOfSecret) { let formattedCredentials = []; for (let i = 0; i < credentials.length; i++) { - formattedCredentials.push({ - 'identity': null, - 'secret': {[keyOfSecret]: credentials[i]} - }) - } + formattedCredentials.push({ + 'identity': null, + 'secret': {[keyOfSecret]: credentials[i]} + }) + } return formattedCredentials; } diff --git a/monkey/monkey_island/cc/ui/src/components/report-components/credentialParsing.js b/monkey/monkey_island/cc/ui/src/components/report-components/credentialParsing.js index affc9d967..fc77f6d4f 100644 --- a/monkey/monkey_island/cc/ui/src/components/report-components/credentialParsing.js +++ b/monkey/monkey_island/cc/ui/src/components/report-components/credentialParsing.js @@ -36,16 +36,16 @@ export function getAllSecrets(stolen, configured) { } function reformatSecret(secret) { - if (secret.hasOwnProperty(SecretTypes.Password)) { + if (Object.prototype.hasOwnProperty.call(secret, SecretTypes.Password)) { return {'title': CredentialTitles.Password, 'content': secret[SecretTypes.Password]} } - if (secret.hasOwnProperty(SecretTypes.NTHash)) { + if (Object.prototype.hasOwnProperty.call(secret, SecretTypes.NTHash)) { return {'title': CredentialTitles.NTHash, 'content': secret[SecretTypes.NTHash]} } - if (secret.hasOwnProperty(SecretTypes.LMHash)) { + if (Object.prototype.hasOwnProperty.call(secret, SecretTypes.LMHash)) { return {'title': CredentialTitles.LMHash, 'content': secret[SecretTypes.LMHash]} } - if (secret.hasOwnProperty(SecretTypes.PrivateKey)) { + if (Object.prototype.hasOwnProperty.call(secret, SecretTypes.PrivateKey)) { return { 'title': CredentialTitles.SSHKeys, 'content': secret[SecretTypes.PrivateKey]