From 967fec8487df40e9398f6b320d5960344a5e5ccb Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Mon, 8 Jul 2019 13:44:15 +0300 Subject: [PATCH] Refactored scan status to use numeric value and other PR fixes --- monkey/infection_monkey/monkey.py | 6 ++---- .../monkey_island/cc/services/attack/attack_report.py | 2 +- .../cc/services/attack/technique_reports/T1107.py | 2 +- .../cc/services/attack/technique_reports/__init__.py | 10 +++++----- .../cc/ui/src/components/attack/techniques/Helpers.js | 6 ++++++ .../cc/ui/src/components/attack/techniques/T1003.js | 3 ++- .../cc/ui/src/components/attack/techniques/T1059.js | 4 ++-- .../cc/ui/src/components/attack/techniques/T1075.js | 4 ++-- .../cc/ui/src/components/attack/techniques/T1082.js | 4 ++-- .../cc/ui/src/components/attack/techniques/T1086.js | 4 ++-- .../cc/ui/src/components/attack/techniques/T1107.js | 2 +- .../cc/ui/src/components/attack/techniques/T1110.js | 4 ++-- .../cc/ui/src/components/attack/techniques/T1145.js | 4 ++-- .../src/components/report-components/AttackReport.js | 5 +++-- 14 files changed, 33 insertions(+), 27 deletions(-) diff --git a/monkey/infection_monkey/monkey.py b/monkey/infection_monkey/monkey.py index c6c5ee8b5..37ac2c434 100644 --- a/monkey/infection_monkey/monkey.py +++ b/monkey/infection_monkey/monkey.py @@ -243,10 +243,8 @@ class InfectionMonkey(object): @staticmethod def self_delete(): - if utils.remove_monkey_dir(): - T1107Telem(ScanStatus.USED, utils.get_monkey_dir_path()).send() - else: - T1107Telem(ScanStatus.SCANNED, utils.get_monkey_dir_path()).send() + status = ScanStatus.USED if utils.remove_monkey_dir() else ScanStatus.SCANNED + T1107Telem(status, utils.get_monkey_dir_path()).send() if WormConfiguration.self_delete_in_cleanup \ and -1 == sys.executable.find('python'): diff --git a/monkey/monkey_island/cc/services/attack/attack_report.py b/monkey/monkey_island/cc/services/attack/attack_report.py index ff038c092..ce918aa60 100644 --- a/monkey/monkey_island/cc/services/attack/attack_report.py +++ b/monkey/monkey_island/cc/services/attack/attack_report.py @@ -58,12 +58,12 @@ class AttackReportService: Gets latest report (by retrieving it from db or generating a new one). :return: report dict. """ - return AttackReportService.generate_new_report() if AttackReportService.is_report_generated(): telem_time = AttackReportService.get_latest_attack_telem_time() latest_report = mongo.db.attack_report.find_one({'name': REPORT_NAME}) if telem_time and latest_report['latest_telem_time'] and telem_time == latest_report['latest_telem_time']: return latest_report + return AttackReportService.generate_new_report() @staticmethod def is_report_generated(): diff --git a/monkey/monkey_island/cc/services/attack/technique_reports/T1107.py b/monkey/monkey_island/cc/services/attack/technique_reports/T1107.py index fd9f1ad10..9448c2e6b 100644 --- a/monkey/monkey_island/cc/services/attack/technique_reports/T1107.py +++ b/monkey/monkey_island/cc/services/attack/technique_reports/T1107.py @@ -7,7 +7,7 @@ __author__ = "VakarisZ" class T1107(AttackTechnique): tech_id = "T1107" unscanned_msg = "" - scanned_msg = "Monkey tried to delete files on a system in the network but failed." + scanned_msg = "Monkey tried to delete files on systems in the network, but failed." used_msg = "Monkey successfully deleted files on systems in the network." query = [{'$match': {'telem_category': 'attack', diff --git a/monkey/monkey_island/cc/services/attack/technique_reports/__init__.py b/monkey/monkey_island/cc/services/attack/technique_reports/__init__.py index 81b7dd6bf..15ce5ac19 100644 --- a/monkey/monkey_island/cc/services/attack/technique_reports/__init__.py +++ b/monkey/monkey_island/cc/services/attack/technique_reports/__init__.py @@ -55,13 +55,13 @@ class AttackTechnique(object): if mongo.db.telemetry.find_one({'telem_category': 'attack', 'data.status': ScanStatus.USED.value, 'data.technique': cls.tech_id}): - return ScanStatus.USED + return ScanStatus.USED.value elif mongo.db.telemetry.find_one({'telem_category': 'attack', 'data.status': ScanStatus.SCANNED.value, 'data.technique': cls.tech_id}): - return ScanStatus.SCANNED + return ScanStatus.SCANNED.value else: - return ScanStatus.UNSCANNED + return ScanStatus.UNSCANNED.value @classmethod def get_message_and_status(cls, status): @@ -70,7 +70,7 @@ class AttackTechnique(object): :param status: Enum type value from common/attack_utils.py :return: Dict with message and status """ - return {'message': cls.get_message_by_status(status), 'status': status.name} + return {'message': cls.get_message_by_status(status), 'status': status.value} @classmethod def get_message_by_status(cls, status): @@ -102,7 +102,7 @@ class AttackTechnique(object): data = {} status = cls.technique_status() title = cls.technique_title() - data.update({'status': status.name, + data.update({'status': status, 'title': title, 'message': cls.get_message_by_status(status)}) return data diff --git a/monkey/monkey_island/cc/ui/src/components/attack/techniques/Helpers.js b/monkey/monkey_island/cc/ui/src/components/attack/techniques/Helpers.js index 1060f4b2d..b620e82d7 100644 --- a/monkey/monkey_island/cc/ui/src/components/attack/techniques/Helpers.js +++ b/monkey/monkey_island/cc/ui/src/components/attack/techniques/Helpers.js @@ -19,3 +19,9 @@ export function renderMachineFromSystemData(data) { }); return machineStr + ")" } + +export const scanStatus = { + UNSCANNED: 0, + SCANNED: 1, + USED: 2 +}; diff --git a/monkey/monkey_island/cc/ui/src/components/attack/techniques/T1003.js b/monkey/monkey_island/cc/ui/src/components/attack/techniques/T1003.js index d7783714a..208840cf3 100644 --- a/monkey/monkey_island/cc/ui/src/components/attack/techniques/T1003.js +++ b/monkey/monkey_island/cc/ui/src/components/attack/techniques/T1003.js @@ -2,6 +2,7 @@ import React from 'react'; import '../../../styles/Collapse.scss' import '../../report-components/StolenPasswords' import StolenPasswordsComponent from "../../report-components/StolenPasswords"; +import {scanStatus} from "./Helpers" class T1003 extends React.Component { @@ -15,7 +16,7 @@ class T1003 extends React.Component {
{this.props.data.message}

- {this.props.data.status === 'USED' ? + {this.props.data.status === scanStatus.USED ? : ""}
diff --git a/monkey/monkey_island/cc/ui/src/components/attack/techniques/T1059.js b/monkey/monkey_island/cc/ui/src/components/attack/techniques/T1059.js index 57d5bcb2c..8d5585829 100644 --- a/monkey/monkey_island/cc/ui/src/components/attack/techniques/T1059.js +++ b/monkey/monkey_island/cc/ui/src/components/attack/techniques/T1059.js @@ -1,7 +1,7 @@ import React from 'react'; import '../../../styles/Collapse.scss' import ReactTable from "react-table"; -import { renderMachine } from "./Helpers" +import { renderMachine, scanStatus } from "./Helpers" class T1059 extends React.Component { @@ -25,7 +25,7 @@ class T1059 extends React.Component {
{this.props.data.message}

- {this.props.data.status === 'USED' ? + {this.props.data.status === scanStatus.USED ?
{this.props.data.message}

- {this.props.data.status === 'USED' ? + {this.props.data.status !== scanStatus.UNSCANNED ?
{this.props.data.message}

- {this.props.data.status === 'USED' ? + {this.props.data.status === scanStatus.USED ?
{this.props.data.message}

- {this.props.data.status === 'USED' ? + {this.props.data.status === scanStatus.USED ?
{this.props.data.message}

- {(this.props.data.status === 'SCANNED' || this.props.data.status === 'USED') ? + {this.props.data.status !== scanStatus.UNSCANNED ?
{this.props.data.message}

- {this.props.data.status === 'USED' ? + {this.props.data.status === scanStatus.USED ?